diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index b45b942697356a3b23450a355e8b5b5178dc9b09..34232f705e7e3fdf4303b6db6ecd16488de2c061 100644 (file)
private static final float SPEED = 69.072f;
private static final float JUMP_VELOCITY = -133.332f;
+ private static final int MAX_HEALTH = 20;
+
+ private boolean hitting = false;
+ private float hitAnim = 0f;
+ private float hitAnimDelta = ANIMATION_SPEED;
public final int[] inventory;
public int slot;
- public final int gameMode;
+ public int gameMode;
public boolean swim;
public float headRotation = 0f;
public Player() {
- super(0, 0, 4, 30, randomDir(), Type.MOB);
- this.gameMode = 1;
+ super(0, 0, 4, 30, randomDir(), Type.MOB, MAX_HEALTH);
inventory = new int[9];
swim = false;
}
this.y = pos.y;
mVelocity.setZero();
mDead = false;
+ heal(MAX_HEALTH);
}
public void pickUpDrop(Drop drop) {
public void changeDir() {
}
- private void drawItem(SpriteBatch spriteBatch, float x, float y) {
+ @Override
+ public void damage(int damage) {
+ if (gameMode == 1) {
+ return;
+ }
+ super.damage(damage);
+ }
+
+ @Override
+ public void heal(int heal) {
+ if (gameMode == 1) {
+ return;
+ }
+ super.heal(heal);
+ }
+
+ private void drawItem(SpriteBatch spriteBatch, float x, float y, float anim) {
final int itemId = inventory[slot];
final Item item = GameItems.getItem(itemId);
final float xOffset = (-1 + getDirection().getIndex()) * sprite.getWidth() + 4 + handMultiplier * (sprite.getWidth() * spriteOrigin.getX());
final float yOffset = item.isTool() ? -sprite.getHeight() / 2 : 0;
- float rotate = mAnim + 30;
+ float rotate = anim + 30;
- final float itemX = x + handLength * MathUtils.sin(handMultiplier * mAnim * MathUtils.degRad) + xOffset;
- final float itemY = y + handLength * MathUtils.cos(handMultiplier * mAnim * MathUtils.degRad) + yOffset;
+ final float itemX = x + handLength * MathUtils.sin(handMultiplier * anim * MathUtils.degRad) + xOffset;
+ final float itemY = y + handLength * MathUtils.cos(handMultiplier * anim * MathUtils.degRad) + yOffset;
if (looksLeft()) {
sprite.setFlip(true, sprite.isFlipY());
sprite.setOriginCenter();
}
+ public void startHitting() {
+ if (hitting) {
+ return;
+ }
+
+ hitting = true;
+ hitAnim = 90f;
+ hitAnimDelta = ANIMATION_SPEED;
+ }
+
+ public void stopHitting() {
+ hitting = false;
+ }
+
+ private float getRightHandAnim(float delta) {
+ hitAnim -= hitAnimDelta * delta;
+
+ if (hitAnim < 30f || hitAnim > 90f) {
+ if (hitting) {
+ hitAnimDelta = -hitAnimDelta;
+ } else {
+ hitAnimDelta = ANIMATION_SPEED;
+ }
+ }
+
+ if (!hitting) {
+ if (hitAnim < hitAnimDelta * delta) {
+ hitAnim = 0;
+ hitAnimDelta = 0;
+ return -mAnim;
+ }
+ }
+
+ return hitAnim;
+ }
+
@Override
public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
updateAnimation(delta);
final Sprite body = Assets.playerSprite[getDirection().getIndex()][1];
final Sprite frontHand = Assets.playerSprite[0][2];
- SpriteUtilsKt.drawSprite(spriteBatch, backHand, x + 2, y + 8, -mAnim);
+ float backHandAnim, frontHandAnim;
+
+ final float rightHandAnim = getRightHandAnim(delta);
+
+ if (looksLeft()) {
+ backHandAnim = rightHandAnim;
+ frontHandAnim = mAnim;
+ } else {
+ backHandAnim = -mAnim;
+ frontHandAnim = -rightHandAnim;
+ }
+
+ SpriteUtilsKt.drawSprite(spriteBatch, backHand, x + 2, y + 8, backHandAnim);
if (looksLeft()) {
- drawItem(spriteBatch, x, y);
+ drawItem(spriteBatch, x, y, -backHandAnim);
}
SpriteUtilsKt.drawSprite(spriteBatch, backLeg, x + 2, y + 20, mAnim);
SpriteUtilsKt.drawSprite(spriteBatch, body, x + 2, y + 8);
if (looksRight()) {
- drawItem(spriteBatch, x, y);
+ drawItem(spriteBatch, x, y, frontHandAnim);
}
- SpriteUtilsKt.drawSprite(spriteBatch, frontHand, x + 2, y + 8, mAnim);
+ SpriteUtilsKt.drawSprite(spriteBatch, frontHand, x + 2, y + 8, frontHandAnim);
}
}