I'm making a 2D game where little sqares are shot from the middle of the screen and the player controlls a pad that rotates around the center of the screen in an attempt to catch the squares. I'm having some trouble with the collision. I split it into two parts. In the first part I calculate when the squares hit the pad and if they do, the square sprites are deleted. This part works. In the second part I calculate when the squares leave a certain distance outside of the game area. (wich is a circle). This is why I used a circle function: x^2 + y^2 = radious^2.
And when the sqares leave this circle, they are deleted. This also works. Then i added a second command to the second part, wich displays a sprite when the squares leave the circle. But the sprite is displayed instantly (I am going to use this for a "game over" screen when the square leaves the circle, so you get a "game over" screen before you even start playing). I have no idea why this is happening.
here is the collision part of the code:
for (int i=2;i<102;i++){
if ((dbSpriteX(i)-400)*(dbSpriteX(i)-400) + (dbSpriteY(i)-300)*(dbSpriteY(i)-300)> 280*280){
dbDeleteSprite(i);
dbSprite(300,100,100,4);
}
}
The squares have IDs ranging from 2-101.
This is the code where I make the squares:
if(time_current-time >= pause && repeat<=37/division){
dbSprite(good_ID,400,300,2);
dbOffsetSprite(good_ID,5,5);
good_rotation = dbWrapValue((good_rotation)+spin);
dbRotateSprite(good_ID,good_rotation);
good_ID++;
repeat++;
if (repeat == 37/division){
circle_done=true;
}
time_got=false;
}
I call the squares goods so good_ID is the Id of a square. I have the display set to 800x600 so x=400,y=300 is the center of the screen.
Thanks in advance!
I just love the smell of code in the morning...