Package br.com.fabioaraujo.slick2d

Source Code of br.com.fabioaraujo.slick2d.SimpleGameSlick2d

package br.com.fabioaraujo.slick2d;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
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;
import org.newdawn.slick.SpriteSheet;

public class SimpleGameSlick2d extends BasicGame{

  private Image land;
  private Image plane;
  private float planeX = 0;
  private float planeY = 0;
  private float scale = 1;
  private Image sprites;

  public SimpleGameSlick2d() {
    super("My Simple Game");
  }

  @Override
  public void render(GameContainer container, Graphics g)
      throws SlickException {
    land.draw(0, 0);
    plane.draw(planeX, planeY, scale);
    sprites.draw(planeX + 100, planeY, 1.5f);
  }

  @Override
  public void init(GameContainer container) throws SlickException {
    land = new Image("textures/land.jpg");
    plane = new Image("textures/plane.png");
    SpriteSheet sheet = new SpriteSheet("textures/sprites.png", 32, 32);
    sprites = sheet.getSprite(1, 0);
  }

  @Override
  public void update(GameContainer container, int delta)
      throws SlickException {
    Input input = container.getInput();

    if(input.isKeyDown(Input.KEY_A)){
      planeX -= 3;
    }
    if(input.isKeyDown(Input.KEY_D)){
      planeX += 3;
    }
    if(input.isKeyDown(Input.KEY_W)){
      planeY -= 3;
    }
    if(input.isKeyDown(Input.KEY_S)){
      planeY += 3;
    }
  }

  public static void main(String[] args) throws SlickException {
    AppGameContainer app =
        new AppGameContainer(new SimpleGameSlick2d());

    app.setDisplayMode(800, 600, false);

    app.start();
  }
}
TOP

Related Classes of br.com.fabioaraujo.slick2d.SimpleGameSlick2d

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.