public void shrink(int x, int y) { SWorld world = (SWorld) getWorld(); Actor futureMain = new Minion(); world.addObject(futureMain, x, y, false); world.mainActor = futureMain; setLocation(x, y); invincibilityDelayCount = 0; world.removeObject(this); minion.setState(minion.getMinion()); }
/** * Moves the actor with appropriate image. Checks for obstacles and adjusts the position of the * actor accordingly. */ public void moveHorizontally() { setLocation(getX() + xSpeed, getY()); while (getOneObjectAtOffset(getImage().getWidth() / 2, 0, Block.class) != null) { setLocation(getX() - 1, getY()); xSpeed = 0; } while (getOneObjectAtOffset(-getImage().getWidth() / 2, 0, Block.class) != null) { setLocation(getX() + 1, getY()); xSpeed = 0; } while (getOneObjectAtOffset(getImage().getWidth() / 2, 0, Brick.class) != null) { setLocation(getX() - 1, getY()); xSpeed = 0; } while (getOneObjectAtOffset(-getImage().getWidth() / 2, 0, Brick.class) != null) { setLocation(getX() + 1, getY()); xSpeed = 0; } if (Greenfoot.isKeyDown("right")) { if (xSpeed < 0) { xSpeed = 0; } if (xSpeed < 5) { xSpeed = xSpeed + 1; } SWorld sWorld = (SWorld) getWorld(); sWorld.minionL = false; } if (Greenfoot.isKeyDown("left")) { if (xSpeed > 0) { xSpeed = 0; } if (xSpeed > -5) { xSpeed = xSpeed - 1; } SWorld sWorld = (SWorld) getWorld(); sWorld.minionL = true; } if (!Greenfoot.isKeyDown("left") && !Greenfoot.isKeyDown("right")) { xSpeed = 0; } if (Greenfoot.isKeyDown("up")) { jump(); } if (Greenfoot.isKeyDown("space")) { shoot(); } }