From be2690f1dee10f68a5ce6d576ace13c825ac5d15 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Sun, 30 Sep 2018 21:38:19 +0700 Subject: [PATCH] Rename position -> pos --- .../cavecraft/game/GameInput.java | 4 +- .../cavecraft/game/GamePhysics.java | 66 +++++++++---------- .../deadsoftware/cavecraft/game/GameProc.java | 8 +-- .../cavecraft/game/GameRenderer.java | 46 ++++++------- .../cavecraft/game/mobs/FallingGravel.java | 4 +- .../cavecraft/game/mobs/FallingSand.java | 4 +- .../deadsoftware/cavecraft/game/mobs/Mob.java | 4 +- .../deadsoftware/cavecraft/game/mobs/Pig.java | 14 ++-- .../cavecraft/game/objects/Drop.java | 6 +- .../cavecraft/game/objects/Player.java | 6 +- 10 files changed, 81 insertions(+), 81 deletions(-) diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index 5f7dfea..48388ac 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -17,8 +17,8 @@ public class GameInput { } private boolean checkSwim() { - return (GameItems.isFluid(gp.world.getForeMap((int) (gp.player.position.x + gp.player.width / 2) / 16, - (int) (gp.player.position.y + gp.player.height / 4 * 3) / 16))); + return (GameItems.isFluid(gp.world.getForeMap((int) (gp.player.pos.x + gp.player.width / 2) / 16, + (int) (gp.player.pos.y + gp.player.height / 4 * 3) / 16))); } private void wasdPressed(int keycode) { diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index d78d319..d314b82 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -69,16 +69,16 @@ public class GamePhysics { private void dropPhy(Drop drop) { if (drop.move.y < 9) drop.move.y += gravity.y / 4; - drop.position.add(drop.move); - drop.position.y = MathUtils.round(drop.position.y); + drop.pos.add(drop.move); + drop.pos.y = MathUtils.round(drop.pos.y); while (checkColl(drop.getRect())) { - drop.position.y--; + drop.pos.y--; drop.move.y = 0; } } private void playerPhy(Player pl) { - pl.position.y += pl.move.y; + pl.pos.y += pl.move.y; if (checkColl(pl.getRect())) { int d = -1; if (pl.move.y < 0) d = 1; @@ -86,8 +86,8 @@ public class GamePhysics { pl.flyMode = false; pl.canJump = true; } - pl.position.y = MathUtils.round(pl.position.y); - while (checkColl(pl.getRect())) pl.position.y += d; + pl.pos.y = MathUtils.round(pl.pos.y); + while (checkColl(pl.getRect())) pl.pos.y += d; pl.move.y = 0; } else { pl.canJump = false; @@ -106,23 +106,23 @@ public class GamePhysics { if (!pl.flyMode && pl.move.y < 18) pl.move.add(gravity); } - pl.position.x += pl.move.x; + pl.pos.x += pl.move.x; if (checkColl(pl.getRect())) { - if (pl.canJump && !pl.flyMode) pl.position.y -= 8; + if (pl.canJump && !pl.flyMode) pl.pos.y -= 8; if (checkColl(pl.getRect())) { - if (pl.canJump && !pl.flyMode) pl.position.y += 8; + if (pl.canJump && !pl.flyMode) pl.pos.y += 8; int d = 0; 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; + pl.pos.x = MathUtils.round(pl.pos.x); + while (checkColl(pl.getRect())) pl.pos.x += d; } } - if (pl.position.x + pl.texWidth / 2 < 0) pl.position.x += gp.world.getWidth() * 16; - if (pl.position.x + pl.texWidth / 2 > gp.world.getWidth() * 16) - pl.position.x -= gp.world.getWidth() * 16; - if (pl.position.y > gp.world.getHeight() * 16) { - pl.position = gp.world.getSpawnPoint().cpy(); + if (pl.pos.x + pl.texWidth / 2 < 0) pl.pos.x += gp.world.getWidth() * 16; + if (pl.pos.x + pl.texWidth / 2 > gp.world.getWidth() * 16) + pl.pos.x -= gp.world.getWidth() * 16; + if (pl.pos.y > gp.world.getHeight() * 16) { + pl.pos = gp.world.getSpawnPoint().cpy(); } if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && pl.move.x != 0) { pl.move.add(0, -8); @@ -131,17 +131,17 @@ public class GamePhysics { } private void mobPhy(Mob mob) { - mob.position.y += mob.move.y; + mob.pos.y += mob.move.y; if (checkColl(mob.getRect())) { int 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.pos.y = MathUtils.round(mob.pos.y); + while (checkColl(mob.getRect())) mob.pos.y += d; mob.move.y = 0; if (mob.getType() > 0) { - gp.world.setForeMap((int) mob.position.x / 16, (int) mob.position.y / 16, mob.getType()); - mob.position.y = -1; + gp.world.setForeMap((int) mob.pos.x / 16, (int) mob.pos.y / 16, mob.getType()); + mob.pos.y = -1; mob.dead = true; } } else { @@ -154,26 +154,26 @@ public class GamePhysics { if (mob.move.y < -3) mob.move.y = -3; } else if (mob.move.y < 18) mob.move.add(gravity); - mob.position.x += mob.move.x; + mob.pos.x += mob.move.x; if (checkColl(mob.getRect())) { if (mob.canJump) { - mob.position.y -= 8; + mob.pos.y -= 8; } if (checkColl(mob.getRect())) { - if (mob.canJump) mob.position.y += 8; + if (mob.canJump) mob.pos.y += 8; int d = 0; 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; + mob.pos.x = MathUtils.round(mob.pos.x); + while (checkColl(mob.getRect())) mob.pos.x += d; if (mob.canJump) mob.changeDir(); } } - if (mob.position.x + mob.width / 2 < 0) mob.position.x += gp.world.getWidth() * 16; - if (mob.position.x + mob.width / 2 > gp.world.getWidth() * 16) - mob.position.x -= gp.world.getWidth() * 16; - if (mob.position.y > gp.world.getHeight() * 16) { - mob.position.y = 0; + if (mob.pos.x + mob.width / 2 < 0) mob.pos.x += gp.world.getWidth() * 16; + if (mob.pos.x + mob.width / 2 > gp.world.getWidth() * 16) + mob.pos.x -= gp.world.getWidth() * 16; + if (mob.pos.y > gp.world.getHeight() * 16) { + mob.pos.y = 0; } if (checkJump(mob.getRect(), mob.dir) && mob.canJump && mob.move.x != 0) { mob.move.add(0, -8); @@ -201,8 +201,8 @@ public class GamePhysics { playerPhy(gp.player); gp.renderer.setCamPos( - gp.player.position.x + gp.player.texWidth / 2 - gp.renderer.getWidth() / 2, - gp.player.position.y + gp.player.height / 2 - gp.renderer.getHeight() / 2); + gp.player.pos.x + gp.player.texWidth / 2 - gp.renderer.getWidth() / 2, + gp.player.pos.y + gp.player.height / 2 - gp.renderer.getHeight() / 2); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 3117cde..08f4425 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -84,10 +84,10 @@ public class GameProc implements Serializable { private void moveCursor() { int pastX = curX, pastY = curY; if (ctrlMode == 0 && CaveGame.TOUCH) { - curX = (int) (player.position.x + player.texWidth / 2) / 16; + curX = (int) (player.pos.x + player.texWidth / 2) / 16; if (player.dir == 0) curX--; else curX++; - curY = (int) (player.position.y + player.texWidth) / 16; + curY = (int) (player.pos.y + player.texWidth) / 16; if (!isAutoselectable(curX, curY)) { curY++; } @@ -114,9 +114,9 @@ public class GameProc implements Serializable { if (curY < 0) curY = 0; if (curY >= world.getHeight()) curY = world.getHeight() - 1; if (ctrlMode == 1) { - if (curX * 16 + 8 < player.position.x + player.texWidth / 2) + if (curX * 16 + 8 < player.pos.x + player.texWidth / 2) player.dir = 0; - if (curX * 16 + 8 > player.position.x + player.texWidth / 2) + if (curX * 16 + 8 > player.pos.x + player.texWidth / 2) player.dir = 1; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index a0ac68a..96f8c78 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -88,21 +88,21 @@ public class GameRenderer extends Renderer { private void drawMob(Mob mob) { mob.draw(spriter, - mob.position.x - getCamX() - gp.world.getWidth() * 16, mob.position.y - getCamY()); + mob.pos.x - getCamX() - gp.world.getWidth() * 16, mob.pos.y - getCamY()); mob.draw(spriter, - mob.position.x - getCamX(), mob.position.y - getCamY()); + mob.pos.x - getCamX(), mob.pos.y - getCamY()); mob.draw(spriter, - mob.position.x - getCamX() + gp.world.getWidth() * 16, mob.position.y - getCamY()); + mob.pos.x - getCamX() + gp.world.getWidth() * 16, mob.pos.y - getCamY()); } private void drawDrop(Drop drop) { switch (GameItems.getItem(drop.getId()).getType()) { case 0: - Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.position.x - getCamX() - gp.world.getWidth() * 16, drop.position.y - getCamY()); + Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX() - gp.world.getWidth() * 16, drop.pos.y - getCamY()); Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter); - Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.position.x - getCamX(), drop.position.y - getCamY()); + Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX(), drop.pos.y - getCamY()); Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter); - Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.position.x - getCamX() + gp.world.getWidth() * 16, drop.position.y - getCamY()); + Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX() + gp.world.getWidth() * 16, drop.pos.y - getCamY()); Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter); } } @@ -124,33 +124,33 @@ public class GameRenderer extends Renderer { //back hand Assets.plSprite[1][2].setPosition( - pl.position.x - getCamX() - 6, - pl.position.y - getCamY()); + pl.pos.x - getCamX() - 6, + pl.pos.y - getCamY()); Assets.plSprite[1][2].draw(spriter); //back leg Assets.plSprite[1][3].setPosition( - pl.position.x - getCamX() - 6, - pl.position.y - getCamY() + 10); + pl.pos.x - getCamX() - 6, + pl.pos.y - getCamY() + 10); Assets.plSprite[1][3].draw(spriter); //front leg Assets.plSprite[0][3].setPosition( - pl.position.x - getCamX() - 6, - pl.position.y - getCamY() + 10); + pl.pos.x - getCamX() - 6, + pl.pos.y - getCamY() + 10); Assets.plSprite[0][3].draw(spriter); //head spriter.draw(Assets.plSprite[pl.dir][0], - pl.position.x - getCamX() - 2, - pl.position.y - getCamY() - 2); + pl.pos.x - getCamX() - 2, + pl.pos.y - getCamY() - 2); //body spriter.draw(Assets.plSprite[pl.dir][1], - pl.position.x - getCamX() - 2, pl.position.y - getCamY() + 8); + pl.pos.x - getCamX() - 2, pl.pos.y - getCamY() + 8); //item in hand if (pl.inv[gp.slot] > 0) switch (GameItems.getItem(pl.inv[gp.slot]).getType()) { case 0: Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition( - pl.position.x - getCamX() - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()), - pl.position.y - getCamY() + 6 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation())); + pl.pos.x - getCamX() - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()), + pl.pos.y - getCamY() + 6 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation())); Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].draw(spriter); break; default: @@ -158,16 +158,16 @@ public class GameRenderer extends Renderer { Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setRotation( -45 + pl.dir * 90 + Assets.plSprite[0][2].getRotation()); Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition( - pl.position.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()), - pl.position.y - getCamY() + 2 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation())); + pl.pos.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()), + pl.pos.y - getCamY() + 2 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation())); Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].draw(spriter); Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].flip((pl.dir == 0), false); break; } //front hand Assets.plSprite[0][2].setPosition( - pl.position.x - getCamX() - 6, - pl.position.y - getCamY()); + pl.pos.x - getCamX() - 6, + pl.pos.y - getCamY()); Assets.plSprite[0][2].draw(spriter); } @@ -279,8 +279,8 @@ public class GameRenderer extends Renderer { if (GameScreen.SHOW_DEBUG) { drawString("FPS: " + GameScreen.FPS, 0, 0); - drawString("X: " + (int) (gp.player.position.x / 16), 0, 10); - drawString("Y: " + (int) (gp.player.position.y / 16), 0, 20); + drawString("X: " + (int) (gp.player.pos.x / 16), 0, 10); + drawString("Y: " + (int) (gp.player.pos.y / 16), 0, 20); drawString("Mobs: " + gp.mobs.size(), 0, 30); drawString("Drops: " + gp.drops.size(), 0, 40); drawString("Block: " + GameItems.getBlockKey(gp.world.getForeMap(gp.curX, gp.curY)), 0, 50); diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java index 21b8dd8..cc3c389 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingGravel.java @@ -10,7 +10,7 @@ public class FallingGravel extends Mob { public FallingGravel(int x, int y) { dir = 0; - position = new Vector2(x, y); + pos = new Vector2(x, y); move = new Vector2(0, 1); width = 16; height = 16; @@ -33,7 +33,7 @@ public class FallingGravel extends Mob { @Override public Rectangle getRect() { - return new Rectangle(position.x, position.y, width, height); + return new Rectangle(pos.x, pos.y, width, height); } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java index b491af5..b910884 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/FallingSand.java @@ -10,7 +10,7 @@ public class FallingSand extends Mob { public FallingSand(int x, int y) { dir = 0; - position = new Vector2(x, y); + pos = new Vector2(x, y); move = new Vector2(0, 1); width = 16; height = 16; @@ -33,7 +33,7 @@ public class FallingSand extends Mob { @Override public Rectangle getRect() { - return new Rectangle(position.x, position.y, width, height); + return new Rectangle(pos.x, pos.y, width, height); } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java index 137e7ca..67df9f7 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java @@ -9,9 +9,9 @@ import java.io.Serializable; public abstract class Mob implements Serializable { public int ANIM_SPEED = 6; - public Vector2 position; + public Vector2 pos; public Vector2 move; - public int width, height, dir, animation; + public int width, height, dir, anim; 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 c615fcb..38eac46 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -10,7 +10,7 @@ public class Pig extends Mob { public Pig(int x, int y) { dir = MathUtils.random(1); - position = new Vector2(x, y); + pos = new Vector2(x, y); move = new Vector2(-1 + dir * 2, 0); width = 25; height = 18; @@ -31,17 +31,17 @@ public class Pig extends Mob { if (move.x != 0f) move.x = 0; else move.x = -1 + 2 * dir; } - if (move.x != 0f) animation += ANIM_SPEED; - else animation = 0; - if (animation >= 60 || animation <= -60) { + if (move.x != 0f) anim += ANIM_SPEED; + else anim = 0; + if (anim >= 60 || anim <= -60) { ANIM_SPEED = -ANIM_SPEED; } } @Override public void draw(SpriteBatch spriteBatch, float x, float y) { - Assets.pigSprite[0][1].setRotation(animation); - Assets.pigSprite[1][1].setRotation(-animation); + Assets.pigSprite[0][1].setRotation(anim); + Assets.pigSprite[1][1].setRotation(-anim); //back legs Assets.pigSprite[1][1].setPosition(x - 4 + (9 - dir * 9), y + 6); Assets.pigSprite[1][1].draw(spriteBatch); @@ -58,7 +58,7 @@ public class Pig extends Mob { @Override public Rectangle getRect() { - return new Rectangle(position.x, position.y, width, height); + return new Rectangle(pos.x, pos.y, width, height); } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java index d92b846..fa60f6b 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java @@ -8,11 +8,11 @@ import java.io.Serializable; public class Drop implements Serializable { private int id; public boolean pickedUp = false; - public Vector2 move, position; + public Vector2 move, pos; public Drop(float x, float y, int id) { this.id = id; - position = new Vector2(x, y); + pos = new Vector2(x, y); move = new Vector2(0, -1); } @@ -31,7 +31,7 @@ public class Drop implements Serializable { } public Rectangle getRect() { - return new Rectangle(position.x, position.y, 8, 8); + return new Rectangle(pos.x, pos.y, 8, 8); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index ad5faaf..74f7249 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -9,7 +9,7 @@ public class Player implements Serializable { public static int ANIM_SPEED = 6; - public Vector2 position; + public Vector2 pos; public Vector2 move; public int width, height, dir, texWidth; public boolean canJump; @@ -17,7 +17,7 @@ public class Player implements Serializable { public boolean flyMode = false; public Player(Vector2 spawnPoint) { - position = spawnPoint.cpy(); + pos = spawnPoint.cpy(); move = new Vector2(0, 0); width = 4; height = 30; @@ -26,7 +26,7 @@ public class Player implements Serializable { } public Rectangle getRect() { - return new Rectangle(position.x + 2, position.y, width, height); + return new Rectangle(pos.x + 2, pos.y, width, height); } } -- 2.29.2