summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 95bc973)
raw | patch | inline | side by side (parent: 95bc973)
author | fredboy <fredboy@protonmail.com> | |
Fri, 19 Apr 2024 11:30:26 +0000 (18:30 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Fri, 19 Apr 2024 11:30:26 +0000 (18:30 +0700) |
core/src/ru/deadsoftware/cavedroid/game/GameInput.java | patch | blob | history | |
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java | patch | blob | history |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java
index 2bf6e7d096ab17912d6794841661a212841c1988..291311a68077622850ed90b533622ccf30ab6557 100644 (file)
}
private void pressLMB() {
- if (mMainConfig.checkGameUiWindow(GameUiWindow.NONE) &&
- ((mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.getForeMapBlock(mCurX, mCurY).getHp() >= 0) ||
- (!mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.hasBackAt(mCurX, mCurY) &&
- mGameWorld.getBackMapBlock(mCurX, mCurY).getHp() >= 0))) {
- if (mPlayer.gameMode == 0) {
- mBlockDamage++;
- if (mGameWorld.hasForeAt(mCurX, mCurY)) {
- if (mBlockDamage >= mGameWorld.getForeMapBlock(mCurX, mCurY).getHp()) {
- mGameWorld.destroyForeMap(mCurX, mCurY);
- mBlockDamage = 0;
+ if (mMainConfig.checkGameUiWindow(GameUiWindow.NONE)) {
+ mPlayer.startHitting();
+
+ if ((mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.getForeMapBlock(mCurX, mCurY).getHp() >= 0) ||
+ (!mGameWorld.hasForeAt(mCurX, mCurY) && mGameWorld.hasBackAt(mCurX, mCurY) &&
+ mGameWorld.getBackMapBlock(mCurX, mCurY).getHp() >= 0)) {
+ if (mPlayer.gameMode == 0) {
+ mBlockDamage++;
+ if (mGameWorld.hasForeAt(mCurX, mCurY)) {
+ if (mBlockDamage >= mGameWorld.getForeMapBlock(mCurX, mCurY).getHp()) {
+ mGameWorld.destroyForeMap(mCurX, mCurY);
+ mBlockDamage = 0;
+ }
+ } else if (mGameWorld.hasBackAt(mCurX, mCurY)) {
+ if (mBlockDamage >= mGameWorld.getBackMapBlock(mCurX, mCurY).getHp()) {
+ mGameWorld.destroyBackMap(mCurX, mCurY);
+ mBlockDamage = 0;
+ }
}
- } else if (mGameWorld.hasBackAt(mCurX, mCurY)) {
- if (mBlockDamage >= mGameWorld.getBackMapBlock(mCurX, mCurY).getHp()) {
- mGameWorld.destroyBackMap(mCurX, mCurY);
- mBlockDamage = 0;
+ } else {
+ if (mGameWorld.hasForeAt(mCurX, mCurY)) {
+ mGameWorld.placeToForeground(mCurX, mCurY, 0);
+ } else if (mGameWorld.hasBackAt(mCurX, mCurY)) {
+ mGameWorld.placeToBackground(mCurX, mCurY, 0);
}
+ mTouchedDown = false;
}
} else {
- if (mGameWorld.hasForeAt(mCurX, mCurY)) {
- mGameWorld.placeToForeground(mCurX, mCurY, 0);
- } else if (mGameWorld.hasBackAt(mCurX, mCurY)) {
- mGameWorld.placeToBackground(mCurX, mCurY, 0);
- }
mTouchedDown = false;
}
}
void update() {
if (mTouchedDown && mTouchDownBtn == Input.Buttons.LEFT) {
pressLMB();
+ } else {
+ mPlayer.stopHitting();
}
if (mTouchedDown && TimeUtils.timeSinceMillis(mTouchDownTime) > 500) {
holdMB();
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index b45b942697356a3b23450a355e8b5b5178dc9b09..8fce1169be150a7a5e568adf1925ef6cb014afd2 100644 (file)
private static final float SPEED = 69.072f;
private static final float JUMP_VELOCITY = -133.332f;
+ 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 void changeDir() {
}
- private void drawItem(SpriteBatch spriteBatch, float x, float y) {
+ 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);
}
}