1 package ru
.deadsoftware
.cavedroid
.game
.objects
;
3 import com
.badlogic
.gdx
.graphics
.g2d
.SpriteBatch
;
4 import com
.badlogic
.gdx
.math
.Rectangle
;
5 import com
.badlogic
.gdx
.math
.Vector2
;
6 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Mob
;
7 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
9 import java
.io
.Serializable
;
11 import static ru
.deadsoftware
.cavedroid
.GameScreen
.GP
;
13 public class Player
extends Mob
implements Serializable
{
15 public final int[] inventory
;
17 public final int gameMode
;
20 public Player(int gameMode
) {
21 super(0, 0, 4, 30, 1);
22 this.gameMode
= gameMode
;
23 inventory
= new int[9];
27 public void respawn() {
28 pos
.set(getSpawnPoint());
32 private Vector2
getSpawnPoint() {
34 for (y
= 0; y
< GP
.world
.getHeight(); y
++) {
35 if (y
== GP
.world
.getHeight() - 1) {
37 GP
.world
.setForeMap(x
, y
, 1);
40 if (GP
.world
.hasForeAt(x
, y
) && GP
.world
.getForeMapBlock(x
, y
).hasCollision()) break;
42 return new Vector2(x
* 16 + 8 - getWidth() / 2, (float) y
* 16 - getHeight());
45 public void setDir(int dir
) {
46 if (dir
!= getDirection()) switchDir();
54 public void changeDir() {
58 public void draw(SpriteBatch spriteBatch
, float x
, float y
) {
59 if (mov
.x
!= 0 || Assets
.playerSprite
[0][2].getRotation() != 0) {
60 Assets
.playerSprite
[0][2].rotate(animDelta
);
61 Assets
.playerSprite
[1][2].rotate(-animDelta
);
62 Assets
.playerSprite
[0][3].rotate(-animDelta
);
63 Assets
.playerSprite
[1][3].rotate(animDelta
);
65 Assets
.playerSprite
[0][2].setRotation(0);
66 Assets
.playerSprite
[1][2].setRotation(0);
67 Assets
.playerSprite
[0][3].setRotation(0);
68 Assets
.playerSprite
[1][3].setRotation(0);
70 if (Assets
.playerSprite
[0][2].getRotation() >= 60 || Assets
.playerSprite
[0][2].getRotation() <= -60)
71 animDelta
= -animDelta
;
74 Assets
.playerSprite
[1][2].setPosition(x
- 6, y
);
75 Assets
.playerSprite
[1][2].draw(spriteBatch
);
77 Assets
.playerSprite
[1][3].setPosition(x
- 6, y
+ 10);
78 Assets
.playerSprite
[1][3].draw(spriteBatch
);
80 Assets
.playerSprite
[0][3].setPosition(x
- 6, y
+ 10);
81 Assets
.playerSprite
[0][3].draw(spriteBatch
);
83 spriteBatch
.draw(Assets
.playerSprite
[getDirection()][0], x
- 2, y
- 2);
85 spriteBatch
.draw(Assets
.playerSprite
[getDirection()][1], x
- 2, y
+ 8);
87 Assets
.playerSprite
[0][2].setPosition(x
- 6, y
);
88 Assets
.playerSprite
[0][2].draw(spriteBatch
);
92 public int getType() {
97 public Rectangle
getRect() {
98 return new Rectangle(pos
.x
, pos
.y
, getWidth(), getHeight());