3335b7f5ebc69322478b8e1eeb7cf82f043b2baa
1 package ru
.deadsoftware
.cavedroid
.game
.mobs
;
3 import com
.badlogic
.gdx
.graphics
.g2d
.SpriteBatch
;
4 import com
.badlogic
.gdx
.math
.Vector2
;
5 import ru
.deadsoftware
.cavedroid
.game
.world
.GameWorld
;
6 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
8 public class Player
extends Mob
{
10 public final int[] inventory
;
12 public final int gameMode
;
16 super(0, 0, 4, 30, randomDir(), Type
.MOB
);
18 inventory
= new int[9];
22 public void respawn(GameWorld gameWorld
) {
23 Vector2 pos
= getSpawnPoint(gameWorld
);
29 private Vector2
getSpawnPoint(GameWorld gameWorld
) {
31 for (y
= 0; y
< gameWorld
.getHeight(); y
++) {
32 if (y
== gameWorld
.getHeight() - 1) {
34 gameWorld
.setForeMap(0, y
, 1);
37 if (gameWorld
.hasForeAt(0, y
) && gameWorld
.getForeMapBlock(0, y
).hasCollision()) {
41 return new Vector2(8 - getWidth() / 2, (float) y
* 16 - getHeight());
44 private boolean isAnimationIncreasing() {
45 return mAnim
> 0 && mAnimDelta
> 0 || mAnim
< 0 && mAnimDelta
< 0;
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 if (mVelocity
.x
!= 0f || Math
.abs(mAnim
) > 5f) {
65 mAnim
+= mAnimDelta
* delta
;
70 Assets
.playerSprite
[0][2].setRotation(mAnim
);
71 Assets
.playerSprite
[1][2].setRotation(-mAnim
);
72 Assets
.playerSprite
[0][3].setRotation(-mAnim
);
73 Assets
.playerSprite
[1][3].setRotation(mAnim
);
77 mAnimDelta
= -ANIMATION_SPEED
;
78 } else if (mAnim
< -60f) {
80 mAnimDelta
= ANIMATION_SPEED
;
83 if (mVelocity
.x
== 0f && isAnimationIncreasing()) {
84 mAnimDelta
= -mAnimDelta
;
88 Assets
.playerSprite
[1][2].setPosition(x
+ 2, y
+ 8);
89 Assets
.playerSprite
[1][2].draw(spriteBatch
);
91 Assets
.playerSprite
[1][3].setPosition(x
+ 2, y
+ 20);
92 Assets
.playerSprite
[1][3].draw(spriteBatch
);
94 Assets
.playerSprite
[0][3].setPosition(x
+ 2, y
+ 20);
95 Assets
.playerSprite
[0][3].draw(spriteBatch
);
97 spriteBatch
.draw(Assets
.playerSprite
[dirMultiplier()][0], x
, y
);
99 spriteBatch
.draw(Assets
.playerSprite
[dirMultiplier()][1], x
+ 2, y
+ 8);
101 Assets
.playerSprite
[0][2].setPosition(x
+ 2, y
+ 8);
102 Assets
.playerSprite
[0][2].draw(spriteBatch
);