Heres the function
Code:
// a function i'm working on to calculate a shot movement
void calculate_shot_movment()
{
int shot_draw_number=0;
while (shot_draw_number < 256)
{
if (bullets[shot_draw_number].isalive!=TRUE) //skip if its a dead bullet
{
shot_draw_number++;
}
if (shot_draw_number < 256)
{
if (bullets[shot_draw_number].direction==DownandRight)
{
bullets[shot_draw_number].bulletx++;
bullets[shot_draw_number].bullety++;
}
if (bullets[shot_draw_number].direction==UpandLeft)
{
bullets[shot_draw_number].bulletx--;
bullets[shot_draw_number].bullety--;
}
if (bullets[shot_draw_number].direction==DownandLeft)
{
bullets[shot_draw_number].bulletx--;
bullets[shot_draw_number].bullety++;
}
if (bullets[shot_draw_number].direction==UpandRight)
{
bullets[shot_draw_number].bulletx++;
bullets[shot_draw_number].bullety--;
}
if (bullets[shot_draw_number].direction==down)
{
bullets[shot_draw_number].bullety++;
}
if (bullets[shot_draw_number].direction==up)
{
bullets[shot_draw_number].bullety--;
}
if (bullets[shot_draw_number].direction==left)
{
bullets[shot_draw_number].bulletx--;
}
if (bullets[shot_draw_number].direction==right)
{
bullets[shot_draw_number].bulletx++;
}
if (bullets[shot_draw_number].bulletx>SCREEN_W) //kill if off screen
{
bullets[shot_draw_number].isalive=FALSE;
}
if (bullets[shot_draw_number].bulletx>SCREEN_H) //kill if off screen
{
bullets[shot_draw_number].isalive=FALSE;
}
}
//textout(dblbuffer, font, "bullets were calculated.", 1, 1, makecol(255,255,255));
draw_sprite(dblbuffer, Ammobuffer, bullets[shot_draw_number].bulletx, bullets[shot_draw_number].bullety); //draw the bullet
shot_draw_number++;
}
}
and heres the def of Bullets
Code:
struct bullet{
int bulletx;
int bullety;
int direction;
char isalive;
}bullets[256]; // this stores information on all the bullets in the air
any way what would be the best way to have the function access that struct. My attemps to use pointers and refernces have been fairly unsecessful but I probalby was doing something wrong.
Im using MSVc++ 6 with allegro.