Refactor N/E/S/W to U/D/L/R
This commit is contained in:
		@ -1,8 +1,8 @@
 | 
				
			|||||||
package com.me.pacman.entity;
 | 
					package com.me.pacman.entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public enum Direction {
 | 
					public enum Direction {
 | 
				
			||||||
    NORTH,
 | 
					    UP,
 | 
				
			||||||
    SOUTH,
 | 
					    DOWN,
 | 
				
			||||||
    WEST,
 | 
					    LEFT,
 | 
				
			||||||
    EAST,
 | 
					    RIGHT,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -34,10 +34,10 @@ public abstract class MovableEntity extends Entity {
 | 
				
			|||||||
        if (nextDirection != null) {
 | 
					        if (nextDirection != null) {
 | 
				
			||||||
            boolean turned = false;
 | 
					            boolean turned = false;
 | 
				
			||||||
            switch (nextDirection) {
 | 
					            switch (nextDirection) {
 | 
				
			||||||
                case NORTH:
 | 
					                case UP:
 | 
				
			||||||
                    nextTile = state.level.getTile(x, y + 1f);
 | 
					                    nextTile = state.level.getTile(x, y + 1f);
 | 
				
			||||||
                    if (nextTile == null) {
 | 
					                    if (nextTile == null) {
 | 
				
			||||||
                        if (currDirection == Direction.SOUTH) {
 | 
					                        if (currDirection == Direction.DOWN) {
 | 
				
			||||||
                            turned = true;
 | 
					                            turned = true;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } else if (nextTile.isPassable() && Math.abs(x - ((int) x + 0.5f)) <= tolerance) {
 | 
					                    } else if (nextTile.isPassable() && Math.abs(x - ((int) x + 0.5f)) <= tolerance) {
 | 
				
			||||||
@ -45,10 +45,10 @@ public abstract class MovableEntity extends Entity {
 | 
				
			|||||||
                        turned = true;
 | 
					                        turned = true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case EAST:
 | 
					                case RIGHT:
 | 
				
			||||||
                    nextTile = state.level.getTile(x + 1f, y);
 | 
					                    nextTile = state.level.getTile(x + 1f, y);
 | 
				
			||||||
                    if (nextTile == null) {
 | 
					                    if (nextTile == null) {
 | 
				
			||||||
                        if (currDirection == Direction.WEST) {
 | 
					                        if (currDirection == Direction.LEFT) {
 | 
				
			||||||
                            turned = true;
 | 
					                            turned = true;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } else if (nextTile.isPassable() && Math.abs(y - ((int) y + 0.5f)) <= tolerance) {
 | 
					                    } else if (nextTile.isPassable() && Math.abs(y - ((int) y + 0.5f)) <= tolerance) {
 | 
				
			||||||
@ -56,10 +56,10 @@ public abstract class MovableEntity extends Entity {
 | 
				
			|||||||
                        turned = true;
 | 
					                        turned = true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case SOUTH:
 | 
					                case DOWN:
 | 
				
			||||||
                    nextTile = state.level.getTile(x, y - 1f);
 | 
					                    nextTile = state.level.getTile(x, y - 1f);
 | 
				
			||||||
                    if (nextTile == null) {
 | 
					                    if (nextTile == null) {
 | 
				
			||||||
                        if (currDirection == Direction.NORTH) {
 | 
					                        if (currDirection == Direction.UP) {
 | 
				
			||||||
                            turned = true;
 | 
					                            turned = true;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } else if (nextTile.isPassable() && Math.abs(x - ((int) x + 0.5f)) <= tolerance) {
 | 
					                    } else if (nextTile.isPassable() && Math.abs(x - ((int) x + 0.5f)) <= tolerance) {
 | 
				
			||||||
@ -67,10 +67,10 @@ public abstract class MovableEntity extends Entity {
 | 
				
			|||||||
                        turned = true;
 | 
					                        turned = true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case WEST:
 | 
					                case LEFT:
 | 
				
			||||||
                    nextTile = state.level.getTile(x - 1f, y);
 | 
					                    nextTile = state.level.getTile(x - 1f, y);
 | 
				
			||||||
                    if (nextTile == null) {
 | 
					                    if (nextTile == null) {
 | 
				
			||||||
                        if (currDirection == Direction.EAST) {
 | 
					                        if (currDirection == Direction.RIGHT) {
 | 
				
			||||||
                            turned = true;
 | 
					                            turned = true;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } else if (nextTile.isPassable() && Math.abs(y - ((int) y + 0.5f)) <= tolerance) {
 | 
					                    } 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;
 | 
					        float new_x = x;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        switch (currDirection) {
 | 
					        switch (currDirection) {
 | 
				
			||||||
            case NORTH:
 | 
					            case UP:
 | 
				
			||||||
                if (currentTile == null && y > state.level.height + 1) {
 | 
					                if (currentTile == null && y > state.level.height + 1) {
 | 
				
			||||||
                    new_y = -1f;
 | 
					                    new_y = -1f;
 | 
				
			||||||
                    canMove = true;
 | 
					                    canMove = true;
 | 
				
			||||||
@ -104,7 +104,7 @@ public abstract class MovableEntity extends Entity {
 | 
				
			|||||||
                    canMove = nextTile == null || nextTile.isPassable();
 | 
					                    canMove = nextTile == null || nextTile.isPassable();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case EAST:
 | 
					            case RIGHT:
 | 
				
			||||||
                if (currentTile == null && x > state.level.width + 1) {
 | 
					                if (currentTile == null && x > state.level.width + 1) {
 | 
				
			||||||
                    new_x = -1f;
 | 
					                    new_x = -1f;
 | 
				
			||||||
                    canMove = true;
 | 
					                    canMove = true;
 | 
				
			||||||
@ -114,7 +114,7 @@ public abstract class MovableEntity extends Entity {
 | 
				
			|||||||
                    canMove = nextTile == null || nextTile.isPassable();
 | 
					                    canMove = nextTile == null || nextTile.isPassable();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case SOUTH:
 | 
					            case DOWN:
 | 
				
			||||||
                if (currentTile == null && y < 0) {
 | 
					                if (currentTile == null && y < 0) {
 | 
				
			||||||
                    new_y = state.level.height + 1;
 | 
					                    new_y = state.level.height + 1;
 | 
				
			||||||
                    canMove = true;
 | 
					                    canMove = true;
 | 
				
			||||||
@ -124,7 +124,7 @@ public abstract class MovableEntity extends Entity {
 | 
				
			|||||||
                    canMove = nextTile == null || nextTile.isPassable();
 | 
					                    canMove = nextTile == null || nextTile.isPassable();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case WEST:
 | 
					            case LEFT:
 | 
				
			||||||
                if (currentTile == null && x < 0) {
 | 
					                if (currentTile == null && x < 0) {
 | 
				
			||||||
                    new_x = state.level.width + 1;
 | 
					                    new_x = state.level.width + 1;
 | 
				
			||||||
                    canMove = true;
 | 
					                    canMove = true;
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@ public class Pacman extends MovableEntity {
 | 
				
			|||||||
    public int deathFrame = 0;
 | 
					    public int deathFrame = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Pacman(PlayState state, boolean moving) {
 | 
					    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;
 | 
					        this.state = state;
 | 
				
			||||||
        sprite = state.getGame().assets.pacman;
 | 
					        sprite = state.getGame().assets.pacman;
 | 
				
			||||||
        death = state.getGame().assets.deathAnimation;
 | 
					        death = state.getGame().assets.deathAnimation;
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,6 @@ package com.me.pacman.state;
 | 
				
			|||||||
import com.badlogic.gdx.Gdx;
 | 
					import com.badlogic.gdx.Gdx;
 | 
				
			||||||
import com.badlogic.gdx.Input;
 | 
					import com.badlogic.gdx.Input;
 | 
				
			||||||
import com.badlogic.gdx.InputAdapter;
 | 
					import com.badlogic.gdx.InputAdapter;
 | 
				
			||||||
import com.badlogic.gdx.audio.Sound;
 | 
					 | 
				
			||||||
import com.badlogic.gdx.graphics.Color;
 | 
					import com.badlogic.gdx.graphics.Color;
 | 
				
			||||||
import com.badlogic.gdx.graphics.Texture;
 | 
					import com.badlogic.gdx.graphics.Texture;
 | 
				
			||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
 | 
					import com.badlogic.gdx.graphics.g2d.BitmapFont;
 | 
				
			||||||
@ -203,7 +202,7 @@ public class PlayState extends LevelState {
 | 
				
			|||||||
        pacmanCaught = false;
 | 
					        pacmanCaught = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pacman = new Pacman(this, 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() {
 | 
					    public void startGame() {
 | 
				
			||||||
@ -256,16 +255,16 @@ public class PlayState extends LevelState {
 | 
				
			|||||||
        public boolean keyDown(int keycode) {
 | 
					        public boolean keyDown(int keycode) {
 | 
				
			||||||
            switch (keycode) {
 | 
					            switch (keycode) {
 | 
				
			||||||
                case Input.Keys.UP:
 | 
					                case Input.Keys.UP:
 | 
				
			||||||
                    pacman.setNextDirection(Direction.NORTH);
 | 
					                    pacman.setNextDirection(Direction.UP);
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case Input.Keys.DOWN:
 | 
					                case Input.Keys.DOWN:
 | 
				
			||||||
                    pacman.setNextDirection(Direction.SOUTH);
 | 
					                    pacman.setNextDirection(Direction.DOWN);
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case Input.Keys.LEFT:
 | 
					                case Input.Keys.LEFT:
 | 
				
			||||||
                    pacman.setNextDirection(Direction.WEST);
 | 
					                    pacman.setNextDirection(Direction.LEFT);
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case Input.Keys.RIGHT:
 | 
					                case Input.Keys.RIGHT:
 | 
				
			||||||
                    pacman.setNextDirection(Direction.EAST);
 | 
					                    pacman.setNextDirection(Direction.RIGHT);
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case Input.Keys.P:
 | 
					                case Input.Keys.P:
 | 
				
			||||||
                    paused = !paused;
 | 
					                    paused = !paused;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user