Well i added "lives" in my game, it's red bar which when asteroid hits spaceship get reduced by 1/3 of it's size... But when they colide it reduce it by 1/3 then another 1/3 and another 1/3, as long as they are touching it keeps reducing and game ends so fast. So i need help, how do i make it reduce only 1/3 when it hits 1 asteroid not all lives. Here's the code that is in the Negativac(Asteroid) class:
And this is the code in the AvoiderWorld class:
As you can see it should add 1 to variable "i" when they colide but it keeps adding as long as they are touching. Help pls ASAP
public void collide()
{
Actor GlavniLik = getOneIntersectingObject(GlavniLik.class);
if (GlavniLik != null)
{
World myWorld = getWorld();
AvoiderWorld avoiderworld = (AvoiderWorld)myWorld;
HealthBar healthbar = avoiderworld.getHealthBar();
if(touchingGlavniLik == false)
{
healthbar.loseHealth();
touchingGlavniLik = true;
}
i=i+1;
} else {
touchingGlavniLik = false;
}
}public void act()
{
if(theNegativac.getI()==3)
{
removeObjects(getObjects(Negativac.class));
removeObjects(getObjects(GlavniLik.class));
addObject(new GameOver(),450,350);
addObject(new PlayAgainDugme(),450,350);
addObject(new ExitDugme(), 450,390);
setPaintOrder(Counter.class);
SpaceMusic.stop();
}
else{
int score=theCounter.getValue();
if(Greenfoot.getRandomNumber(limit1) < 20 && theNegativac.getI()!=3)
{
addObject(new Negativac(), Greenfoot.getRandomNumber(getWidth()-20)+10, - 30);
theCounter.add(5);
}
}
