0f12f18f5548f7de52903d7c58893df76ecb92fe
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
.GameItems
;
7 import ru
.deadsoftware
.cavedroid
.game
.GameWorld
;
8 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Mob
;
9 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
11 import java
.io
.Serializable
;
13 import static ru
.deadsoftware
.cavedroid
.GameScreen
.GP
;
15 public class Player
extends Mob
implements Serializable
{
17 public int[] inventory
;
22 public Player(int gameMode
) {
23 super(0, 0, 4, 30, 1);
24 this.gameMode
= gameMode
;
25 inventory
= new int[9];
29 public void respawn() {
30 pos
.set(getSpawnPoint());
34 private Vector2
getSpawnPoint() {
36 for (y
= 0; y
< GP
.world
.getHeight(); y
++) {
37 if (y
== GP
.world
.getHeight() - 1) {
39 GP
.world
.setForeMap(x
, y
, 1);
42 if (GP
.world
.hasForeAt(x
, y
) && GP
.world
.getForeMapBlock(x
, y
).hasCollision()) break;
44 return new Vector2(x
* 16 + 8 - getWidth() / 2, (float) y
* 16 - getHeight());
47 public void setDir(int dir
) {
48 if (dir
!= getDirection()) switchDir();
56 public void changeDir() {
60 public void draw(SpriteBatch spriteBatch
, float x
, float y
) {
61 if (mov
.x
!= 0 || Assets
.plSprite
[0][2].getRotation() != 0) {
62 Assets
.plSprite
[0][2].rotate(animDelta
);
63 Assets
.plSprite
[1][2].rotate(-animDelta
);
64 Assets
.plSprite
[0][3].rotate(-animDelta
);
65 Assets
.plSprite
[1][3].rotate(animDelta
);
67 Assets
.plSprite
[0][2].setRotation(0);
68 Assets
.plSprite
[1][2].setRotation(0);
69 Assets
.plSprite
[0][3].setRotation(0);
70 Assets
.plSprite
[1][3].setRotation(0);
72 if (Assets
.plSprite
[0][2].getRotation() >= 60 || Assets
.plSprite
[0][2].getRotation() <= -60)
73 animDelta
= -animDelta
;
76 Assets
.plSprite
[1][2].setPosition(x
- 6, y
);
77 Assets
.plSprite
[1][2].draw(spriteBatch
);
79 Assets
.plSprite
[1][3].setPosition(x
- 6, y
+ 10);
80 Assets
.plSprite
[1][3].draw(spriteBatch
);
82 Assets
.plSprite
[0][3].setPosition(x
- 6, y
+ 10);
83 Assets
.plSprite
[0][3].draw(spriteBatch
);
85 spriteBatch
.draw(Assets
.plSprite
[getDirection()][0], x
- 2, y
- 2);
87 spriteBatch
.draw(Assets
.plSprite
[getDirection()][1], x
- 2, y
+ 8);
89 Assets
.plSprite
[0][2].setPosition(x
- 6, y
);
90 Assets
.plSprite
[0][2].draw(spriteBatch
);
94 public int getType() {
99 public Rectangle
getRect() {
100 return new Rectangle(pos
.x
, pos
.y
, getWidth(), getHeight());