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

2012/3/25

how to climb

GreenDude GreenDude

2012/3/25

#
This is my scenario http://imageshack.us/photo/my-images/42/imagearl.png/ and i wanna make the "hero" climb the ladder, is the black thing, but i cant. this is the code i have: if (Greenfoot.isKeyDown("w") && checkLadder() ){ setImage("heroback.png"); moveUp(); } public boolean checkLadder() { //stairs escada = (stairs) getOneIntersectingObject(stairs.class); <- tryed both none of this lines worked Actor escada = getOneObjectAtOffset(0,0, stairs.class); <- return escada!=null; } public void moveUp() { setLocation ( getX(), getY() - speed ); }
matt.milan matt.milan

2012/3/25

#
please capitalize class names (stairs -> Stairs) it's just a convention, we're trained to read things a certain way in java :) i'm going to try to write a quick ladder-situation using your code, and i'll let you know what i find afterwards
GreenDude GreenDude

2012/3/25

#
ok i will do that
danpost danpost

2012/3/25

#
Assuming speed is not zero, both ways should return true (if true). You could just say:
public boolean checkLadder()
{
    return (getOneIntersectingObject(stairs.class) != null);
}
But this change will not alter the results you are getting.
GreenDude GreenDude

2012/3/25

#
yh is the same thing, a solution may be he jump the ladder instead of speed i write -20. but in the next ladder i ill have same problem... :S
danpost danpost

2012/3/25

#
You should be able to set up a new int variable 'private int ladderSpeed = 3;' in the class, but outside any method within the class, and use it instead of speed.
You need to login to post a reply.