Refactor N/E/S/W to U/D/L/R

This commit is contained in:
Matt Low 2019-12-26 01:54:58 +04:00
parent 0177090ea3
commit d10148ace1
4 changed files with 22 additions and 23 deletions

View File

@ -1,8 +1,8 @@
package com.me.pacman.entity;
public enum Direction {
NORTH,
SOUTH,
WEST,
EAST,
UP,
DOWN,
LEFT,
RIGHT,
}

View File

@ -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;

View File

@ -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;

View File

@ -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;