summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 75809eb)
raw | patch | inline | side by side (parent: 75809eb)
author | fredboy <fredboy@protonmail.com> | |
Mon, 15 Apr 2024 16:29:40 +0000 (23:29 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Mon, 15 Apr 2024 16:29:40 +0000 (23:29 +0700) |
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java | patch | blob | history |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index cb3c2a5dfdcdd3e577a910b2a1ca9bfa06a7606d..5ea56d9bf8c9b30cbf1d72254b02497473fe8f57 100644 (file)
return new Vector2(8 - getWidth() / 2, (float) y * 16 - getHeight());
}
+ private boolean isAnimationIncreasing() {
+ return mAnim > 0 && mAnimDelta > 0 || mAnim < 0 && mAnimDelta < 0;
+ }
+
public void setDir(Direction dir) {
if (dir != getDirection()) {
switchDir();
@Override
public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
- final float correctedAnimationDelta = mAnimDelta * delta;
-
- if (mVelocity.x != 0f || Math.abs(Assets.playerSprite[0][2].getRotation()) > Math.abs(correctedAnimationDelta)) {
- Assets.playerSprite[0][2].rotate(correctedAnimationDelta);
- Assets.playerSprite[1][2].rotate(-correctedAnimationDelta);
- Assets.playerSprite[0][3].rotate(-correctedAnimationDelta);
- Assets.playerSprite[1][3].rotate(correctedAnimationDelta);
+ if (mVelocity.x != 0f || Math.abs(mAnim) > 5f) {
+ mAnim += mAnimDelta * delta;
} else {
- Assets.playerSprite[0][2].setRotation(0);
- Assets.playerSprite[1][2].setRotation(0);
- Assets.playerSprite[0][3].setRotation(0);
- Assets.playerSprite[1][3].setRotation(0);
+ mAnim = 0;
}
- if (Assets.playerSprite[0][2].getRotation() >= 60 || Assets.playerSprite[0][2].getRotation() <= -60) {
+
+ Assets.playerSprite[0][2].setRotation(mAnim);
+ Assets.playerSprite[1][2].setRotation(-mAnim);
+ Assets.playerSprite[0][3].setRotation(-mAnim);
+ Assets.playerSprite[1][3].setRotation(mAnim);
+
+ if (mAnim >= 60 || mAnim <= -60 ||(mVelocity.x == 0f && isAnimationIncreasing())) {
mAnimDelta = -mAnimDelta;
}