Hello,
Long time no post! Well, I'm creating a game uisng Allegro, and dev-c++. But I have ran into a problem in my game. I have a struct bullet. I know how to check the space bar, but what I don't know is how to make it so it creates a NEW bullet, everytime he/she pushes the space bar, then, how do I make it so it updates the bullets location so it looks like its flying through the air?? I can't find anyware about a for each loop. If you could help, thanks. Here is my source code. **NOTE I havn't put in the bullet's graphic yet.
Code:
#include <allegro.h> //For allegro graphics lbrary
//Structs
struct enemy {
int x;
int y;
};
struct player {
int x;
};
struct bullet {
int x;
int y;
};
int num_of_enemys;
//Main Function
int main(int argc, char *argv[]){
//Start Allegro
allegro_init(); // Start allegro
//Set color depth
set_color_depth(32);
//Set Graphics mode
set_gfx_mode(GFX_AUTODETECT,800,600,0,0);
//Images
BITMAP *strongbad = load_bitmap("./graphics/strongbad.bmp",NULL);
BITMAP *homestar = load_bitmap("./graphics/homestarrunner.bmp",NULL);
BITMAP *background = load_bitmap("./graphics/background.bmp",NULL);
BITMAP *buffer = create_bitmap(800,600);
//create objects
player strong_bad;
strong_bad.x = 500;
install_keyboard();
while(!key[KEY_ESC]){
//Check keyboard
if(key[KEY_LEFT]){
strong_bad.x = strong_bad.x - 5;
}
if(key[KEY_RIGHT]){
strong_bad.x = strong_bad.x + 5;
}
if(key[KEY_SPACE]){
bullet dot;
dot.x = strong_bad.x;
dot.y = 400
}
//Check players position
if(strong_bad.x <= -32){
strong_bad.x = 790;
}
if(strong_bad.x >= 832){
strong_bad.x = 10;
}
clear_bitmap(buffer);
draw_sprite(buffer,background,0,0);
masked_blit(strongbad,buffer,0,0,strong_bad.x,400,32,55);
blit(buffer,screen,0,0,0,0,800,600);
}
destroy_bitmap(buffer);
destroy_bitmap(strongbad);
destroy_bitmap(homestar);
destroy_bitmap(background);
return 0;
}
END_OF_MAIN()