From: fredboy Date: Sun, 14 Apr 2024 17:55:02 +0000 (+0700) Subject: Rename move -> velocity X-Git-Tag: alpha0.4.1~8 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=3992892d92be0c4ea654de3b4e10c32bf4552d9c;p=cavedroid.git Rename move -> velocity --- diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index 594f8cc..3f9b773 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -67,12 +67,12 @@ public class GameInput { if (checkSwim()) { mPlayer.swim = true; } else if (mPlayer.canJump()) { - mPlayer.getMove().add(0, -7); + mPlayer.getVelocity().add(0, -7); } else if (!mPlayer.isFlyMode() && mPlayer.gameMode == 1) { mPlayer.setFlyMode(true); - mPlayer.getMove().y = 0; + mPlayer.getVelocity().y = 0; } else if (mPlayer.isFlyMode()) { - mPlayer.getMove().y = -GamePhysics.PL_SPEED; + mPlayer.getVelocity().y = -GamePhysics.PL_SPEED; } } @@ -89,14 +89,14 @@ public class GameInput { if (mControlMode == ControlMode.WALK || !mMainConfig.isTouch()) { switch (keycode) { case Input.Keys.A: - mPlayer.getMove().x = -GamePhysics.PL_SPEED; + mPlayer.getVelocity().x = -GamePhysics.PL_SPEED; mPlayer.setDir(Mob.Direction.LEFT); if (mMainConfig.isTouch() && checkSwim()) { mPlayer.swim = true; } break; case Input.Keys.D: - mPlayer.getMove().x = GamePhysics.PL_SPEED; + mPlayer.getVelocity().x = GamePhysics.PL_SPEED; mPlayer.setDir(Mob.Direction.RIGHT); if (mMainConfig.isTouch() && checkSwim()) { mPlayer.swim = true; @@ -108,7 +108,7 @@ public class GameInput { break; case Input.Keys.S: case Input.Keys.CONTROL_LEFT: - mPlayer.getMove().y = GamePhysics.PL_SPEED; + mPlayer.getVelocity().y = GamePhysics.PL_SPEED; break; } } else { @@ -315,7 +315,7 @@ public class GameInput { switch (keycode) { case Input.Keys.A: case Input.Keys.D: - mPlayer.getMove().x = 0; + mPlayer.getVelocity().x = 0; if (mMainConfig.isTouch() && mPlayer.swim) { mPlayer.swim = false; } @@ -326,7 +326,7 @@ public class GameInput { case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: if (mPlayer.isFlyMode()) { - mPlayer.getMove().y = 0; + mPlayer.getVelocity().y = 0; } if (mPlayer.swim) { mPlayer.swim = false; diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java index d6b5a9a..6572cf5 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java @@ -96,26 +96,26 @@ class GamePhysics { if (dropToPlayer > 0) { drop.moveToPlayer(mGameWorld, mMobsController.getPlayer(), dropToPlayer); } else { - if (drop.getMove().x >= .5f) { - drop.getMove().x -= .5f; - } else if (drop.getMove().x <= -.5f) { - drop.getMove().x += .5f; + if (drop.getVelocity().x >= .5f) { + drop.getVelocity().x -= .5f; + } else if (drop.getVelocity().x <= -.5f) { + drop.getVelocity().x += .5f; } else { - drop.getMove().x = 0; + drop.getVelocity().x = 0; } - if (drop.getMove().y < 9) { - drop.getMove().y += gravity.y / 4; + if (drop.getVelocity().y < 9) { + drop.getVelocity().y += gravity.y / 4; } } drop.move(); if (checkColl(drop)) { - drop.getMove().set(0, -1); + drop.getVelocity().set(0, -1); do { drop.move(); } while (checkColl(drop)); - drop.getMove().setZero(); + drop.getVelocity().setZero(); } } @@ -132,9 +132,9 @@ class GamePhysics { int d = 0; - if (mob.getMove().x < 0) { + if (mob.getVelocity().x < 0) { d = 1; - } else if (mob.getMove().x > 0) { + } else if (mob.getVelocity().x > 0) { d = -1; } @@ -157,7 +157,7 @@ class GamePhysics { if (checkColl(mob)) { int d = -1; - if (mob.getMove().y < 0) { + if (mob.getVelocity().y < 0) { d = 1; } @@ -172,7 +172,7 @@ class GamePhysics { mob.y += d; } - mob.getMove().y = 0; + mob.getVelocity().y = 0; } else { mob.setCanJump(false); @@ -184,7 +184,7 @@ class GamePhysics { } private void playerPhy(Player player) { - player.y += player.getMove().y; + player.y += player.getVelocity().y; mobYColl(player); if (player.isDead()) { @@ -192,71 +192,71 @@ class GamePhysics { } if (GameItems.isFluid(getBlock(player))) { - if (mMainConfig.isTouch() && player.getMove().x != 0 && !player.swim && !player.isFlyMode()) { + if (mMainConfig.isTouch() && player.getVelocity().x != 0 && !player.swim && !player.isFlyMode()) { player.swim = true; } if (!player.swim) { - if (!player.isFlyMode() && player.getMove().y < 4.5f) { - player.getMove().add(gravity.x / 4, gravity.y / 4); + if (!player.isFlyMode() && player.getVelocity().y < 4.5f) { + player.getVelocity().add(gravity.x / 4, gravity.y / 4); } - if (!player.isFlyMode() && player.getMove().y > 4.5f) { - player.getMove().add(0, -1f); + if (!player.isFlyMode() && player.getVelocity().y > 4.5f) { + player.getVelocity().add(0, -1f); } } else { - player.getMove().add(0, -.5f); - if (player.getMove().y < -3) { - player.getMove().y = -3; + player.getVelocity().add(0, -.5f); + if (player.getVelocity().y < -3) { + player.getVelocity().y = -3; } } } else { - if (!player.isFlyMode() && player.getMove().y < 18) { - player.getMove().add(gravity); + if (!player.isFlyMode() && player.getVelocity().y < 18) { + player.getVelocity().add(gravity); } } - player.x += player.getMove().x * (player.isFlyMode() ? 1.5f : 1) * + player.x += player.getVelocity().x * (player.isFlyMode() ? 1.5f : 1) * (GameItems.isFluid(getBlock(player)) && !player.isFlyMode() ? .8f : 1); mobXColl(player); - if (mMainConfig.isTouch() && !player.isFlyMode() && player.canJump() && player.getMove().x != 0 && checkJump(player)) { - player.getMove().add(0, -8); + if (mMainConfig.isTouch() && !player.isFlyMode() && player.canJump() && player.getVelocity().x != 0 && checkJump(player)) { + player.getVelocity().add(0, -8); player.setCanJump(false); } } private void mobPhy(Mob mob) { if (mob.getType() == Mob.Type.MOB && GameItems.isFluid(getBlock(mob))) { - if (mob.getMove().y > 9) { - mob.getMove().add(0, -.9f); + if (mob.getVelocity().y > 9) { + mob.getVelocity().add(0, -.9f); } - mob.getMove().add(0, -.5f); + mob.getVelocity().add(0, -.5f); - if (mob.getMove().y < -3) { - mob.getMove().y = -3; + if (mob.getVelocity().y < -3) { + mob.getVelocity().y = -3; } - } else if (!mob.isFlyMode() && mob.getMove().y < 18) { - mob.getMove().add(gravity); + } else if (!mob.isFlyMode() && mob.getVelocity().y < 18) { + mob.getVelocity().add(gravity); } - mob.y += mob.getMove().y; + mob.y += mob.getVelocity().y; mobYColl(mob); if (mob.isDead()) { return; } - mob.x += mob.getMove().x; + mob.x += mob.getVelocity().x; mobXColl(mob); - if (mob.canJump() && mob.getMove().x != 0 && checkJump(mob)) { - mob.getMove().add(0, -8); + if (mob.canJump() && mob.getVelocity().x != 0 && checkJump(mob)) { + mob.getVelocity().add(0, -8); mob.setCanJump(false); } } - void update() { + void update(float delta) { Player player = mMobsController.getPlayer(); for (Iterator it = mDropController.getIterator(); it.hasNext(); ) { diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java index 44a4687..d8925f9 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java @@ -28,7 +28,7 @@ public class GameProc implements Disposable { } public void update(float delta) { - mGamePhysics.update(); + mGamePhysics.update(delta); mGameInput.update(); mGameWorld.update(); mGameRenderer.render(delta); diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java index 23cf1dc..359a74b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java @@ -19,12 +19,12 @@ public class FallingGravel extends Mob { */ public FallingGravel(float x, float y) { super(x, y, 16, 16, Direction.LEFT, Type.GRAVEL); - mMove = new Vector2(0, 1); + mVelocity = new Vector2(0, 1); } @Override public void ai(GameWorld gameWorld) { - if (mMove.isZero()) { + if (mVelocity.isZero()) { gameWorld.setForeMap(getMapX(), getMiddleMapY(), 11); kill(); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java index 9a383a2..a8d9ce2 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java @@ -20,12 +20,12 @@ public class FallingSand extends Mob { */ public FallingSand(float x, float y) { super(x, y, 16, 16, Direction.LEFT, Type.SAND); - mMove = new Vector2(0, 1); + mVelocity = new Vector2(0, 1); } @Override public void ai(GameWorld gameWorld) { - if (mMove.isZero()) { + if (mVelocity.isZero()) { gameWorld.setForeMap(getMapX(), getMiddleMapY(), 10); kill(); } diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java index 0f76592..3bc3b5b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java @@ -24,7 +24,7 @@ public abstract class Mob extends Rectangle implements Serializable { RIGHT } - protected Vector2 mMove; + protected Vector2 mVelocity; protected Type mType; protected int mAnimDelta = 6; protected int mAnim; @@ -43,7 +43,7 @@ public abstract class Mob extends Rectangle implements Serializable { */ protected Mob(float x, float y, float width, float height, Direction mDirection, Type type) { super(x, y, width, height); - mMove = new Vector2(0, 0); + mVelocity = new Vector2(0, 0); mCanJump = false; mDead = false; this.mDirection = mDirection; @@ -131,13 +131,13 @@ public abstract class Mob extends Rectangle implements Serializable { mDead = true; } - public final void move() { - x += mMove.x; - y += mMove.y; + public final void move(float delta) { + x += mVelocity.x * delta; + y += mVelocity.y * delta; } - public final Vector2 getMove() { - return mMove; + public final Vector2 getVelocity() { + return mVelocity; } public final boolean canJump() { diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java index b362da7..b2760c2 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java @@ -12,26 +12,26 @@ public class Pig extends Mob { public Pig(float x, float y) { super(x, y, 25, 18, randomDir(), Type.MOB); - mMove = new Vector2(looksLeft() ? -1 : 1, 0); + mVelocity = new Vector2(looksLeft() ? -1 : 1, 0); } @Override public void changeDir() { switchDir(); - mMove.x = -1 + 2 * dirMultiplier(); + mVelocity.x = -1 + 2 * dirMultiplier(); } @Override public void ai(GameWorld gameWorld) { if (MathUtils.randomBoolean(.0025f)) { - if (mMove.x != 0f) { - mMove.x = 0; + if (mVelocity.x != 0f) { + mVelocity.x = 0; } else { changeDir(); } } - if (mMove.x != 0f) { + if (mVelocity.x != 0f) { mAnim += mAnimDelta; } else { mAnim = 0; diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java index 0b7ab8b..f373dc3 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java @@ -23,7 +23,7 @@ public class Player extends Mob { Vector2 pos = getSpawnPoint(gameWorld); this.x = pos.x; this.y = pos.y; - mMove.setZero(); + mVelocity.setZero(); } private Vector2 getSpawnPoint(GameWorld gameWorld) { @@ -57,7 +57,7 @@ public class Player extends Mob { @Override public void draw(SpriteBatch spriteBatch, float x, float y) { - if (mMove.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) { + if (mVelocity.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) { Assets.playerSprite[0][2].rotate(mAnimDelta); Assets.playerSprite[1][2].rotate(-mAnimDelta); Assets.playerSprite[0][3].rotate(-mAnimDelta); diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java index 3b5c760..07a2f6c 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java @@ -12,17 +12,17 @@ import java.io.Serializable; public class Drop extends Rectangle implements Serializable { private final int id; - private final Vector2 move; + private final Vector2 velocity; private boolean pickedUp = false; Drop(float x, float y, int id) { super(x, y, 8, 8); this.id = id; - this.move = new Vector2(0, -1); + this.velocity = new Vector2(0, -1); } - public Vector2 getMove() { - return move; + public Vector2 getVelocity() { + return velocity; } public int closeToPlayer(GameWorld gameWorld, Player player) { @@ -72,18 +72,18 @@ public class Drop extends Rectangle implements Serializable { dy = .5f; } - move.add(dx, dy); + velocity.add(dx, dy); - if (move.x > 2) { - move.x = 1; - } else if (move.x < -2) { - move.x = -1; + if (velocity.x > 2) { + velocity.x = 1; + } else if (velocity.x < -2) { + velocity.x = -1; } - if (move.y > 2) { - move.y = 1; - } else if (move.y < -2) { - move.y = -1; + if (velocity.y > 2) { + velocity.y = 1; + } else if (velocity.y < -2) { + velocity.y = -1; } } } @@ -107,8 +107,8 @@ public class Drop extends Rectangle implements Serializable { } public void move() { - x += move.x; - y += move.y; + x += velocity.x; + y += velocity.y; checkWorldBounds(); y = MathUtils.round(y); }