This site requires JavaScript, please enable it in your browser!
Greenfoot back
Asiantree
Asiantree wrote ...

2017/4/5

Need someone to check for logic error

Asiantree Asiantree

2017/4/5

#
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--;   
    }
Asiantree Asiantree

2017/4/5

#
I have the Apple method taken care of, just ignore that for now.
danpost danpost

2017/4/5

#
Asiantree wrote...
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?
I took note of that here.
You need to login to post a reply.