From d10148ace1afdf1dd79c218ed8ce9605663e452c Mon Sep 17 00:00:00 2001 From: Matt Low Date: Thu, 26 Dec 2019 01:54:58 +0400 Subject: [PATCH] Refactor N/E/S/W to U/D/L/R --- core/src/com/me/pacman/entity/Direction.java | 8 +++---- .../com/me/pacman/entity/MovableEntity.java | 24 +++++++++---------- core/src/com/me/pacman/entity/Pacman.java | 2 +- core/src/com/me/pacman/state/PlayState.java | 11 ++++----- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/core/src/com/me/pacman/entity/Direction.java b/core/src/com/me/pacman/entity/Direction.java index 630ee34..70b7bac 100644 --- a/core/src/com/me/pacman/entity/Direction.java +++ b/core/src/com/me/pacman/entity/Direction.java @@ -1,8 +1,8 @@ package com.me.pacman.entity; public enum Direction { - NORTH, - SOUTH, - WEST, - EAST, + UP, + DOWN, + LEFT, + RIGHT, } diff --git a/core/src/com/me/pacman/entity/MovableEntity.java b/core/src/com/me/pacman/entity/MovableEntity.java index 383f6c7..a7856c6 100644 --- a/core/src/com/me/pacman/entity/MovableEntity.java +++ b/core/src/com/me/pacman/entity/MovableEntity.java @@ -34,10 +34,10 @@ public abstract class MovableEntity extends Entity { if (nextDirection != null) { boolean turned = false; switch (nextDirection) { - case NORTH: + case UP: nextTile = state.level.getTile(x, y + 1f); if (nextTile == null) { - if (currDirection == Direction.SOUTH) { + if (currDirection == Direction.DOWN) { turned = true; } } else if (nextTile.isPassable() && Math.abs(x - ((int) x + 0.5f)) <= tolerance) { @@ -45,10 +45,10 @@ public abstract class MovableEntity extends Entity { turned = true; } break; - case EAST: + case RIGHT: nextTile = state.level.getTile(x + 1f, y); if (nextTile == null) { - if (currDirection == Direction.WEST) { + if (currDirection == Direction.LEFT) { turned = true; } } else if (nextTile.isPassable() && Math.abs(y - ((int) y + 0.5f)) <= tolerance) { @@ -56,10 +56,10 @@ public abstract class MovableEntity extends Entity { turned = true; } break; - case SOUTH: + case DOWN: nextTile = state.level.getTile(x, y - 1f); if (nextTile == null) { - if (currDirection == Direction.NORTH) { + if (currDirection == Direction.UP) { turned = true; } } else if (nextTile.isPassable() && Math.abs(x - ((int) x + 0.5f)) <= tolerance) { @@ -67,10 +67,10 @@ public abstract class MovableEntity extends Entity { turned = true; } break; - case WEST: + case LEFT: nextTile = state.level.getTile(x - 1f, y); if (nextTile == null) { - if (currDirection == Direction.EAST) { + if (currDirection == Direction.RIGHT) { turned = true; } } else if (nextTile.isPassable() && Math.abs(y - ((int) y + 0.5f)) <= tolerance) { @@ -94,7 +94,7 @@ public abstract class MovableEntity extends Entity { float new_x = x; switch (currDirection) { - case NORTH: + case UP: if (currentTile == null && y > state.level.height + 1) { new_y = -1f; canMove = true; @@ -104,7 +104,7 @@ public abstract class MovableEntity extends Entity { canMove = nextTile == null || nextTile.isPassable(); } break; - case EAST: + case RIGHT: if (currentTile == null && x > state.level.width + 1) { new_x = -1f; canMove = true; @@ -114,7 +114,7 @@ public abstract class MovableEntity extends Entity { canMove = nextTile == null || nextTile.isPassable(); } break; - case SOUTH: + case DOWN: if (currentTile == null && y < 0) { new_y = state.level.height + 1; canMove = true; @@ -124,7 +124,7 @@ public abstract class MovableEntity extends Entity { canMove = nextTile == null || nextTile.isPassable(); } break; - case WEST: + case LEFT: if (currentTile == null && x < 0) { new_x = state.level.width + 1; canMove = true; diff --git a/core/src/com/me/pacman/entity/Pacman.java b/core/src/com/me/pacman/entity/Pacman.java index 1e1bd06..e3a413a 100644 --- a/core/src/com/me/pacman/entity/Pacman.java +++ b/core/src/com/me/pacman/entity/Pacman.java @@ -18,7 +18,7 @@ public class Pacman extends MovableEntity { public int deathFrame = 0; public Pacman(PlayState state, boolean moving) { - super(state, 14, 7.5f, 7.5f, moving, Direction.WEST, 0.3f); + super(state, 14, 7.5f, 7.5f, moving, Direction.LEFT, 0.3f); this.state = state; sprite = state.getGame().assets.pacman; death = state.getGame().assets.deathAnimation; diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index 546aedf..11bd330 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -3,7 +3,6 @@ package com.me.pacman.state; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; -import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -203,7 +202,7 @@ public class PlayState extends LevelState { pacmanCaught = false; pacman = new Pacman(this, false); - ghosts[0] = new Ghost(this, 14, 19.5f, Direction.WEST, 0, null, null, null); + ghosts[0] = new Ghost(this, 14, 19.5f, Direction.LEFT, 0, null, null, null); } public void startGame() { @@ -256,16 +255,16 @@ public class PlayState extends LevelState { public boolean keyDown(int keycode) { switch (keycode) { case Input.Keys.UP: - pacman.setNextDirection(Direction.NORTH); + pacman.setNextDirection(Direction.UP); break; case Input.Keys.DOWN: - pacman.setNextDirection(Direction.SOUTH); + pacman.setNextDirection(Direction.DOWN); break; case Input.Keys.LEFT: - pacman.setNextDirection(Direction.WEST); + pacman.setNextDirection(Direction.LEFT); break; case Input.Keys.RIGHT: - pacman.setNextDirection(Direction.EAST); + pacman.setNextDirection(Direction.RIGHT); break; case Input.Keys.P: paused = !paused;