From: fred-boy Date: Sun, 30 Sep 2018 12:55:45 +0000 (+0700) Subject: Remove unnecessary vectors X-Git-Tag: alpha0.4~82 X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=commitdiff_plain;h=84b8cd80e39699174969bfed0734e78b8ec09615 Remove unnecessary vectors --- diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index 63cf93d..7cac744 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -25,12 +25,12 @@ public class GameInput { if (gameProc.ctrlMode == 0 || !CaveGame.TOUCH) { switch (keycode) { case Input.Keys.A: - gameProc.player.moveX.x = -GamePhysics.PL_SPEED; + gameProc.player.move.x = -GamePhysics.PL_SPEED; gameProc.player.dir = 0; if (CaveGame.TOUCH && checkSwim()) gameProc.swim = true; break; case Input.Keys.D: - gameProc.player.moveX.x = GamePhysics.PL_SPEED; + gameProc.player.move.x = GamePhysics.PL_SPEED; gameProc.player.dir = 1; if (CaveGame.TOUCH && checkSwim()) gameProc.swim = true; break; @@ -72,17 +72,17 @@ public class GameInput { if (checkSwim()) { gameProc.swim = true; } else if (gameProc.player.canJump) { - gameProc.player.moveY.add(0, -7); + gameProc.player.move.add(0, -7); } else if (!gameProc.player.flyMode) { gameProc.player.flyMode = true; - gameProc.player.moveY.setZero(); + gameProc.player.move.y = 0; } else { - gameProc.player.moveY.y = -GamePhysics.PL_SPEED; + gameProc.player.move.y = -GamePhysics.PL_SPEED; } break; case Input.Keys.CONTROL_LEFT: - gameProc.player.moveY.y = GamePhysics.PL_SPEED; + gameProc.player.move.y = GamePhysics.PL_SPEED; break; case Input.Keys.E: @@ -109,13 +109,13 @@ public class GameInput { switch (keycode) { case Input.Keys.A: case Input.Keys.D: - gameProc.player.moveX.x = 0; + gameProc.player.move.x = 0; if (CaveGame.TOUCH && gameProc.swim) gameProc.swim = false; break; case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: - if (gameProc.player.flyMode) gameProc.player.moveY.setZero(); + if (gameProc.player.flyMode) gameProc.player.move.y = 0; if (gameProc.swim) gameProc.swim = false; break; } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 66f4236..142e959 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -78,42 +78,42 @@ public class GamePhysics { } private void playerPhy(Player pl) { - pl.position.add(pl.moveY); + pl.position.y += pl.move.y; if (checkColl(pl.getRect())) { int d = -1; - if (pl.moveY.y < 0) d = 1; + if (pl.move.y < 0) d = 1; if (d == -1) { pl.flyMode = false; pl.canJump = true; } pl.position.y = MathUtils.round(pl.position.y); while (checkColl(pl.getRect())) pl.position.y += d; - pl.moveY.setZero(); + pl.move.y = 0; } else { pl.canJump = false; } if (Items.isFluid(getBlock(pl.getRect()))) { - if (CaveGame.TOUCH && pl.moveX.x != 0 && !gameProc.swim && !pl.flyMode) gameProc.swim = true; + if (CaveGame.TOUCH && pl.move.x != 0 && !gameProc.swim && !pl.flyMode) gameProc.swim = true; if (!gameProc.swim) { - if (!pl.flyMode && pl.moveY.y < 4.5f) pl.moveY.add(gravity.x / 4, gravity.y / 4); - if (!pl.flyMode && pl.moveY.y > 4.5f) pl.moveY.add(0, -1f); + if (!pl.flyMode && pl.move.y < 4.5f) pl.move.add(gravity.x / 4, gravity.y / 4); + if (!pl.flyMode && pl.move.y > 4.5f) pl.move.add(0, -1f); } else { - pl.moveY.add(0, -.5f); - if (pl.moveY.y < -3) pl.moveY.y = -3; + pl.move.add(0, -.5f); + if (pl.move.y < -3) pl.move.y = -3; } } else { - if (!pl.flyMode && pl.moveY.y < 18) pl.moveY.add(gravity); + if (!pl.flyMode && pl.move.y < 18) pl.move.add(gravity); } - pl.position.add(pl.moveX); + pl.position.x += pl.move.x; if (checkColl(pl.getRect())) { if (pl.canJump && !pl.flyMode) pl.position.y -= 8; if (checkColl(pl.getRect())) { if (pl.canJump && !pl.flyMode) pl.position.y += 8; int d = 0; - if (pl.moveX.x < 0) d = 1; - else if (pl.moveX.x > 0) d = -1; + if (pl.move.x < 0) d = 1; + else if (pl.move.x > 0) d = -1; pl.position.x = MathUtils.round(pl.position.x); while (checkColl(pl.getRect())) pl.position.x += d; } @@ -124,21 +124,21 @@ public class GamePhysics { if (pl.position.y > gameProc.world.getHeight() * 16) { pl.position = gameProc.world.getSpawnPoint().cpy(); } - if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && !pl.moveX.equals(Vector2.Zero)) { - pl.moveY.add(0, -8); + if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && pl.move.x != 0) { + pl.move.add(0, -8); pl.canJump = false; } } private void mobPhy(Mob mob) { - mob.position.add(mob.moveY); + mob.position.y += mob.move.y; if (checkColl(mob.getRect())) { int d = -1; - if (mob.moveY.y < 0) d = 1; + if (mob.move.y < 0) d = 1; if (d == -1) mob.canJump = true; mob.position.y = MathUtils.round(mob.position.y); while (checkColl(mob.getRect())) mob.position.y += d; - mob.moveY.setZero(); + mob.move.y = 0; if (mob.getType() > 0) { gameProc.world.setForeMap((int) mob.position.x / 16, (int) mob.position.y / 16, mob.getType()); mob.position.y = -1; @@ -149,12 +149,12 @@ public class GamePhysics { } if (mob.getType() == 0 && Items.isFluid(getBlock(mob.getRect()))) { - if (mob.moveY.y > 9) mob.moveY.add(0, -.9f); - mob.moveY.add(0, -.5f); - if (mob.moveY.y < -3) mob.moveY.y = -3; - } else if (mob.moveY.y < 18) mob.moveY.add(gravity); + if (mob.move.y > 9) mob.move.add(0, -.9f); + mob.move.add(0, -.5f); + if (mob.move.y < -3) mob.move.y = -3; + } else if (mob.move.y < 18) mob.move.add(gravity); - mob.position.add(mob.moveX); + mob.position.x += mob.move.x; if (checkColl(mob.getRect())) { if (mob.canJump) { mob.position.y -= 8; @@ -162,8 +162,8 @@ public class GamePhysics { if (checkColl(mob.getRect())) { if (mob.canJump) mob.position.y += 8; int d = 0; - if (mob.moveX.x < 0) d = 1; - else if (mob.moveX.x > 0) d = -1; + if (mob.move.x < 0) d = 1; + else if (mob.move.x > 0) d = -1; mob.position.x = MathUtils.round(mob.position.x); while (checkColl(mob.getRect())) mob.position.x += d; if (mob.canJump) mob.changeDir(); @@ -175,8 +175,8 @@ public class GamePhysics { if (mob.position.y > gameProc.world.getHeight() * 16) { mob.position.y = 0; } - if (checkJump(mob.getRect(), mob.dir) && mob.canJump && !mob.moveX.equals(Vector2.Zero)) { - mob.moveY.add(0, -8); + if (checkJump(mob.getRect(), mob.dir) && mob.canJump && mob.move.x != 0) { + mob.move.add(0, -8); mob.canJump = false; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 5a8ab94..8ed1ebd 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -88,7 +88,7 @@ public class GameRenderer extends Renderer { } private void drawPlayer(Player pl) { - if (!pl.moveX.equals(Vector2.Zero) || Assets.playerSprite[0][2].getRotation() != 0) { + if (pl.move.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) { Assets.playerSprite[0][2].rotate(Player.ANIM_SPEED); Assets.playerSprite[1][2].rotate(-Player.ANIM_SPEED); Assets.playerSprite[0][3].rotate(-Player.ANIM_SPEED); diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java index 11d02d2..441d75f 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java @@ -11,8 +11,7 @@ public class FallingGravel extends Mob { public FallingGravel(int x, int y) { dir = 0; position = new Vector2(x, y); - moveX = new Vector2(0, 0); - moveY = new Vector2(0, 1); + move = new Vector2(0, 1); width = 16; height = 16; canJump = false; diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java index 37f8a59..a410eb3 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java @@ -11,8 +11,7 @@ public class FallingSand extends Mob { public FallingSand(int x, int y) { dir = 0; position = new Vector2(x, y); - moveX = new Vector2(0, 0); - moveY = new Vector2(0, 1); + move = new Vector2(0, 1); width = 16; height = 16; canJump = false; diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java index fbab397..137e7ca 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java @@ -10,7 +10,7 @@ public abstract class Mob implements Serializable { public int ANIM_SPEED = 6; public Vector2 position; - public Vector2 moveX, moveY; + public Vector2 move; public int width, height, dir, animation; public boolean canJump; public boolean dead; diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java index 0fa08bd..c615fcb 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -11,8 +11,7 @@ public class Pig extends Mob { public Pig(int x, int y) { dir = MathUtils.random(1); position = new Vector2(x, y); - moveX = new Vector2(-1 + dir * 2, 0); - moveY = new Vector2(0, 0); + move = new Vector2(-1 + dir * 2, 0); width = 25; height = 18; canJump = false; @@ -22,17 +21,17 @@ public class Pig extends Mob { @Override public void changeDir() { dir = -dir + 1; - moveX.set(-1 + 2 * dir, 0); + move.x = -1 + 2 * dir; } @Override public void ai() { if (MathUtils.randomBoolean(.0025f)) changeDir(); else if (MathUtils.randomBoolean(.0025f)) { - if (moveX.x != 0f) moveX.setZero(); - else moveX.set(-1 + 2 * dir, 0); + if (move.x != 0f) move.x = 0; + else move.x = -1 + 2 * dir; } - if (moveX.x != 0f) animation += ANIM_SPEED; + if (move.x != 0f) animation += ANIM_SPEED; else animation = 0; if (animation >= 60 || animation <= -60) { ANIM_SPEED = -ANIM_SPEED; diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index 546fb6e..4a6c4d4 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -10,7 +10,7 @@ public class Player implements Serializable { public static int ANIM_SPEED = 6; public Vector2 position; - public Vector2 moveX, moveY; + public Vector2 move; public int width, height, dir, texWidth; public boolean canJump; public int[] inventory; @@ -18,8 +18,7 @@ public class Player implements Serializable { public Player(Vector2 spawnPoint) { position = spawnPoint.cpy(); - moveX = new Vector2(0, 0); - moveY = new Vector2(0, 0); + move = new Vector2(0, 0); width = 4; height = 30; texWidth = 8;