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

2014/11/22

Actor interacts with the edge of the world

jnlrsl jnlrsl

2014/11/22

#
HEY GUYS WELP :( I've been working on this game I made for a while now, and I need one code left that I just can't figure out. See it's a maze game with an opening on the left and the right side. Starting from the left is where my character is. When my character reaches the right edge, I want to switch worlds! I have no clue how to do this, and for further informing you guys, my character is under the actor class! I would really appreciate it if you helped me out! :(
jnlrsl jnlrsl

2014/11/22

#
By the way, this is what's under my actor! public void act() { if (Greenfoot.isKeyDown("right")) { turn(10); } if (Greenfoot.isKeyDown("left")) { turn(-10); } if (Greenfoot.isKeyDown("down")) { move(-5); } if (Greenfoot.isKeyDown("space")) { move(5); } if (Greenfoot.isKeyDown("up")) { move(10); } } public void setLocation(int x, int y) { int oldX = getX(); int oldY = getY(); super.setLocation(x, y); if(!getIntersectingObjects(Wall1.class).isEmpty()) { super.setLocation(oldX, oldY); } }
danpost danpost

2014/11/22

#
Change what you said to present tense, at the exact instant in time that is in question. That is, instead of saying, "When my character reaches the right edge, I want to switch worlds!" -- say "If my character is at the right edge, switch worlds (to whatever world).". Or, more specifically, "If the x-location of my character is equal to the right-most x-coordinate in the world, set the active world to a new world." This reads almost the way you would write the code.
You need to login to post a reply.