DEADSOFTWARE

11838d16195e8a3bf5e4c7faad17126704afc85a
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / objects / Player.java
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;
14 public Vector2 pos;
15 public Vector2 move;
16 public int width, height, dir, texWidth, hp;
17 public boolean canJump;
18 public int[] inv;
19 public boolean flyMode = false;
20 public int gameMode;
22 public Player(GameWorld world, int gameMode) {
23 this.gameMode = gameMode;
24 pos = getSpawnPoint(world).cpy();
25 move = new Vector2(0, 0);
26 width = 4;
27 height = 30;
28 texWidth = 8;
29 inv = new int[9];
30 hp = 20;
31 }
33 public void respawn(GameWorld world) {
34 pos.set(getSpawnPoint(world));
35 move.setZero();
36 hp = 20;
37 }
39 private Vector2 getSpawnPoint(GameWorld world) {
40 int x = 0, y;
41 for (y = 0; y < world.getHeight(); y++) {
42 if (y == world.getHeight() - 1) {
43 y = 60;
44 world.setForeMap(x, y, 1);
45 break;
46 }
47 if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).coll) break;
48 }
49 x = x * 16 + texWidth / 2;
50 y = y * 16 - height;
51 return new Vector2(x, y);
52 }
54 public Rectangle getRect() {
55 return new Rectangle(pos.x + 2, pos.y, width, height);
56 }
58 }