Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- public class SimpleGame extends BasicGame{
- Image land = null;
- Image plane = null;
- float x = 400; //plane pos x
- float y = 300; //plane pos y
- float scale = 1.0f; //plane size
- public SimpleGame(){
- super("CLick2DPath2Glory - Simple Game");
- }
- @Override
- public void init(GameContainer gc)throws SlickException{
- land = new Image("fetch.jpg");
- plane = new Image("fetch2.png");
- }
- @Override
- public void update(GameContainer gc, int delta)throws SlickException{
- Input input = gc.getInput();
- if(input.isKeyDown(Input.KEY_A)){
- plane.rotate(-0.2f * delta);
- }
- if(input.isKeyDown(Input.KEY_D)){
- plane.rotate(0.2f * delta);
- }
- if(input.isKeyDown(Input.KEY_W)){
- float hip = 0.4f * delta;
- float rotation = plane.getRotation();
- x+= hip * Math.sin(Math.toRadians(rotation));
- y-= hip * Math.cos(Math.toRadians(rotation));
- }
- if(input.isKeyDown(Input.KEY_2)){
- scale += (scale >= 5.0f) ? 0 : 0.1f;
- plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
- }
- if(input.isKeyDown(Input.KEY_1)){
- scale -= (scale <= 1.0f) ? 0 : 0.1f;
- plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
- }
- }
- public void render(GameContainer gc, Graphics g)throws SlickException{
- land.draw(0,0);
- plane.draw(x, y, scale);
- }
- public static void main(String[] args)throws SlickException{
- AppGameContainer app = new AppGameContainer(new SimpleGame());
- app.setDisplayMode(800, 600, false);
- app.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment