For some reason, all of my Ants turn into DeadAnts after less than 3 seconds of runtime. Is there a logic error for my badCalorie and goodCalorie good in my Ant act method?
public void act()
{
exactX += xSpeed;
exactY += ySpeed;
setLocation ( (int) exactX, (int) exactY );
//bouncing off walls only
if ((xSpeed < 0 && getX() <= getImage().getWidth() / 2) || (xSpeed > 0 && getX() >= getWorld().getWidth() - (getImage().getWidth() / 2)))
{
xSpeed = -xSpeed;
}
if ((ySpeed < 0 && getY() <= getImage().getHeight() / 2) || (ySpeed > 0 && getY() >= getWorld().getHeight() - (getImage().getHeight() / 2)))
{
ySpeed = -ySpeed;
}
moveTowardsFries();
//for when touching an apple
Actor Apple;
Apple = getOneIntersectingObject(Apple.class);
if (Apple != null)
{
}
moveTowardsAnts();
//in here somewhere in the logic error that causes my Ants to die within two seconds, even though they should have 200 good calories and 100
// bad calories to start off
if (goodCalorie <= 0){
badCalorie-=5;
if(badCalorie <= 0){
World myWorld = getWorld();
MyWorld myworld = (MyWorld)myWorld;
getWorld().removeObject(this);
myworld.addObject(new DeadAnt(), (int) exactX, (int) exactY);
}
}
goodCalorie--;
}
