Package it.marteEngine.test.stateMachine

Source Code of it.marteEngine.test.stateMachine.IdleState

package it.marteEngine.test.stateMachine;

import it.marteEngine.State;
import it.marteEngine.entity.Entity;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class IdleState implements State {

  private Image image;

  private Entity entity;

  public IdleState(Entity e) {
    this.entity = e;
  }

  public void init() {
    try {
      image = new Image("data/face-sleep.png");
    } catch (SlickException e) {
      e.printStackTrace();
    }
  }

  public void render(Graphics g) {
    g.drawImage(entity.getCurrentImage(), entity.x, entity.y);
    // render status image on top left of parent image
    g.drawImage(image, entity.x - 10, entity.y - 10);
  }

  public void update(GameContainer container, int delta) {
    // do nothing untile player try to move
    Input input = container.getInput();
    if (input.isKeyPressed(Input.KEY_SPACE)) {
      entity.stateManager.enter(MovingState.class);
    }
  }

}
TOP

Related Classes of it.marteEngine.test.stateMachine.IdleState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.