so im programming a maze game for my game design class and when the player touches a portal the wasd keys are supposed to invert tbh i have no idea how tf im supposed to do this and any help would be appreciated


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import greenfoot.*; public class main extends Actor { int speed = 2 ; int dir = 1 ; public void act() { move(); invert(); } private void move() { int dx = 0 , dy = 0 ; if (Greenfoot.isKeyDown( "a" )) dx--; if (Greenfoot.isKeyDown( "d" )) dx++; if (Greenfoot.isKeyDown( "w" )) dy--; if (Greenfoot.isKeyDown( "s" )) dy++; setLocation(getX()+speed*dx*dir, getY()+speed*dy*dir); } private void invert() { if (isTouching(funnyinvert. class )) { removeTouching(funnyinvert. class ); dir = -dir; } } } |