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

2016/11/13

From entering a door/passage that automatically moves you to the next level

lolitsme lolitsme

2016/11/13

#
Hello! Do you guys have codes wherein once my actor goes to a door it will automatically move me to the next level? Also how can I program the Actor "Door" wherein once my Actor "Human" passes through it will proceed to the next level? Thank you and God Bless!
danpost danpost

2016/11/13

#
lolitsme wrote...
how can I program the Actor "Door" wherein once my Actor "Human" passes through it will proceed to the next level?
What code have you tried in your Door class?
lolitsme lolitsme

2016/11/14

#
public void act() { if (isTouching(Door.class)) { Greenfoot.setWorld(new Level2()); } This oneee.
danpost danpost

2016/11/14

#
lolitsme wrote...
public void act() { if (isTouching(Door.class)) { Greenfoot.setWorld(new Level2()); } This oneee.
I hope that is in the class of the human -- not the Door class. Also, you may want to check the current level before proceeding to the next level. You may not automatically want to go to a Level2 world anytime a Door object is touched:
if (isTouching(Door.class))
{
    if (getWorld() instanceof Level1) Greenfoot.setWorld(new Level2());
}
lolitsme lolitsme

2016/11/14

#
Okay thank u so much!! I finally know why I was wrong.
lolitsme lolitsme

2016/11/14

#
Ohh! Last question, how can I make it continuous? I can know move from level 1 to level 2. I dont know what to do with level 3
danpost danpost

2016/11/14

#
lolitsme wrote...
Ohh! Last question, how can I make it continuous? I can know move from level 1 to level 2. I dont know what to do with level 3
Just add additional if statements in the 'isTouching(Door.class)' block.
You need to login to post a reply.