Problem declaring struct in allegro
heres my code:
//#define DEBUGMODE //include this if your debugging
#include <stdio.h>
#include <allegro.h>
#include "test.h"
#define left 1
#define right 2
#define up 3
#define down 4
#define UpandLeft 5
#define DownandLeft 6
#define UpandRight 7
#define DownandRight 8
#define space 9
#define ericw 43 // width of eric.bmp
#define erich 61 // hight of eric.bmp
typedef struct bullet // this is one bullet with its xpos, ypos, and the direction its moving in
{
int bulletx;
int bullety;
int direction;
};
PALETTE Pal;
BITMAP *ImageBuffer;
BITMAP *Ammobuffer; // stores the the immage of the amunition
int main(void)
{
BITMAP *dblbuffer;
int x=100;
int y=100;
int shotx=0;
int shoty=0;
int lastkeypressed=0;
bullet bullets[6]; // this stores information on all the bullets in the air
allegro_init();
install_keyboard();
install_timer(); /* needed for `rest' function */
set_color_depth(32);
if (set_gfx_mode(GFX_SAFE, 800, 600, 0, 0) < 0)
{
printf("%s\n", allegro_error);
exit(1);
}
clear(screen);
// Pay attention!!! We HAVE to allocate memory for our memory bitmap
dblbuffer = create_bitmap(SCREEN_W, SCREEN_H);
clear(dblbuffer);
ImageBuffer = load_bmp("Eric.bmp", Pal);
Ammobuffer = load_bmp("rock.bmp", Pal);
while(1)// main loop
{
/////////////////// input
if (key[KEY_LEFT])
{
x--;
lastkeypressed=left;
}
if (key[KEY_RIGHT])
{
x++;
lastkeypressed=right;
}
if (key[KEY_UP])
{
y--;
lastkeypressed=up;
}
if (key[KEY_DOWN])
{
y++;
lastkeypressed=down;
}
if (key[KEY_LEFT] && key[KEY_UP])
{
lastkeypressed=UpandLeft;
}
if (key[KEY_LEFT] && key[KEY_DOWN])
{
lastkeypressed=DownandLeft;
}
if (key[KEY_RIGHT] && key[KEY_UP])
{
lastkeypressed=UpandRight;
}
if (key[KEY_RIGHT] && key[KEY_DOWN])
{
lastkeypressed=DownandRight;
}
if (key[KEY_SPACE])
{
lastkeypressed=space;
//fire(lastkeypressed, Ammobuffer, x, y+50, dblbuffer);
}
//////////////////output
if (lastkeypressed=right)
{
rectfill(dblbuffer, x - 1 , y ,x + ericw - 1, y + erich, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=left)
{
rectfill(dblbuffer, x + 1 , y ,x + ericw + 1, y + erich, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=up)
{
rectfill(dblbuffer, x , y + 1,x + ericw , y + erich + 1, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=down)
{
rectfill(dblbuffer, x , y - 1,x + ericw ,y + erich - 1, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=UpandLeft)
{
rectfill(dblbuffer, x + 1 ,y + 1,x + ericw + 1, y + erich + 1, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=DownandLeft)
{
rectfill(dblbuffer, x + 1 ,y - 1,x + ericw + 1, y + erich - 1, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=UpandRight)
{
rectfill(dblbuffer, x - 1 ,y + 1,x + ericw - 1, y + erich + 1, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=DownandRight)
{
rectfill(dblbuffer, x - 1 ,y - 1,x + ericw - 1, y + erich - 1, makecol(000,000,000)); /* erase from last place */
}
if (lastkeypressed=space)
{
draw_sprite(dblbuffer, Ammobuffer, shotx, shoty);
}
//circlefill(dblbuffer, x , y, 50, makecol(255,255,255)); /* redraw at new place */
draw_sprite(dblbuffer, ImageBuffer, x, y); //draw bitmap on dblbuffer
draw_sprite(dblbuffer, ImageBuffer, x, y);
vsync();
blit(dblbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); // copy from double buffer to screen
if (key[KEY_ESC])//clean up and quit
{
// Now, remember to FREE the memory you previously allocated
destroy_bitmap(dblbuffer);
destroy_bitmap(ImageBuffer);
destroy_bitmap(Ammobuffer);
allegro_exit();
exit(1);
}
}
return 0;
}
END_OF_MAIN();
and im getting these error messages:
--------------------Configuration: allegrotest - Win32 Debug--------------------
Compiling...
test.c
C:\programming stuff\allegrotest\test.c(41) : error C2065: 'bullet' : undeclared identifier
C:\programming stuff\allegrotest\test.c(41) : error C2146: syntax error : missing ';' before identifier 'bullets'
C:\programming stuff\allegrotest\test.c(41) : error C2065: 'bullets' : undeclared identifier
C:\programming stuff\allegrotest\test.c(41) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
allegrotest.exe - 4 error(s), 0 warning(s)
bullet bullets[6]; // this stores information on all the this is line 41
the struct worked fine when i excluded the rest of the code also it won't let me use an array like this [] i have to set how long it is there any way to make an array of structs as long as you want.