5cdb5d85bb5baa6a28e01e14327675f2e1d59deb
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
.GamePhysics
;
6 import ru
.deadsoftware
.cavedroid
.game
.GameWorld
;
7 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
9 public class Player
extends Mob
{
11 public final int[] inventory
;
13 public final int gameMode
;
17 super(0, 0, 4, 30, randomDir(), Type
.MOB
);
19 inventory
= new int[9];
23 public void respawn(GameWorld gameWorld
) {
24 Vector2 pos
= getSpawnPoint(gameWorld
);
30 private Vector2
getSpawnPoint(GameWorld gameWorld
) {
32 for (y
= 0; y
< gameWorld
.getHeight(); y
++) {
33 if (y
== gameWorld
.getHeight() - 1) {
35 gameWorld
.setForeMap(0, y
, 1);
38 if (gameWorld
.hasForeAt(0, y
) && gameWorld
.getForeMapBlock(0, y
).hasCollision()) {
42 return new Vector2(8 - getWidth() / 2, (float) y
* 16 - getHeight());
45 public void setDir(Direction dir
) {
46 if (dir
!= getDirection()) {
52 public void ai(GameWorld gameWorld
, float delta
) {
56 public void changeDir() {
60 public void draw(SpriteBatch spriteBatch
, float x
, float y
, float delta
) {
61 final float correctedAnimationDelta
= mAnimDelta
* delta
;
63 if (mVelocity
.x
!= 0 || Math
.abs(Assets
.playerSprite
[0][2].getRotation()) > Math
.abs(correctedAnimationDelta
)) {
64 Assets
.playerSprite
[0][2].rotate(correctedAnimationDelta
);
65 Assets
.playerSprite
[1][2].rotate(-correctedAnimationDelta
);
66 Assets
.playerSprite
[0][3].rotate(-correctedAnimationDelta
);
67 Assets
.playerSprite
[1][3].rotate(correctedAnimationDelta
);
69 Assets
.playerSprite
[0][2].setRotation(0);
70 Assets
.playerSprite
[1][2].setRotation(0);
71 Assets
.playerSprite
[0][3].setRotation(0);
72 Assets
.playerSprite
[1][3].setRotation(0);
74 if (Assets
.playerSprite
[0][2].getRotation() >= 60 || Assets
.playerSprite
[0][2].getRotation() <= -60) {
75 mAnimDelta
= -mAnimDelta
;
79 Assets
.playerSprite
[1][2].setPosition(x
+ 2, y
+ 8);
80 Assets
.playerSprite
[1][2].draw(spriteBatch
);
82 Assets
.playerSprite
[1][3].setPosition(x
+ 2, y
+ 20);
83 Assets
.playerSprite
[1][3].draw(spriteBatch
);
85 Assets
.playerSprite
[0][3].setPosition(x
+ 2, y
+ 20);
86 Assets
.playerSprite
[0][3].draw(spriteBatch
);
88 spriteBatch
.draw(Assets
.playerSprite
[dirMultiplier()][0], x
, y
);
90 spriteBatch
.draw(Assets
.playerSprite
[dirMultiplier()][1], x
+ 2, y
+ 8);
92 Assets
.playerSprite
[0][2].setPosition(x
+ 2, y
+ 8);
93 Assets
.playerSprite
[0][2].draw(spriteBatch
);