10a1885681723d5b13c34644dd4535cd55cc26ab
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
;
15 public final int gameMode
;
17 public float headRotation
= 0f;
20 super(0, 0, 4, 30, randomDir(), Type
.MOB
);
22 inventory
= new int[9];
26 public void respawn(GameWorld gameWorld
) {
27 Vector2 pos
= getSpawnPoint(gameWorld
);
33 private Vector2
getSpawnPoint(GameWorld gameWorld
) {
35 for (y
= 0; y
< gameWorld
.getHeight(); y
++) {
36 if (y
== gameWorld
.getHeight() - 1) {
38 gameWorld
.setForeMap(0, y
, 1);
41 if (gameWorld
.hasForeAt(0, y
) && gameWorld
.getForeMapBlock(0, y
).hasCollision()) {
45 return new Vector2(8 - getWidth() / 2, (float) y
* 16 - getHeight());
48 public void setDir(Direction dir
) {
49 if (dir
!= getDirection()) {
55 public void ai(GameWorld gameWorld
, float delta
) {
59 public void changeDir() {
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
);