Hello, I recently started working on a simple 2D game and I've run in to a bit of a problem with one of my classes.
class AddSprite
{
private:
D3DXIMAGE_INFO Size;
bool drawBrick;
static RECT Player;
static RECT Ball;
RECT Brick;
public:
enum OBJ_TYPE
{
PLAYER,
BALL,
BRICK,
DEFAULT
};
AddSprite() { drawBrick = true; }
void LoadSprite(LPCSTR filename);
void DrawSprite(int x, int y, int z, int type = DEFAULT);
void TileSprite(int xStart = 0, int yStart = 0, int xEnd = WIDTH, int yEnd = HEIGHT);
};
/*...*/
void AddSprite::DrawSprite(int x, int y, int z, int type)
{
/*...*/
if(type == BRICK)
{
SetRect(&Brick, x, y, Brick.left + Size.Width, Brick.top + Size.Height);
if(Ball.top <= Brick.bottom && Ball.left <= Brick.right && Ball.right >= Brick.left && Ball.bottom >= Brick.top)
{
drawBrick = false;
}
if(drawBrick == true)
{
D3DXVECTOR3 loc(x, y, z);
d3dspt->Draw(sprite, NULL, NULL, &loc, D3DCOLOR_XRGB(255, 255, 255));
}
}
}
/*...*/
The problem is on this if statement:
if(Ball.top <= Brick.bottom && Ball.left <= Brick.right && Ball.right >= Brick.left && Ball.bottom >= Brick.top)
{
drawBrick = false;
}
I want to change the value of 'drawBrick' from true to false, to stop it from drawing that sprite. However, it only stays false for when the ball sprite is over the brick sprite, then reverts back to it's initial value, true. Should this be happening, or am I doing something wrong? Is there any way I can stop this from happening without making it static?
Any help would be greatly appreciated. Thanks.