Advertisement
Guest User

Player

a guest
Jun 13th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package com.thecherno.rain.entity.mob;
  2.  
  3. import com.thecherno.rain.graphics.Screen;
  4. import com.thecherno.rain.graphics.Sprite;
  5. import com.thecherno.rain.input.Keyboard;
  6.  
  7. public class Player extends Mob {
  8.    
  9.     private Keyboard input;
  10.    
  11.     public Player(Keyboard input) {
  12.         this.input = input;
  13.     }
  14.    
  15.     public Player(int x, int y, Keyboard input) {
  16.         this.x = x;
  17.         this.y = y;
  18.         this.input = input;
  19.     }
  20.    
  21.     public void update() {
  22.         int xa = 0, ya = 0;
  23.         if (input.up) ya--;
  24.         if (input.down) ya++;
  25.         if (input.left) xa--;
  26.         if (input.right) xa++;
  27.        
  28.         if (xa != 0 || ya != 0) move(xa, ya);
  29.     }
  30.    
  31.     public void render(Screen screen) {
  32.         int xx = x - 16;
  33.         int yy = y - 16;
  34.        
  35.         screen.renderPlayer(xx, yy, Sprite.player0);
  36.         screen.renderPlayer(xx + 16, yy, Sprite.player1);
  37.         screen.renderPlayer(xx, yy + 16, Sprite.player2);
  38.         screen.renderPlayer(xx + 16, yy + 16, Sprite.player3);
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement