示例#1
0
  @Override
  public void update(long dt) {
    camera.update(dt);
    state.update(dt);

    playerDisplayRotation.update(dt);

    if (!(pmx == 0 && pmy == 0) && !state.isBlockAnimInEffect()) {
      movePlayer(pmx, pmy);
      pmx = pmy = 0;
    }

    if (state.hasPlayerWon()) {
      if (modeController.getCurrentMode().getId() == getId()) {
        modeController.popMode();

        String exitText = context.getString(state.exitText);
        if (exitText == null) {
          exitText = "Congratulations!";
        }

        modeController.pushMode(
            new GameDialogMode(
                this,
                exitText,
                new GameDialogMode.OnResult() {
                  public void onResult() {
                    state.revertAllMoves();
                    state.update(
                        0); // Update because revert doesn't take effect until next update is called
                  }
                }));
      }
    }
  }
示例#2
0
  private void movePlayer(int x, int y) {
    if (!(x == 0 && y == 0)) {
      state.movePlayer(x, y);

      if (x == 0 && y == 1 && playerRotation != 0) {
        playerDisplayRotation.initLinearAnimation(0 - playerRotation, 100);
        playerRotation = 0;
      } else if (x == 1 && y == 0 && playerRotation != 90) {
        playerDisplayRotation.initLinearAnimation(90 - playerRotation, 100);
        playerRotation = 90;
      } else if (x == 0 && y == -1 && playerRotation != 180) {
        playerDisplayRotation.initLinearAnimation(180 - playerRotation, 100);
        playerRotation = 180;
      } else if (x == -1 && y == 0 && playerRotation != 270) {
        playerDisplayRotation.initLinearAnimation(270 - playerRotation, 100);
        playerRotation = 270;
      }
    }
  }
示例#3
0
  private void drawPlayer(GL10 gl, GameState state) {
    gl.glColor4f(1, 1, 1, 1);
    gl.glPushMatrix();

    gl.glTranslatef(
        state.playerDisplayPosition.getX(),
        state.playerDisplayPosition.getY(),
        state.playerDisplayPosition.getZ());

    gl.glTranslatef(0.5f, 0.5f, 0.5f); // rotate about the center of the player
    gl.glRotatef(playerDisplayRotation.getValue(), 0, 1, 0);
    gl.glTranslatef(-0.5f, -0.5f, -0.5f);
    playerModel.prerender(gl);
    gameResources.bindTexture(gl, R.drawable.player);
    playerModel.render(gl);
    playerModel.postrender(gl);

    gl.glPopMatrix();
  }