DEADSOFTWARE

Fix script
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / Player.java
1 package ru.deadsoftware.cavedroid.game.mobs;
3 import com.badlogic.gdx.graphics.g2d.Sprite;
4 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
5 import com.badlogic.gdx.math.MathUtils;
6 import com.badlogic.gdx.math.Vector2;
7 import ru.deadsoftware.cavedroid.game.world.GameWorld;
8 import ru.deadsoftware.cavedroid.misc.Assets;
9 import ru.deadsoftware.cavedroid.misc.utils.SpriteUtilsKt;
11 public class Player extends Mob {
13 public final int[] inventory;
14 public int slot;
15 public final int gameMode;
16 public boolean swim;
17 public float headRotation = 0f;
19 public Player() {
20 super(0, 0, 4, 30, randomDir(), Type.MOB);
21 this.gameMode = 1;
22 inventory = new int[9];
23 swim = false;
24 }
26 public void respawn(GameWorld gameWorld) {
27 Vector2 pos = getSpawnPoint(gameWorld);
28 this.x = pos.x;
29 this.y = pos.y;
30 mVelocity.setZero();
31 }
33 private Vector2 getSpawnPoint(GameWorld gameWorld) {
34 int y;
35 for (y = 0; y < gameWorld.getHeight(); y++) {
36 if (y == gameWorld.getHeight() - 1) {
37 y = 60;
38 gameWorld.setForeMap(0, y, 1);
39 break;
40 }
41 if (gameWorld.hasForeAt(0, y) && gameWorld.getForeMapBlock(0, y).hasCollision()) {
42 break;
43 }
44 }
45 return new Vector2(8 - getWidth() / 2, (float) y * 16 - getHeight());
46 }
48 public void setDir(Direction dir) {
49 if (dir != getDirection()) {
50 switchDir();
51 }
52 }
54 @Override
55 public void ai(GameWorld gameWorld, float delta) {
56 }
58 @Override
59 public void changeDir() {
60 }
62 @Override
63 public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
64 updateAnimation(delta);
66 final Sprite backHand = Assets.playerSprite[1][2];
67 final Sprite backLeg = Assets.playerSprite[1][3];
68 final Sprite frontLeg = Assets.playerSprite[0][3];
69 final Sprite head = Assets.playerSprite[dirMultiplier()][0];
70 final Sprite body = Assets.playerSprite[dirMultiplier()][1];
71 final Sprite frontHand = Assets.playerSprite[0][2];
73 SpriteUtilsKt.draw(spriteBatch, backHand, x + 2, y + 8, -mAnim);
74 SpriteUtilsKt.draw(spriteBatch, backLeg, x + 2, y + 20, mAnim);
75 SpriteUtilsKt.draw(spriteBatch, frontLeg, x + 2, y + 20, -mAnim);
76 SpriteUtilsKt.draw(spriteBatch, head, x, y, headRotation);
77 SpriteUtilsKt.draw(spriteBatch, body, x + 2, y + 8);
78 SpriteUtilsKt.draw(spriteBatch, frontHand, x + 2, y + 8, mAnim);
79 }
81 }