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

2015/1/16

Movement!

gamer98 gamer98

2015/1/16

#
Hi i was just trying to figure out something. My game currently has a left and right movement control. Is there a way in which i could activate the up and down movement if a condition has been met e.g. if score is equal to 200 then the player gets the ability to move up and down. How should i approach this. Thanks in advance for any help. :)
-nic- -nic-

2015/1/16

#
First of all you want to be able to move your actor up and down to do this you can change its y-position by setting its location but changing the y-position
setLocation(getX(), getY() + 1);
This will if put into your actors class will move it down 1 pixel Now allowing the user to be able to do this after a certain amount of points: Quite simply we can check when the user want to move
int points =200;
        if(Greenfoot.isKeyDown("down") && points >= 200)
        {
            setLocation(getX(), getY() + 1);
        }
This will check if the the down key is pressed AND (&&) if points is over or equal to 200 and then move the actor down
Super_Hippo Super_Hippo

2015/1/17

#
You shouldn't use line 1 right before that though. :P
gamer98 gamer98

2015/1/17

#
Thanks for the help, i got it now. :)
-nic- -nic-

2015/1/17

#
Yeah I know but I copied it from a test scenario and it threw an error otherwise forgot to get rid off it. Thanks Super_Hippo
You need to login to post a reply.