import com.genuts.gameui.*; /** * Base animation of the robot */ public class RobotSprite extends MovingSpriteWrapper { // AnimatedSprites of flames private AnimatedSprite horizontalJet = null; private AnimatedSprite upJet = null; // Horizontal jet offset private int hjDx = 0; private int hjDy = 0; // Upstairs jet offset private int ujDx = 0; private int ujDy = 0; // Is the robot walking? private boolean walking = false; // Is the robot flying? private boolean flying = false; // Speed of the robot when it moves public int vSpeed = 0; public int hSpeed = 0; public RobotSprite(AnimatedSprite robot, AnimatedSprite horizontalJet, int hjDx, int hjDy, AnimatedSprite upJet, int ujDx, int ujDy) { super(robot); setPremode(true); robot.setPause(true); this.horizontalJet = horizontalJet; horizontalJet.setBackgroundSprite(true); horizontalJet.setVisible(false); this.upJet = upJet; upJet.setBackgroundSprite(true); upJet.setVisible(false); this.hjDx = hjDx; this.hjDy = hjDy; this.ujDx = ujDx; this.ujDy = ujDy; } /** * No checking for collisions */ public boolean checkCollision(Sprite sprite) { return false; } /** * Sets the parent playfield for flames sprites. */ protected void setParent(PlayField parent) { if (getParent() != null) { getParent().removeSprite(horizontalJet); getParent().removeSprite(upJet); } super.setParent(parent); if (parent != null) { int index = getParent().getSpriteIndex(getFinalWrapper()); getParent().addSprite(horizontalJet, index); getParent().addSprite(upJet, index); } } /** * Sets position of flames sprites too. */ public boolean setPosition(int x, int y) { if (super.setPosition(x, y)) { horizontalJet.setPosition(x + hjDx, y + hjDy); upJet.setPosition(x + ujDx, y + ujDy); return true; } else { return false; } } /** * Shortcut to access to getCurrentPictureNumber() of * the AnimatedSprite. */ public int getCurrentPictureNumber() { return ((AnimatedSprite) getActionSprite()).getCurrentPictureNumber(); } /** * Shortcut to access to setCurrentPictureNumber(int) of * the AnimatedSprite. */ public void setCurrentPictureNumber(int n) { ((AnimatedSprite) getActionSprite()).setCurrentPictureNumber(n); } public void setVerticalSpeed(int speed) { vSpeed = speed; } public int getVerticalSpeed() { return vSpeed; } public void setHorizontalSpeed(int speed) { hSpeed = speed; } public int getHorizontalSpeed() { return hSpeed; } public void walk(boolean action) { walking = action; } public boolean isWalking() { return walking; } public void fly(boolean action) { flying = action; } public boolean isFlying() { return flying; } /** * Moving engine of the robot. */ public void move(int ticks) { if (isFlying()) { ((AnimatedSprite) getActionSprite()).setPause(true); if (!upJet.isVisible()) { upJet.setVisible(true); } setPosition(getX(), getY() - getVerticalSpeed()); if (isWalking() && !horizontalJet.isVisible()) { horizontalJet.setVisible(true); } } else { if (upJet.isVisible()) { upJet.setVisible(false); } if (setPosition(getX(), getY() + getVerticalSpeed())) { ((AnimatedSprite) getActionSprite()).setPause(true); if (isWalking() && !horizontalJet.isVisible()) { horizontalJet.setVisible(true); } } else if (isWalking()) { ((AnimatedSprite) getActionSprite()).setPause(false); if (horizontalJet.isVisible()) { horizontalJet.setVisible(false); } } } if (isWalking()) { setPosition(getX() + getHorizontalSpeed(), getY()); } else { ((AnimatedSprite) getActionSprite()).setPause(true); if (horizontalJet.isVisible()) { horizontalJet.setVisible(false); } } } }