Advertisement
daixso

First Slick Game

Oct 30th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. import org.newdawn.slick.AppGameContainer;
  2. import org.newdawn.slick.BasicGame;
  3. import org.newdawn.slick.GameContainer;
  4. import org.newdawn.slick.Graphics;
  5. import org.newdawn.slick.Image;
  6. import org.newdawn.slick.Input;
  7. import org.newdawn.slick.SlickException;
  8.  
  9. public class SimpleGame extends BasicGame{
  10.     Image land = null;
  11.     Image plane = null;
  12.     float x = 400; //plane pos x
  13.     float y = 300; //plane pos y
  14.     float scale = 1.0f; //plane size
  15.    
  16.     public SimpleGame(){
  17.         super("CLick2DPath2Glory - Simple Game");
  18.     }
  19.    
  20.     @Override
  21.     public void init(GameContainer gc)throws SlickException{
  22.         land = new Image("fetch.jpg");
  23.         plane = new Image("fetch2.png");
  24.     }
  25.    
  26.     @Override
  27.     public void update(GameContainer gc, int delta)throws SlickException{
  28.         Input input = gc.getInput();
  29.         if(input.isKeyDown(Input.KEY_A)){
  30.             plane.rotate(-0.2f * delta);
  31.         }
  32.         if(input.isKeyDown(Input.KEY_D)){
  33.             plane.rotate(0.2f * delta);
  34.         }
  35.         if(input.isKeyDown(Input.KEY_W)){
  36.             float hip = 0.4f * delta;
  37.            
  38.             float rotation = plane.getRotation();
  39.            
  40.             x+= hip * Math.sin(Math.toRadians(rotation));
  41.             y-= hip * Math.cos(Math.toRadians(rotation));
  42.         }
  43.         if(input.isKeyDown(Input.KEY_2)){
  44.             scale += (scale >= 5.0f) ? 0 : 0.1f;
  45.             plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
  46.         }
  47.         if(input.isKeyDown(Input.KEY_1)){
  48.             scale -= (scale <= 1.0f) ? 0 : 0.1f;
  49.             plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
  50.         }
  51.     }
  52.    
  53.     public void render(GameContainer gc, Graphics g)throws SlickException{
  54.         land.draw(0,0);
  55.         plane.draw(x, y, scale);
  56.     }
  57.    
  58.     public static void main(String[] args)throws SlickException{
  59.         AppGameContainer app = new AppGameContainer(new SimpleGame());
  60.        
  61.         app.setDisplayMode(800, 600, false);
  62.         app.start();
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement