Hi all, I'm having problem with an If statement in my game.
I've created a class called SPRITE to hold basic informaiton about sprites such as their location and the size of them
CODE
class SPRITE
{
public:
int x,y;
int width,height;
int movex,movey;
int curframe,lastframe;
int animdelay,animcount;
int scalex, scaley;
int rotation, rotaterate;
int health; // Health of enemies
bool alive;
};
Now, I have used "new" to create a dynamic object called "fire" which will be weapons fire and I have entered data into the object using ->, for exmaple
CODE
fire->x = 100; //set to zero as it will always come from where the player is when fired
fire->y = 500;
fire->width = 16;
fire->height = 16;
fire->curframe = 1;
fire->lastframe = 6;
fire->animdelay = 3;
fire->animcount = 0;
fire->movex = 10;
fire->movey = 0;
fire->alive = 0;
When viewing the sprite in the game, everything works fine, it loads at the coordinate as it should, the height is as it should and everything else works, except for the alive variable. I am using that variable to see whether the weapon is alive, for example, once a button has been pressed, then when its alive it can fire off, here is the code for that.
CODE
if (Mouse_Button(0));
{
fire->alive = 1;
if(fire->alive == 1);
{
fire->x += fire->movex;
position3.x = (float)fire->x;
position3.y = (float)fire->y;
sprite_handler->Draw(
fire_image,
&srcRect3,
NULL,
&position3,
D3DCOLOR_XRGB(255,255,255));
}
}
So, once the mouse button is pressed, alive gets set to 1, and if alive is set to 1, then move the sprite accordingly and draw it. But the problem is, no matter what I set the condition to, it will ALWAYS fire, and I have checked the code and alive is not set to 1 anywhere else, infact it is set to 1 when the class is filled in. At first I thought it was some problem caused by using a dynamic class, but if that were true the rest of the filled in data would have a problem too.
Does anyone know why the if statement is failing? If its soemthing obvious I'm gonna kick myself, any help is appreciated, if ive explained it badly just let me know and ill go through it again. Thanks.