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
.objects
.Drop
;
8 import ru
.deadsoftware
.cavedroid
.game
.world
.GameWorld
;
9 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
10 import ru
.deadsoftware
.cavedroid
.misc
.utils
.SpriteUtilsKt
;
12 public class Player
extends Mob
{
14 public final int[] inventory
;
16 public final int gameMode
;
18 public float headRotation
= 0f;
21 super(0, 0, 4, 30, randomDir(), Type
.MOB
);
23 inventory
= new int[9];
27 public void respawn(GameWorld gameWorld
) {
28 Vector2 pos
= getSpawnPoint(gameWorld
);
34 public void pickUpDrop(Drop drop
) {
35 for (int i
= 0; i
< inventory
.length
; i
++) {
36 if (inventory
[i
] == 0 || inventory
[i
] == drop
.getId()) {
37 inventory
[i
] = drop
.getId();
38 drop
.setPickedUp(true);
44 private Vector2
getSpawnPoint(GameWorld gameWorld
) {
46 for (y
= 0; y
< gameWorld
.getHeight(); y
++) {
47 if (y
== gameWorld
.getHeight() - 1) {
49 gameWorld
.setForeMap(0, y
, 1);
52 if (gameWorld
.hasForeAt(0, y
) && gameWorld
.getForeMapBlock(0, y
).hasCollision()) {
56 return new Vector2(8 - getWidth() / 2, (float) y
* 16 - getHeight());
59 public void setDir(Direction dir
) {
60 if (dir
!= getDirection()) {
66 public void ai(GameWorld gameWorld
, float delta
) {
70 public void changeDir() {
74 public void draw(SpriteBatch spriteBatch
, float x
, float y
, float delta
) {
75 updateAnimation(delta
);
77 final Sprite backHand
= Assets
.playerSprite
[1][2];
78 final Sprite backLeg
= Assets
.playerSprite
[1][3];
79 final Sprite frontLeg
= Assets
.playerSprite
[0][3];
80 final Sprite head
= Assets
.playerSprite
[dirMultiplier()][0];
81 final Sprite body
= Assets
.playerSprite
[dirMultiplier()][1];
82 final Sprite frontHand
= Assets
.playerSprite
[0][2];
84 SpriteUtilsKt
.draw(spriteBatch
, backHand
, x
+ 2, y
+ 8, -mAnim
);
85 SpriteUtilsKt
.draw(spriteBatch
, backLeg
, x
+ 2, y
+ 20, mAnim
);
86 SpriteUtilsKt
.draw(spriteBatch
, frontLeg
, x
+ 2, y
+ 20, -mAnim
);
87 SpriteUtilsKt
.draw(spriteBatch
, head
, x
, y
, headRotation
);
88 SpriteUtilsKt
.draw(spriteBatch
, body
, x
+ 2, y
+ 8);
89 SpriteUtilsKt
.draw(spriteBatch
, frontHand
, x
+ 2, y
+ 8, mAnim
);