1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package pathgame.gameplay;
- import pathgame.tilemap.Tile;
- import pathgame.tilemap.TileMap;
- public class Player
- {
- private static final float SPEED = 0.125f;
- private float lastX = 0;
- private float lastY = 0;
- private float x = 0;
- private float y = 0;
- private float velX = 0;
- private float velY = 0;
- private boolean isMoving = false;
- public Player()
- {
- }
- public float getLastX()
- {
- return lastX;
- }
- public float getLastY()
- {
- return lastY;
- }
- public float getX()
- {
- return x;
- }
- public float getY()
- {
- return y;
- }
- public void tick(TileMap map)
- {
- lastX = x;
- lastY = y;
- if(isOnTile())
- {
- velX = 0.0f;
- velY = 0.0f;
- if(isMoving)
- {
- //TODO: +Energy
- //Tile currTile = map.getTile((int)x,(int) y);
- }
- isMoving = false;
- }
- if(Keys.LEFT_KEY.isDown() && !isMoving && x > 0)
- {
- velX = -SPEED;
- isMoving = true;
- }
- else if(Keys.RIGHT_KEY.isDown() && !isMoving && x < map.getWidth() - 1)
- {
- velX = SPEED;
- isMoving = true;
- }
- else if(Keys.UP_KEY.isDown() && !isMoving && y > 0)
- {
- velY = -SPEED;
- isMoving = true;
- }
- else if(Keys.DOWN_KEY.isDown() && !isMoving && y < map.getHeight() - 1)
- {
- velY = SPEED;
- isMoving = true;
- }
- x += velX;
- y += velY;
- }
- private boolean isOnTile()
- {
- return Math.abs(x - Math.round(x)) < 0.01f && Math.abs(y - Math.round(y)) < 0.01f;
- }
- }
|