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

2014/8/25

Countered problems

1
2
sharifahhilwa sharifahhilwa

2014/8/27

#
and underneath my public void act, these are my codes public void addedToWorld (World w) { active = true; } private void checkKeys() { if (active == true) { if (Greenfoot.isKeyDown("up")) { setLocation (getX(), getY() - movement); } if (Greenfoot.isKeyDown("down")) { setLocation (getX(), getY() + movement); } else if (Greenfoot.isKeyDown("left")) { setLocation (getX() - movement, getY()); } else if (Greenfoot.isKeyDown("right")) { setLocation (getX() + movement, getY()); } } }
danpost danpost

2014/8/27

#
That is not your act method code.
sharifahhilwa sharifahhilwa

2014/8/27

#
@danpost hi i have asked my instructor to help me analyze the problem and look through your points. It works now!! Thanj you so much danpost!!! Really appreciate
Super_Hippo Super_Hippo

2014/8/27

#
The act method is the last post on the first page. You can put the last two lines (with the removing of Gold) before the 'if checkWin()', so if the 'Crosser' will be removed, there is nothing in the act method after that which needs the Crosser to be in the world.
    public void act() 
    {
     checkKeys();
     
     Gold gold = (Gold)getOneIntersectingObject(Gold.class);
     if (isTouching(Gold.class)) removeTouching(Gold.class);


     if (checkWin())
     {
         endGame(true);
     }
        
     else if(checkDeath() && active == true)
     {
         active = false;
         endGame(false);
     }
     
}
danpost danpost

2014/8/27

#
@Super_Hippo, the page change got me there (along with the separate posting of the two methods). I concur with your rearrangement of the code. However, either line 5 should be removed (as 'gold' is not being used in the method) or line 6 should be changed to the following:
if (gold != null) getWorld().removeObject(gold);
making good use of the reference to the object.
You need to login to post a reply.
1
2