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

2012/10/29

Set edge

DOGGY DOGGY

2012/10/29

#
hello, im making a game with a soccerfield in it but i have a problem. I need a object to stay between the lines otherwise the game wont be as it used to be. which code can i use to keep this object between the lines? The object to stay between the line can only move up and down. This is the code im using for the object to move up and down. public void act() { if (Greenfoot.isKeyDown("q")) { setLocation(getX(), getY()-30); } if (Greenfoot.isKeyDown("a")) { setLocation(getX(), getY()+30); } } can i get some help?
Avinash Avinash

2012/10/29

#
ewa ja
erdelf erdelf

2012/10/29

#
well, if you dont move it in the x-axe it will stay between the lines
davmac davmac

2012/10/29

#
Please format your code as code! click 'code' when editing your post and paste your code into the pop-up. Your first setLocation (on the fourth line) could be changed to:
    setLocation(getX(), Math.max(getY() - 30, upperLineYpos));
You need to choose a value for 'upperLineYpos', it specifies the position of the higher line. (Replace 'upperLineYpos' with a suitable number). Similarly for the other setLocation:
   setLocation(getX(), Math.min(getY()+30, lowerLineYpos));
AzonnerA AzonnerA

2012/10/31

#
I do not understand what you mean. explain in more detail, maybe I can help.
You need to login to post a reply.