import java.awt.*; import com.genuts.gameui.*; /** * Choose the direction of the robot */ public class DummyRobot extends SpriteWrapper { // Speed of the robot private final static int HSPEED = 3; private final static int VSPEED = 2; // Action sprites for left an right direction private RobotSprite robotRight; private RobotSprite robotLeft; public DummyRobot(RobotSprite robotRight, RobotSprite robotLeft) { super(robotRight); this.robotRight = robotRight; robotRight.setHorizontalSpeed(HSPEED); robotRight.setVerticalSpeed(VSPEED); this.robotLeft = robotLeft; robotLeft.setHorizontalSpeed(-HSPEED); robotLeft.setVerticalSpeed(VSPEED); } public int getVerticalSpeed() { return VSPEED; } public int getHorizontalSpeed() { return HSPEED; } /** * Changes direction of the robot */ protected void changeDirection(RobotSprite fromSprite, RobotSprite toSprite) { PlayField parent = getParent(); Sprite finalWrapper = getFinalWrapper(); Point p = getPosition(); toSprite.setCurrentPictureNumber(fromSprite.getCurrentPictureNumber()); parent.removeSprite(finalWrapper); setActionSprite(toSprite); setPosition(p.x, p.y); toSprite.fly(fromSprite.isFlying()); parent.addSprite(finalWrapper); } /** * Order to go the to left */ public void goLeft() { if (getActionSprite() != robotLeft) { changeDirection(robotRight, robotLeft); } robotLeft.walk(true); } /** * Order to go the to right */ public void goRight() { if (getActionSprite() != robotRight) { changeDirection(robotLeft, robotRight); } robotRight.walk(true); } /** * Order to stop walking */ public void stopWalking() { ((RobotSprite) getActionSprite()).walk(false); } /** * Order to fly */ public void flyUp() { ((RobotSprite) getActionSprite()).fly(true); } /** * Order to stop flying */ public void stopFlying() { ((RobotSprite) getActionSprite()).fly(false); } /** * Transmit if the robot is flying */ public boolean isFlying() { return ((RobotSprite) getActionSprite()).isFlying(); } }