Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project.x;
- import java.awt.Graphics;
- import java.awt.image.BufferedImage;
- import project.x.tiles.Tile;
- public class Player {
- public boolean up = false, down = false, left = false, right = false;
- public static int playerDirection = 0;
- private int x, y, xOffset, yOffset, xSpeed, ySpeed;
- private ImageManager im;
- private final int speed = 1;
- private final int TileSize = 16;
- private int yDir, xDir;
- public Player(int x, int y, int xOffset, int yOffset, ImageManager im) {
- this.x = x;
- this.y = y;
- this.im = im;
- this.xOffset = xOffset;
- this.yOffset = yOffset;
- this.xSpeed = 0;
- this.ySpeed = 0;
- }
- public void tick() {
- xSpeed = 0;
- ySpeed = 0;
- if (up == true && Display.getPlayer().get_yOffset() != 0) {
- ySpeed -= speed;
- }
- else if (down == true) {
- ySpeed += speed;
- }
- if (left == true && Display.getPlayer().get_xOffset() != 0) {
- xSpeed -= speed;
- }
- else if (right == true) {
- xSpeed += speed;
- }
- move(xSpeed, ySpeed);
- }
- public void render(Graphics g) {
- if (playerDirection == 0) {
- Tile.playerFront.render(g, x, y);
- //g.drawImage(im.playerFront, x, y, 16, 16, null);
- } else if (playerDirection == 1) {
- Tile.playerLeft.render(g, x, y);
- //g.drawImage(im.playerLeft, x, y, 16, 16, null);
- } else if (playerDirection == 2) {
- Tile.playerRight.render(g, x, y);
- //g.drawImage(im.playerRight, x, y, 16, 16, null);
- } else if (playerDirection == 3) {
- Tile.playerBack.render(g, x, y);
- //g.drawImage(im.playerBack, x, y, 16, 16, null);
- }
- }
- public void move(int xSpeed, int ySpeed) {
- if (!collision(xSpeed, ySpeed)) {
- xOffset += xSpeed;
- yOffset += ySpeed;
- }
- }
- public boolean collision(int xSpeed, int ySpeed) {
- if (!Display.getLevel().getTile((xOffset + xSpeed + x) / 16, (yOffset + ySpeed + y) / 16).PassThrough()) {
- return true;
- }
- if (!Display.getLevel().getTile((xOffset + xSpeed + x + TileSize - 1) / 16, (yOffset + ySpeed + y) / 16).PassThrough()) {
- return true;
- }
- if (!Display.getLevel().getTile((xOffset + xSpeed + x) / 16, (yOffset + ySpeed + y + TileSize - 1) / 16).PassThrough()) {
- return true;
- }
- if (!Display.getLevel().getTile((xOffset + xSpeed + x + TileSize - 1) / 16, (yOffset + ySpeed + y + TileSize - 1) / 16).PassThrough()) {
- return true;
- }
- return false;
- }
- public int get_xOffset() {
- return xOffset;
- }
- public int get_yOffset() {
- return yOffset;
- }
- public void set_xOffset(int xValue) {
- this.xOffset = xValue;
- }
- public void set_yOffset(int yValue) {
- this.yOffset = yValue;
- }
- public int get_playerX() {
- return x;
- }
- public int get_playerY() {
- return y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement