1 package ru
.deadsoftware
.cavedroid
.game
.objects
;
3 import com
.badlogic
.gdx
.graphics
.g2d
.SpriteBatch
;
4 import com
.badlogic
.gdx
.math
.MathUtils
;
5 import com
.badlogic
.gdx
.math
.Rectangle
;
6 import com
.badlogic
.gdx
.math
.Vector2
;
7 import ru
.deadsoftware
.cavedroid
.game
.GameItems
;
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
{
22 public Player(int gameMode
) {
23 super(0, 0, 4, 30, 1, true);
24 this.gameMode
= gameMode
;
26 pos
= getSpawnPoint().cpy();
30 public void respawn() {
31 pos
.set(getSpawnPoint());
35 private Vector2
getSpawnPoint() {
37 for (y
= 0; y
< GP
.world
.getHeight(); y
++) {
38 if (y
== GP
.world
.getHeight() - 1) {
40 GP
.world
.setForeMap(x
, y
, 1);
43 if (GP
.world
.getForeMap(x
, y
) > 0 && GameItems
.getBlock(GP
.world
.getForeMap(x
, y
)).hasCollision()) break;
45 return new Vector2(x
* 16 + 8 - (float) getWidth() / 2, (float) y
* 16 - getHeight());
48 public void setDir(int dir
) {
49 if (dir
!= getDir()) switchDir();
57 public void changeDir() {
61 public void draw(SpriteBatch spriteBatch
, float x
, float y
) {
62 if (mov
.x
!= 0 || Assets
.plSprite
[0][2].getRotation() != 0) {
63 Assets
.plSprite
[0][2].rotate(animDelta
);
64 Assets
.plSprite
[1][2].rotate(-animDelta
);
65 Assets
.plSprite
[0][3].rotate(-animDelta
);
66 Assets
.plSprite
[1][3].rotate(animDelta
);
68 Assets
.plSprite
[0][2].setRotation(0);
69 Assets
.plSprite
[1][2].setRotation(0);
70 Assets
.plSprite
[0][3].setRotation(0);
71 Assets
.plSprite
[1][3].setRotation(0);
73 if (Assets
.plSprite
[0][2].getRotation() >= 60 || Assets
.plSprite
[0][2].getRotation() <= -60)
74 animDelta
= -animDelta
;
77 Assets
.plSprite
[1][2].setPosition(x
- 6, y
);
78 Assets
.plSprite
[1][2].draw(spriteBatch
);
80 Assets
.plSprite
[1][3].setPosition(x
- 6, y
+ 10);
81 Assets
.plSprite
[1][3].draw(spriteBatch
);
83 Assets
.plSprite
[0][3].setPosition(x
- 6, y
+ 10);
84 Assets
.plSprite
[0][3].draw(spriteBatch
);
86 spriteBatch
.draw(Assets
.plSprite
[getDir()][0], x
- 2, y
- 2);
88 spriteBatch
.draw(Assets
.plSprite
[getDir()][1], x
- 2, y
+ 8);
90 if (inv
[invSlot
] > 0) {
91 float handRotation
= MathUtils
.degRad
* Assets
.plSprite
[0][2].getRotation();
92 switch (GameItems
.getItem(inv
[invSlot
]).getType()) {
94 Assets
.blockTex
[GameItems
.getItem(inv
[invSlot
]).getTex()].setPosition(
95 x
- 8 * MathUtils
.sin(handRotation
),
96 y
+ 6 + 8 * MathUtils
.cos(handRotation
));
97 Assets
.blockTex
[GameItems
.getItem(inv
[invSlot
]).getTex()].draw(spriteBatch
);
100 Assets
.itemTex
[GameItems
.getItem(inv
[invSlot
]).getTex()].flip((getDir() == 0), false);
101 Assets
.itemTex
[GameItems
.getItem(inv
[invSlot
]).getTex()].setRotation(
102 -45 + getDir() * 90 + Assets
.plSprite
[0][2].getRotation());
103 Assets
.itemTex
[GameItems
.getItem(inv
[invSlot
]).getTex()].setPosition(
104 x
- 10 + (12 * getDir()) - 8 * MathUtils
.sin(handRotation
),
105 y
+ 2 + 8 * MathUtils
.cos(handRotation
));
106 Assets
.itemTex
[GameItems
.getItem(inv
[invSlot
]).getTex()].draw(spriteBatch
);
107 Assets
.itemTex
[GameItems
.getItem(inv
[invSlot
]).getTex()].flip((getDir() == 0), false);
112 Assets
.plSprite
[0][2].setPosition(x
- 6, y
);
113 Assets
.plSprite
[0][2].draw(spriteBatch
);
117 public int getType() {
122 public Rectangle
getRect() {
123 return new Rectangle(pos
.x
, pos
.y
, getWidth(), getHeight());