this code has driven me crazy
most of it i have found at a tutorial site.
its a spaceshooter game (yes the same as before)
my problem is that i want the ship to "shoot" a laser beam
when u press a certain key i almost solved that problem once
but then it shot one beam then the game crashed
but then i forgot even that
btw it is an allegro game
Code:
#include <allegro.h> // You must include the Allegro Header file
int main(int argc, char *argv[])
{
allegro_init(); // Initialize Allegro
install_keyboard(); // Initialize keyboard routines
set_color_depth(16); // Set the color depth
set_gfx_mode(GFX_AUTODETECT,640,480,0,0); //Change our graphics mode to 640x480
BITMAP*bild;
bild=load_bitmap("c:\\temp\\ship.bmp",0);
BITMAP *my_pic; //Declare a BITMAP called my_pic
my_pic = load_bitmap("c:\\temp\\rocket.bmp", NULL); // Load our picture
BITMAP *buffer; //Declare a BITMAP called buffer.
buffer = create_bitmap(640,480); //Create an empty bitmap.
while(!key[KEY_ESC])//If the user hits escape, quit the program
{
if(key[KEY_RIGHT])// If the user hits the right key, change the picture's X coordinate
{
my_pic_x ++;// Moving right so up the X coordinate by 1
}
if(key[KEY_LEFT])// Ditto' - only for left key
{
my_pic_x --;// Moving left, so lower the X coordinate by 1
}
if(key[KEY_UP])// If the user hits the up key, change the picture's Y coordinate
{ for(int w=500;w>0
{
putpixel(buffer,my_pic_x,w+10,0);
putpixel(buffer,my_pic_x,w--,500);
}
if(key[KEY_DOWN])// Ditto' - only for down
{
my_pic_y ++;// Moving down, so up the Y coordinate by 1
}
acquire_screen();// Get the screen
draw_sprite(buffer, bild, my_pic_x, my_pic_y);//Draw the picture to the buffer
blit(buffer, screen, 0,0,0,0,640,480);//Draw the buffer to the screen
release_screen();// Release it
}
destroy_bitmap(bild);//Release the bitmap data
destroy_bitmap(buffer);//Release the bitmap data
return(0);// Exit with no errors
}
END_OF_MAIN();