SHARE
TWEET

Untitled

a guest Sep 6th, 2014 227 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package project.x;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.image.BufferedImage;
  5. import project.x.tiles.Tile;
  6.  
  7. public class Player {
  8.  
  9.     public boolean up = false, down = false, left = false, right = false;
  10.     public static int playerDirection = 0;
  11.     private int x, y, xOffset, yOffset, xSpeed, ySpeed;
  12.     private ImageManager im;
  13.     private final int speed = 1;
  14.     private final int TileSize = 16;
  15.     private int yDir, xDir;
  16.    
  17.     public Player(int x, int y, int xOffset, int yOffset, ImageManager im) {
  18.        
  19.         this.x = x;
  20.         this.y = y;
  21.         this.im = im;
  22.         this.xOffset = xOffset;
  23.         this.yOffset = yOffset;
  24.         this.xSpeed = 0;
  25.         this.ySpeed = 0;
  26.        
  27.     }
  28.    
  29.     public void tick() {
  30.        
  31.         xSpeed = 0;
  32.         ySpeed = 0;
  33.        
  34.         if (up == true && Display.getPlayer().get_yOffset() != 0) {
  35.             ySpeed -= speed;
  36.         }
  37.         else if (down == true) {
  38.             ySpeed += speed;
  39.         }
  40.         if (left == true && Display.getPlayer().get_xOffset() != 0) {
  41.             xSpeed -= speed;
  42.         }
  43.         else if (right == true) {
  44.             xSpeed += speed;
  45.         }
  46.         move(xSpeed, ySpeed);
  47.     }
  48.    
  49.     public void render(Graphics g) {
  50.         if (playerDirection == 0) {
  51.             Tile.playerFront.render(g, x, y);
  52.             //g.drawImage(im.playerFront, x, y, 16, 16, null);
  53.         } else if (playerDirection == 1) {
  54.             Tile.playerLeft.render(g, x, y);
  55.             //g.drawImage(im.playerLeft, x, y, 16, 16, null);
  56.         } else if (playerDirection == 2) {
  57.             Tile.playerRight.render(g, x, y);
  58.             //g.drawImage(im.playerRight, x, y, 16, 16, null);
  59.         } else if (playerDirection == 3) {
  60.             Tile.playerBack.render(g, x, y);
  61.             //g.drawImage(im.playerBack, x, y, 16, 16, null);
  62.         }
  63.     }
  64.    
  65.     public void move(int xSpeed, int ySpeed) {
  66.         if (!collision(xSpeed, ySpeed)) {
  67.             xOffset += xSpeed;
  68.             yOffset += ySpeed;
  69.         }
  70.     }
  71.    
  72.     public boolean collision(int xSpeed, int ySpeed) {
  73.         if (!Display.getLevel().getTile((xOffset + xSpeed + x) / 16, (yOffset + ySpeed + y) / 16).PassThrough()) {
  74.             return true;
  75.         }
  76.         if (!Display.getLevel().getTile((xOffset + xSpeed + x + TileSize - 1) / 16, (yOffset + ySpeed + y) / 16).PassThrough()) {
  77.             return true;
  78.         }
  79.         if (!Display.getLevel().getTile((xOffset + xSpeed + x) / 16, (yOffset + ySpeed + y + TileSize - 1) / 16).PassThrough()) {
  80.             return true;
  81.         }
  82.         if (!Display.getLevel().getTile((xOffset + xSpeed + x + TileSize - 1) / 16, (yOffset + ySpeed + y + TileSize - 1) / 16).PassThrough()) {
  83.             return true;
  84.         }
  85.        
  86.         return false;
  87.     }
  88.    
  89.     public int get_xOffset() {
  90.         return xOffset;
  91.     }
  92.    
  93.     public int get_yOffset() {
  94.         return yOffset;
  95.     }
  96.    
  97.     public void set_xOffset(int xValue) {
  98.         this.xOffset = xValue;
  99.     }
  100.    
  101.     public void set_yOffset(int yValue) {
  102.         this.yOffset = yValue;
  103.     }
  104.    
  105.     public int get_playerX() {
  106.        return x;
  107.     }
  108.    
  109.     public int get_playerY() {
  110.         return y;
  111.     }
  112. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top