Package it.marteEngine.test.stateMachine

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

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 CombatState implements State {

  private Image image;

  private Entity entity;

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

  public void init() {
    try {
      image = new Image("data/sword-icon.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) {
    Input input = container.getInput();
    if (input.isKeyPressed(Input.KEY_SPACE)) {
      entity.stateManager.enter(IdleState.class);
    }
  }

}
TOP

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

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.