580665ef8950f1daa3d6ab59faf1776412e7d5ab
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 private boolean isAnimationIncreasing() {
49 return mAnim
> 0 && mAnimDelta
> 0 || mAnim
< 0 && mAnimDelta
< 0;
52 private void updateAnimation(float delta
) {
53 if (mVelocity
.x
!= 0f || Math
.abs(mAnim
) > 5f) {
54 mAnim
+= mAnimDelta
* delta
;
61 mAnimDelta
= -ANIMATION_SPEED
;
62 } else if (mAnim
< -60f) {
64 mAnimDelta
= ANIMATION_SPEED
;
67 if (mVelocity
.x
== 0f && isAnimationIncreasing()) {
68 mAnimDelta
= -mAnimDelta
;
72 public void setDir(Direction dir
) {
73 if (dir
!= getDirection()) {
79 public void ai(GameWorld gameWorld
, float delta
) {
83 public void changeDir() {
87 public void draw(SpriteBatch spriteBatch
, float x
, float y
, float delta
) {
88 updateAnimation(delta
);
90 final Sprite backHand
= Assets
.playerSprite
[1][2];
91 final Sprite backLeg
= Assets
.playerSprite
[1][3];
92 final Sprite frontLeg
= Assets
.playerSprite
[0][3];
93 final Sprite head
= Assets
.playerSprite
[dirMultiplier()][0];
94 final Sprite body
= Assets
.playerSprite
[dirMultiplier()][1];
95 final Sprite frontHand
= Assets
.playerSprite
[0][2];
97 SpriteUtilsKt
.draw(spriteBatch
, backHand
, x
+ 2, y
+ 8, -mAnim
);
98 SpriteUtilsKt
.draw(spriteBatch
, backLeg
, x
+ 2, y
+ 20, mAnim
);
99 SpriteUtilsKt
.draw(spriteBatch
, frontLeg
, x
+ 2, y
+ 20, -mAnim
);
100 SpriteUtilsKt
.draw(spriteBatch
, head
, x
, y
, headRotation
);
101 SpriteUtilsKt
.draw(spriteBatch
, body
, x
+ 2, y
+ 8);
102 SpriteUtilsKt
.draw(spriteBatch
, frontHand
, x
+ 2, y
+ 8, mAnim
);