public void onStep() {
   super.onStep();
   float rXOld = rX;
   float rYOld = rY;
   rX = rX - Math.signum(rX) * Game.getDeltaSeconds() * 250;
   rY = rY - Math.signum(rY) * Game.getDeltaSeconds() * 250;
   if (rXOld * rX < 0 || rYOld * rY < 0 || (rXOld == rX && rYOld == rY)) {
     rX = 0;
     rY = 0;
     if (path != null) {
       if (path.size() == 0) {
         // We made it to destination
         path = null;
         callback.execute();
       } else {
         Node next = path.removeFirst();
         rX = -(next.x - xcoord) * 16;
         rY = -(next.y - ycoord) * 16;
         xcoord = next.x;
         ycoord = next.y;
         x = xcoord * 16;
         y = ycoord * 16;
       }
     }
   }
 }
 public void beginStep() {
   List<KeyboardEvent> keys = Game.getKeys();
   if (Keyboard.isKeyDown(Keyboard.KEY_LEFT) && repeatTimers[2] == 0) {
     repeatTimers[2] = 0.12f;
     yesHover = !yesHover;
     AudioPlayer.playAudio("cursor2", 1, 1);
   }
   if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT) && repeatTimers[3] == 0) {
     repeatTimers[3] = 0.12f;
     yesHover = !yesHover;
     AudioPlayer.playAudio("cursor2", 1, 1);
   }
   for (KeyboardEvent ke : keys) {
     if (ke.state) {
       if (ke.key == Keyboard.KEY_RETURN || ke.key == Keyboard.KEY_Z) {
         AudioPlayer.playAudio("select", 1, 1);
         if (yesHover) confirm();
         else cancel();
         destroy();
       }
       if (ke.key == Keyboard.KEY_X) {
         AudioPlayer.playAudio("cancel", 1, 1);
         cancel();
         destroy();
       }
     }
   }
   for (int i = 0; i < repeatTimers.length; i++) {
     if (repeatTimers[i] > 0) {
       repeatTimers[i] -= Game.getDeltaSeconds();
       if (repeatTimers[i] < 0) repeatTimers[i] = 0;
     }
   }
 }
 /* (non-Javadoc)
  * @see chu.engine.menu.TextInputBox#beginStep()
  */
 public void beginStep() {
   List<MouseEvent> mouseEvents = Game.getMouseEvents();
   for (MouseEvent event : mouseEvents) {
     if (event.button == 0) {
       int mX = Math.round(event.x / Game.getScaleX());
       int mY = Math.round((Game.getWindowHeight() - event.y) / Game.getScaleY());
       boolean newHover = (mX >= x && mX < x + width && mY >= y && mY < y + height);
       hasFocus = newHover;
     }
   }
   super.beginStep();
 }
  /* (non-Javadoc)
   * @see chu.engine.Game#init(int, int, java.lang.String)
   */
  public void init(int width, int height, String name) {
    super.init(width, height, name);
    Player p1 = new Player("Player", (byte) 0);
    localPlayer = p1;
    ByteBuffer icon16, icon32;
    icon16 = icon32 = null;
    try {
      icon16 =
          ByteBuffer.wrap(
              TextureLoader.getTexture(
                      "PNG", ResourceLoader.getResourceAsStream("res/gui/icon16.png"))
                  .getTextureData());
      icon32 =
          ByteBuffer.wrap(
              TextureLoader.getTexture(
                      "PNG", ResourceLoader.getResourceAsStream("res/gui/icon32.png"))
                  .getTextureData());
    } catch (IOException e) {
      e.printStackTrace();
    }
    Display.setIcon(new ByteBuffer[] {icon16, icon32});
    FEResources.loadResources();
    FEResources.loadBitmapFonts();
    WeaponFactory.loadWeapons();
    UnitFactory.loadUnits();
    p1.getParty().setColor(Party.TEAM_BLUE);

    /* OpenGL final setup */
    glEnable(GL_LINE_SMOOTH);

    UnitFactory.getUnit("Lyn");
    connect = new ConnectStage();
    setCurrentStage(new TitleStage());
    SoundTrack.loop("main");
  }
 @Override
 public void update() {
   super.update();
   if (dodging) {
     dodgeTimer += Game.getDeltaSeconds();
     if (dodgeTimer > DODGE_DURATION) {
       dodging = false;
       setSpeed(-DodgeAnimation.NORMAL_SPEED);
     }
   }
 }
 public void beginStep() {
   List<MouseEvent> mouseEvents = Game.getMouseEvents();
   for (MouseEvent event : mouseEvents) {
     if (event.button == 0) {
       int mX = Math.round(event.x / Game.getScaleX());
       int mY = Math.round((Game.getWindowHeight() - event.y) / Game.getScaleY());
       boolean newHover = (mX >= x && mX < x + width && mY >= y && mY < y + height);
       hasFocus = newHover;
     }
   }
   super.beginStep();
   if (hasFocus) {
     List<KeyboardEvent> keys = Game.getKeys();
     for (KeyboardEvent ke : keys) {
       if (ke.state) {
         if (ke.key == FEResources.getKeyMapped(Keyboard.KEY_RETURN)) {
           send();
         }
       }
     }
   }
 }
 public void setHp(int hp) {
   this.hp = Math.max(hp, 0);
   if (hp == 0) {
     ((OverworldStage) stage).removeUnit(xcoord, ycoord);
     if (rescuedUnit != null) {
       drop(xcoord, ycoord);
     }
     if (Game.glContextExists()) {
       ((ClientOverworldStage) stage).setControl(false);
       stage.addEntity(new Corpse(this));
     }
   }
 }
 public void beginStep() {
   super.beginStep();
   if (Game.glContextExists() && !sprite.hasAnimation("IDLE")) {
     loadMapSprites();
   }
   if (path != null) {
     String name;
     if (rX > 0) name = "left";
     else if (rX < 0) name = "right";
     else if (rY > 0) name = "up";
     else name = "down";
     sprite.setAnimation(name);
   }
   renderDepth = calcRenderDepth();
 }
  public void render() {
    ClientOverworldStage cs = (ClientOverworldStage) stage;
    Renderer.translate(-cs.camX, -cs.camY);
    Renderer.addClip(0, 0, 368, 240, true);

    if (FEResources.hasTexture(functionalClassName().toLowerCase() + "_map_idle")) {
      Transform t = new Transform();
      if (sprite.getAnimationName().equals("RIGHT")) {
        t.flipHorizontal();
        t.setTranslation(14, 0); // Why do we have to do this?
      }
      Color mod = new Color(1.0f, 1.0f, 1.0f, 1.0f);
      t.setColor(mod);
      if (moved) {
        sprite.render(x + 1 + rX, y + 1 + rY, renderDepth, t, new ShaderArgs("greyscale"));
      } else {
        ShaderArgs args = PaletteSwapper.setup(this);
        sprite.render(x + 1 + rX, y + 1 + rY, renderDepth, t, args);
      }
    } else {
      Color c = !moved ? new Color(getPartyColor()) : new Color(128, 128, 128);
      Renderer.drawRectangle(
          x + 1 + rX, y + 1 + rY, x + 14 + rX, y + 14 + rY, ClientOverworldStage.UNIT_DEPTH, c);
      Renderer.drawString(
          "default_med",
          name.charAt(0) + "" + name.charAt(1),
          x + 2 + rX,
          y + 1 + rY,
          ClientOverworldStage.UNIT_DEPTH);
    }
    if (rescuedUnit != null) {
      counter += Game.getDeltaSeconds();
      counter %= 1;
      if (counter > 0.5) {
        Renderer.render(rescue, 0, 0, 1, 1, x + 9, y + 7, x + 9 + 8, y + 7 + 8, renderDepth);
      }
    }

    Renderer.removeClip();
    Renderer.translate(cs.camX, cs.camY);
  }
 static {
   if (Game.glContextExists()) rescue = FEResources.getTexture("rescue");
 }