Witam .
Pisze z kolegami gre Snake . mamy następujący problem udało się zrobić kolzije z dwiema ścianami i z resztą próbowaliśmy ,ale nie działa , no i kolizja z Jedzeniem -wcale jej nie wykrywa nie wiem dlaczego . Nie patrzeć na nic związanego z bonusem , bo nadtym dopiero pracujemy .
Proszę o pomoc w zrobieniu kolizja z jedzeniem i wszystkimi ścianami
z Góry dziękujemy za pomoc .
kod odpowiedzialny z kolizje i rysowanie węża :
do
{
textprintf( screen, font, 20, 20, makecol( 255, 255, 128 ), "Klawisz to : %d", klaw );
while( speed > 0 )
{
if (keypressed)klaw=readkey();
tab[x3]=14+rand()%605;
tab1[y3]=15+rand()%535;
hline(screen, 5, 10, 630, makecol(255,255,255));
hline(screen, 5, 550,630, makecol(255,255,255));
vline(screen, 5, 550,10, makecol(255,255,255));
vline(screen, 630, 550, 10, makecol(255,255,255));
speed--;
textprintf_ex( screen, font, 300, 620, makecol( 255, 100, 200 ), - 1, "Score: %i ",pkt );
if( klaw==20992)
x--,x1--;
if( klaw==21248 )
x++,x1++;
if( klaw==21504 )
y--,y1--;
if( klaw==21760 )
y++,y1++;
rectfill( screen, 150, 150, 145, 145, makecol( 128, 20, 20 ) );
if(((x<5) && (x<=630) && (y==10)) || ((y<=550) && (y<=10)&& (x>5 ))||((x<5) && (x<=630) && (y=550)))
{
textprintf_ex( screen, font, 300, 520, makecol( 255, 100, 200 ), - 1," Game Over");
textprintf_ex( screen, font, 300, 540, makecol( 255, 100, 200 ), - 1, "Score: %i ",pkt );
rest(2500);
exit(1);
}
if((x1==150) && (y1==150) && (x==145) && (y==145 ))
{
pkty+1;
textprintf_ex( screen, font, 300, 520, makecol( 255, 100, 200 ), - 1, "pkty %i",pkty );
if((x1=tab[x3]) && (y1==tab1[y3]) )
{
ellipsefill( screen, tab[x3], tab1[y3], 3, 3, makecol( 128, 20, 20 ) ); // rysowanie pkt do zjedzneia
pkty+1;
textprintf_ex( screen, font, 300, 520, makecol( 255, 100, 200 ), - 1, "pkty %i",pkty );
pkt=pkt+10; // naliczanie pkt
textprintf_ex( screen, font, 300, 620, makecol( 174, 244, 111 ), - 1, "Score: %i ",pkt );
}
}
cały Kod :
#include <allegro.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <stdio.h>
#include <time.h>
int pkty;
volatile long speed = 0;
void increment_speed()
{
speed++;
}
END_OF_FUNCTION( increment_speed );
LOCK_VARIABLE( speed );
LOCK_FUNCTION( increment_speed );
int pkt;
int main()
{
int i,tab[700],tab1[600],x3,y3;
srand( (unsigned)time( NULL ) );
allegro_init();
install_keyboard();
set_color_depth( 16 );
set_gfx_mode( GFX_AUTODETECT, 640, 640, 0, 0 );
clear_to_color( screen, makecol( 128, 128, 128 ) );
BITMAP*tlo=NULL;
BITMAP * bonus = NULL;
install_timer();
install_int_ex( increment_speed, BPS_TO_TIMER( 1000 ) );
tlo = load_bmp("tlo.bmp",default_palette);
if (!tlo) //obsługa błędu
{
set_gfx_mode(GFX_TEXT,0,0,0,0);
allegro_message("nie mogę załadować obrazka tlo !");
allegro_exit();
return 0;
}
blit( tlo, screen, 0, 0, 0, 0,tlo->w, tlo->h);
bonus = load_bmp( "bonus.bmp", default_palette );
if( !bonus )
{
set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
allegro_message( "nie mogę załadować obrazka !" );
allegro_exit();
return 0;
}
int x=150, y=100, x1=150, y1=100;
int bx,by;
int klaw,punkt;
klaw=0;
punkt=0;
pkty=0;
do
{
textprintf( screen, font, 20, 20, makecol( 255, 255, 128 ), "Klawisz to : %d", klaw );
while( speed > 0 )
{
if (keypressed)klaw=readkey();
tab[x3]=14+rand()%605;
tab1[y3]=15+rand()%535;
hline(screen, 5, 10, 630, makecol(255,255,255));
hline(screen, 5, 550,630, makecol(255,255,255));
vline(screen, 5, 550,10, makecol(255,255,255));
vline(screen, 630, 550, 10, makecol(255,255,255));
speed--;
textprintf_ex( screen, font, 300, 620, makecol( 255, 100, 200 ), - 1, "Score: %i ",pkt );
if( klaw==20992)
x--,x1--;
if( klaw==21248 )
x++,x1++;
if( klaw==21504 )
y--,y1--;
if( klaw==21760 )
y++,y1++;
rectfill( screen, 150, 150, 145, 145, makecol( 128, 20, 20 ) );
if(((x<5) && (x<=630) && (y==10)) || ((y<=550) && (y<=10)&& (x>5 ))||((x<5) && (x<=630) && (y=550)))
{
textprintf_ex( screen, font, 300, 520, makecol( 255, 100, 200 ), - 1," Game Over");
textprintf_ex( screen, font, 300, 540, makecol( 255, 100, 200 ), - 1, "Score: %i ",pkt );
rest(2500);
exit(1);
}
if((x1==150) && (y1==150) && (x==145) && (y==145 ))
{
pkty+1;
textprintf_ex( screen, font, 300, 520, makecol( 255, 100, 200 ), - 1, "pkty %i",pkty );
if((x1=tab[x3]) && (y1==tab1[y3]) )
{
ellipsefill( screen, tab[x3], tab1[y3], 3, 3, makecol( 128, 20, 20 ) ); // rysowanie pkt do zjedzneia
pkty+1;
textprintf_ex( screen, font, 300, 520, makecol( 255, 100, 200 ), - 1, "pkty %i",pkty );
pkt=pkt+10; // naliczanie pkt
textprintf_ex( screen, font, 300, 620, makecol( 174, 244, 111 ), - 1, "Score: %i ",pkt );
}
}
masked_blit( bonus, screen, 0, 0, bx, by, bonus->w, bonus->h );
rectfill( screen,x,y,x1+5,y1+5, makecol(255,128,64));
}
}while(!key[KEY_ESC]);
//clear_to_color(screen, makecol(10,10,10));
rest(15);
remove_int( increment_speed );
destroy_bitmap( bonus );
allegro_exit();
return 0;
}
END_OF_MAIN();