public void handleInput() { InputHandler input = Game.getInstance().getInputHandler(); if (input.isSpacePressed()) { // If previous state complete if (state.isComplete()) { // Jump again state = new PlayerJumping(this); } } // if not running and previous state complete, run again else if (!(state instanceof PlayerRunning) && state.isComplete()) state = new PlayerRunning(this); }
@Override public void draw(Graphics2D g) { // Draw small black rectangle to merge // road and dino tail g.setColor(GameConfig.COLOR_BACKGROUND); g.fillRect(x + 6, y + 28, 20, 10); state.draw(g); }
@Override public void update(long elapsedTime) { handleInput(); state.update(elapsedTime); }