Code: Select all
#include <allegro.h>
#include <C:\Dev-Cpp\collfunctions.h>
int main()
{
allegro_init();
install_keyboard();
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 );
set_color_depth( 16 );
BITMAP *square = load_bitmap( "green square.bmp", NULL );
BITMAP *buffer;
buffer = create_bitmap( 640, 480 );
while( !key[KEY_ESC] )
{
masked_blit( square, buffer, 0, 0, x, y, 130, 130 );
masked_blit( square, buffer, 0, 0, p2x, p2y, 130, 130 );
blit( buffer, screen, 0, 0, 0, 0, 640, 480 );
if( key[KEY_UP] )
{
y--;
}
else if( key[KEY_DOWN] )
{
y++;
}
if( key[KEY_LEFT] )
{
x--;
}
else if( key[KEY_RIGHT] )
{
x++;
}
clear_bitmap( buffer );
checkColl1();
}
clear_bitmap( square );
return 0;
}
END_OF_MAIN();
Code: Select all
//fuctions.h
//dynamic polygon
int x = 0;
int y = 0;
int p1trcx = 0;
int p1trcy = 0;
int p1blcx = 0;
int p1blcy = 0;
int p1brcx = 0;
int p1brcy = 0;
//static polygon
int p2x = 200;
int p2y = 200;
int p2trcx = 330;
int p2trcy = 330;
int p2blcx = 200;
int p2blcy = 30;
int p2brcx = 330;
int p2brcy = 30;
//collison boolean
bool collision = false;
int popcolllog()
int checkColl1()
{
if( ( p1brcx > p2x ) and ( p1brcy > p2y ) )
{
collision = true;
}
else if( (p1brcx < p2x) and (p1brcy < p2y) )
{
collision = false;
}
};