summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 522264a)
raw | patch | inline | side by side (parent: 522264a)
author | fredboy <fredboy@protonmail.com> | |
Tue, 16 Apr 2024 14:05:33 +0000 (21:05 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Tue, 16 Apr 2024 14:05:33 +0000 (21:05 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index 38253948725eae1e5fbf6c874509d1d7fe13f771..6b69faada2470f556265259c5df8f5aa6cda74b7 100644 (file)
mobXColl(mob);
if (mob.canJump() && mob.getVelocity().x != 0 && checkJump(mob)) {
- mob.getVelocity().y += PL_JUMP_VELOCITY;
+ mob.getVelocity().y = PL_JUMP_VELOCITY;
mob.setCanJump(false);
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index 4ad04e8538affb3b49e3bbf2eb0f80a796ce4510..2b58f7c626817f0fd9789f453b751d7463aa8b59 100644 (file)
return MathUtils.randomBoolean(.5f) ? Direction.LEFT : Direction.RIGHT;
}
+ private boolean isAnimationIncreasing() {
+ return mAnim > 0 && mAnimDelta > 0 || mAnim < 0 && mAnimDelta < 0;
+ }
+
+ protected final void updateAnimation(float delta) {
+ if (mVelocity.x != 0f || Math.abs(mAnim) > mAnimDelta * delta) {
+ mAnim += mAnimDelta * delta;
+ } else {
+ mAnim = 0;
+ }
+
+ if (mAnim > 60f) {
+ mAnim = 60f;
+ mAnimDelta = -ANIMATION_SPEED;
+ } else if (mAnim < -60f) {
+ mAnim = -60f;
+ mAnimDelta = ANIMATION_SPEED;
+ }
+
+ if (mVelocity.x == 0f && isAnimationIncreasing()) {
+ mAnimDelta = -mAnimDelta;
+ }
+ }
+
/**
* @return The X coordinate of a mob in blocks
*/
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java
index 15185ef1b8319311aead7f8f74c675a73a0b14f0..376c68bf641bb0581d280802995ff49f9f52a0e8 100644 (file)
package ru.deadsoftware.cavedroid.game.mobs;
+import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavedroid.game.GamePhysics;
import ru.deadsoftware.cavedroid.game.world.GameWorld;
import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.misc.utils.SpriteUtilsKt;
import static ru.deadsoftware.cavedroid.misc.Assets.pigSprite;
public Pig(float x, float y) {
super(x, y, 25, 18, randomDir(), Type.MOB);
- mVelocity = new Vector2(looksLeft() ? -1 : 1, 0);
+ mVelocity = new Vector2((looksLeft() ? -1 : 1) * GamePhysics.PL_SPEED, 0);
}
@Override
public void changeDir() {
switchDir();
- mVelocity.x = -1 + 2 * dirMultiplier();
+ mVelocity.x = (-1 + 2 * dirMultiplier()) * GamePhysics.PL_SPEED;
}
@Override
public void ai(GameWorld gameWorld, float delta) {
- if (MathUtils.randomBoolean(.0025f)) {
+ if (MathUtils.randomBoolean(delta)) {
if (mVelocity.x != 0f) {
mVelocity.x = 0;
} else {
@Override
public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
- pigSprite[0][1].setRotation(getAnim());
- pigSprite[1][1].setRotation(-getAnim());
- //back legs
- pigSprite[1][1].setPosition(x + (9 - dirMultiplier() * 9), y + 12);
- pigSprite[1][1].draw(spriteBatch);
- pigSprite[1][1].setPosition(x + 21 - (9 * dirMultiplier()), y + 12);
- pigSprite[1][1].draw(spriteBatch);
- //head & body
- spriteBatch.draw(Assets.pigSprite[dirMultiplier()][0], x, y);
- //front legs
- pigSprite[0][1].setPosition(x + (9 - dirMultiplier() * 9), y + 12);
- pigSprite[0][1].draw(spriteBatch);
- pigSprite[0][1].setPosition(x + 21 - (9 * dirMultiplier()), y + 12);
- pigSprite[0][1].draw(spriteBatch);
+ updateAnimation(delta);
+
+ final Sprite frontLeg = pigSprite[0][1];
+ final Sprite backLeg = pigSprite[1][1];
+ final Sprite body = pigSprite[dirMultiplier()][0];
+
+ SpriteUtilsKt.draw(spriteBatch, backLeg, x + (9 - dirMultiplier() * 9), y + 12, -mAnim);
+ SpriteUtilsKt.draw(spriteBatch, backLeg, x + 21 - (9 * dirMultiplier()), y + 12, -mAnim);
+ SpriteUtilsKt.draw(spriteBatch, body, x, y);
+ SpriteUtilsKt.draw(spriteBatch, frontLeg, x + (9 - dirMultiplier() * 9), y + 12, mAnim);
+ SpriteUtilsKt.draw(spriteBatch, frontLeg, x + 21 - (9 * dirMultiplier()), y + 12, mAnim);
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 580665ef8950f1daa3d6ab59faf1776412e7d5ab..10a1885681723d5b13c34644dd4535cd55cc26ab 100644 (file)
return new Vector2(8 - getWidth() / 2, (float) y * 16 - getHeight());
}
- private boolean isAnimationIncreasing() {
- return mAnim > 0 && mAnimDelta > 0 || mAnim < 0 && mAnimDelta < 0;
- }
-
- private void updateAnimation(float delta) {
- if (mVelocity.x != 0f || Math.abs(mAnim) > 5f) {
- mAnim += mAnimDelta * delta;
- } else {
- mAnim = 0;
- }
-
- if (mAnim > 60f) {
- mAnim = 60f;
- mAnimDelta = -ANIMATION_SPEED;
- } else if (mAnim < -60f) {
- mAnim = -60f;
- mAnimDelta = ANIMATION_SPEED;
- }
-
- if (mVelocity.x == 0f && isAnimationIncreasing()) {
- mAnimDelta = -mAnimDelta;
- }
- }
-
public void setDir(Direction dir) {
if (dir != getDirection()) {
switchDir();