1 package ru
.deadsoftware
.cavedroid
.game
.mobs
;
3 import com
.badlogic
.gdx
.graphics
.g2d
.SpriteBatch
;
4 import com
.badlogic
.gdx
.math
.Vector2
;
5 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
7 import static ru
.deadsoftware
.cavedroid
.GameScreen
.GP
;
9 public class Player
extends Mob
{
11 public final int[] inventory
;
13 public final int gameMode
;
16 public Player(int gameMode
) {
17 super(0, 0, 4, 30, randomDir(), Type
.MOB
);
18 this.gameMode
= gameMode
;
19 inventory
= new int[9];
23 public void respawn() {
24 Vector2 pos
= getSpawnPoint();
30 private Vector2
getSpawnPoint() {
32 for (y
= 0; y
< GP
.world
.getHeight(); y
++) {
33 if (y
== GP
.world
.getHeight() - 1) {
35 GP
.world
.setForeMap(x
, y
, 1);
38 if (GP
.world
.hasForeAt(x
, y
) && GP
.world
.getForeMapBlock(x
, y
).hasCollision()) {
42 return new Vector2(x
* 16 + 8 - getWidth() / 2, (float) y
* 16 - getHeight());
45 public void setDir(Direction dir
) {
46 if (dir
!= getDirection()) {
56 public void changeDir() {
60 public void draw(SpriteBatch spriteBatch
, float x
, float y
) {
61 if (move
.x
!= 0 || Assets
.playerSprite
[0][2].getRotation() != 0) {
62 Assets
.playerSprite
[0][2].rotate(animDelta
);
63 Assets
.playerSprite
[1][2].rotate(-animDelta
);
64 Assets
.playerSprite
[0][3].rotate(-animDelta
);
65 Assets
.playerSprite
[1][3].rotate(animDelta
);
67 Assets
.playerSprite
[0][2].setRotation(0);
68 Assets
.playerSprite
[1][2].setRotation(0);
69 Assets
.playerSprite
[0][3].setRotation(0);
70 Assets
.playerSprite
[1][3].setRotation(0);
72 if (Assets
.playerSprite
[0][2].getRotation() >= 60 || Assets
.playerSprite
[0][2].getRotation() <= -60) {
73 animDelta
= -animDelta
;
77 Assets
.playerSprite
[1][2].setPosition(x
+ 2, y
+ 8);
78 Assets
.playerSprite
[1][2].draw(spriteBatch
);
80 Assets
.playerSprite
[1][3].setPosition(x
+ 2, y
+ 20);
81 Assets
.playerSprite
[1][3].draw(spriteBatch
);
83 Assets
.playerSprite
[0][3].setPosition(x
+ 2, y
+ 20);
84 Assets
.playerSprite
[0][3].draw(spriteBatch
);
86 spriteBatch
.draw(Assets
.playerSprite
[dirMultiplier()][0], x
, y
);
88 spriteBatch
.draw(Assets
.playerSprite
[dirMultiplier()][1], x
+ 2, y
+ 8);
90 Assets
.playerSprite
[0][2].setPosition(x
+ 2, y
+ 8);
91 Assets
.playerSprite
[0][2].draw(spriteBatch
);