I have an actor called "Red_Robot"(subclass of Robot which is a subclass of Game_Piece). I want an actor called "Red_Ball"(subclass of Ball which is a subclass of Game_Piece)to move when Red_Robot touches it. If anyone knows how that would work please answer.
Here's the "Red_Ball" code:
Here's the code for "Red_Robot"
The Blue_Ball is identical to Red_Ball. Blue_Robot is only different in that becomes . And that Red_Robot drives with WASD and Blue_Robot drives with Arrow keys.
public class Red_Ball extends Ball { public void act() { PushedByRed(); PushedByBlue(); } public void PushedByRed() { if (Greenfoot.isKeyDown("w") && isTouching(Red_Robot.class)) move(3); if (Greenfoot.isKeyDown("s") && isTouching(Red_Robot.class)) move(-3); } public void PushedByBlue() { if (Greenfoot.isKeyDown("up") && isTouching(Blue_Robot.class)) move(3); if (Greenfoot.isKeyDown("down") && isTouching(Blue_Robot.class)) move(-3); } }
public class Red_Robot extends Robot { public void act() { wasdDrive(); } public void wasdDrive() { if (Greenfoot.isKeyDown("a")) turn(-3); if (Greenfoot.isKeyDown("d")) turn(3); if (Greenfoot.isKeyDown("w")) move(3); if (Greenfoot.isKeyDown("s")) move(-3); } }
public void wasdDrive()
public void arrowDrive()