I am making a pong game and this is what i got so far
Code:
#include <allegro.h>
int x = 5;
int y = 0;
int counter;
int down = 0, up = 0;
int x2 = 615;
int y2 = 0;
int counter2;
int down2 = 0, up2 = 0;
int play1scor = 0;
int play2scor = 0;
int ballx = 300, bally = 190;
void update_counter()
{
counter++;
}
END_OF_FUNCTION(update_counter);
void update_counter2()
{
counter2++;
}
END_OF_FUNCTION(update_counter2);
int main()
{
allegro_init();
install_keyboard();
LOCK_VARIABLE(counter);
LOCK_FUNCTION(update_counter);
install_int_ex( update_counter, BPS_TO_TIMER(60));
LOCK_VARIABLE(counter2);
LOCK_FUNCTION(update_counter2);
install_int_ex( update_counter2, BPS_TO_TIMER(60));
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
BITMAP *bar = load_bitmap( "sprite/bar.bmp", NULL );
BITMAP *logo = load_bitmap( "sprite/logo.bmp", NULL );
BITMAP *ball = load_bitmap( "sprite/ball.bmp", NULL );
while ( !key[KEY_ESC] )
{
while ( counter > 0 )
{
if (down) y-=7;
if (up) y+=7;
counter--;
}
if ( y > 0 && key[KEY_UP])
down = 1;
else
down = 0;
if ( y < 375 && key[KEY_DOWN])
up = 1;
else
up = 0;
while ( counter2 > 0 )
{
if (down2) y2-=7;
if (up2) y2+=7;
counter2--;
}
if ( y2 > 0 && key[KEY_A])
down2 = 1;
else
down2 = 0;
if ( y2 < 375 && key[KEY_Z])
up2 = 1;
else
up2 = 0;
vsync();
clear_to_color (screen, 0);
draw_sprite ( screen, bar, x, y );
draw_sprite ( screen, bar, x2, y2 );
draw_sprite ( screen, logo, 245, 200 );
draw_sprite ( screen, ball, ballx, bally );
}
destroy_bitmap(bar);
destroy_bitmap(logo);
allegro_exit();
return 0;
}
END_OF_MAIN();
how do i make the ball move and... you know... do what the pong ball does?
thanks