Advertisement
staxx6

GameplayState

Oct 27th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. package world0;
  2.  
  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. import org.newdawn.slick.state.BasicGameState;
  9. import org.newdawn.slick.state.StateBasedGame;
  10.  
  11. public class GameplayState extends BasicGameState
  12. {
  13.     int stateID = -1;
  14.    
  15.     Image background = null;
  16.     Image background1 = null;
  17.     Image background2 = null;
  18.     Image ground = null;
  19.  
  20.     private Player player;
  21.    
  22.     GameplayState (int stateID)
  23.     {
  24.         this.stateID = stateID;
  25.     }
  26.    
  27.     @Override
  28.     public int getID()
  29.     {
  30.         return stateID;
  31.     }
  32.  
  33.     public void init (GameContainer gc, StateBasedGame sbg) throws SlickException
  34.     {
  35.         background = new Image("textures/levels/world_0/background0.jpg");
  36.         background1 = new Image("textures/levels/world_0/background1.png");
  37.         background2 = new Image("textures/levels/world_0/background2.png");
  38.         player = new Player(200, 608, new Image("textures/charakters/spieler1.png"));
  39.         ground = new Image("textures/levels/world_0/ground.jpg");
  40.     }
  41.  
  42.     public void render (GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException
  43.     {
  44.         background.draw();
  45.         background1.draw(0, 120);
  46.         background2.draw(0, 100);
  47.         player.draw(g);
  48.         ground.draw(0, gc.getHeight() - ground.getHeight());
  49.     }
  50.    
  51.     public void update (GameContainer gc, StateBasedGame sbg, int delta) throws SlickException
  52.     {
  53.         Input input = gc.getInput();
  54.        
  55.         // yet useless
  56.         int mouseX = input.getMouseX();
  57.         int mouseY = input.getMouseY();
  58.        
  59.         if (input.isKeyPressed(Input.KEY_RIGHT))
  60.         {
  61.             player.updateR(delta);
  62.         }
  63.        
  64.         if (input.isKeyPressed(Input.KEY_LEFT))
  65.         {
  66.             player.updateL(delta);
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement