5672807cc1205182190ff939d84913adc81f8c55
1 package ru
.deadsoftware
.cavecraft
.game
.objects
;
3 import com
.badlogic
.gdx
.math
.Rectangle
;
4 import com
.badlogic
.gdx
.math
.Vector2
;
5 import ru
.deadsoftware
.cavecraft
.game
.GameItems
;
6 import ru
.deadsoftware
.cavecraft
.game
.GameWorld
;
8 import java
.io
.Serializable
;
10 public class Player
implements Serializable
{
12 public static int ANIM_SPEED
= 6;
16 private int width
, height
, dir
, hp
;
17 public boolean canJump
;
19 public boolean flyMode
= false;
22 public Player(GameWorld world
, int gameMode
) {
23 this.gameMode
= gameMode
;
24 mov
= new Vector2(0, 0);
29 pos
= getSpawnPoint(world
).cpy();
32 public void respawn(GameWorld world
) {
33 pos
.set(getSpawnPoint(world
));
38 private Vector2
getSpawnPoint(GameWorld world
) {
40 for (y
= 0; y
< world
.getHeight(); y
++) {
41 if (y
== world
.getHeight() - 1) {
43 world
.setForeMap(x
, y
, 1);
46 if (world
.getForeMap(x
, y
) > 0 && GameItems
.getBlock(world
.getForeMap(x
, y
)).hasCollision()) break;
48 return new Vector2(x
* 16 + 8 - (float) getWidth() / 2, (float) y
* 16 - getHeight());
51 public int getMapX() {
52 return (int) (pos
.x
+ (getWidth() / 2)) / 16;
55 public int getMapY() {
56 return (int) (pos
.y
+ (getHeight() / 2)) / 16;
59 public int getWidth() {
63 public int getHeight() {
71 public void setHp(int hp
) {
79 public void setDir(int dir
) {
83 public Rectangle
getRect() {
84 return new Rectangle(pos
.x
, pos
.y
, getWidth(), getHeight());