From b19daafc2b777cd289b791973d0a4abec7b946a9 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 22 Jan 2020 02:34:59 +0400 Subject: [PATCH] Refactor some constants to Constants class Use TILE_SIZE everywhere a magic 8 appears (in the context of a tile size) --- core/src/com/me/pacman/Constants.java | 32 +++++++++++++++++++ core/src/com/me/pacman/PacDude.java | 27 ++++++---------- core/src/com/me/pacman/entity/Blinky.java | 4 +-- core/src/com/me/pacman/entity/Entity.java | 6 ++-- core/src/com/me/pacman/entity/Ghost.java | 3 +- core/src/com/me/pacman/entity/Inky.java | 4 +-- core/src/com/me/pacman/entity/Pacman.java | 3 +- core/src/com/me/pacman/entity/Pinky.java | 4 +-- core/src/com/me/pacman/level/Level.java | 3 +- core/src/com/me/pacman/level/Modifiers.java | 16 +++++----- .../me/pacman/state/HighScoreEntryState.java | 11 ++++--- .../com/me/pacman/state/HighScoresState.java | 7 ++-- core/src/com/me/pacman/state/LevelState.java | 10 +++--- core/src/com/me/pacman/state/MenuState.java | 9 +++--- core/src/com/me/pacman/state/PlayState.java | 26 +++++++-------- .../me/pacman/desktop/DesktopLauncher.java | 7 ++-- 16 files changed, 101 insertions(+), 71 deletions(-) create mode 100644 core/src/com/me/pacman/Constants.java diff --git a/core/src/com/me/pacman/Constants.java b/core/src/com/me/pacman/Constants.java new file mode 100644 index 0000000..f212bea --- /dev/null +++ b/core/src/com/me/pacman/Constants.java @@ -0,0 +1,32 @@ +package com.me.pacman; + +public final class Constants { + + public static final String TITLE = "Pac-Dude"; + public static final String VERSION = "v0.1.0"; + + public static final boolean DEBUG = false; + + // Pixels + public static final int TILE_SIZE = 8; + + // The size of the original Pac-Man game in 8x8 pixel tiles + public static final int GAME_WIDTH_TILES = 28; + public static final int GAME_HEIGHT_TILES = 36; + + // The game window width and height - arbitrary units (in this case, matches up with the pixel + // counts of the original Pacman. + public static final int GAME_WIDTH = GAME_WIDTH_TILES * TILE_SIZE; + public static final int GAME_HEIGHT = GAME_HEIGHT_TILES * TILE_SIZE; + + // Pac-man level rendering position offset in game coordinates + public static final int LEVEL_OFFSET_X = 0; + public static final int LEVEL_OFFSET_Y = 2 * TILE_SIZE; + + // 100% speed in tiles (8 pixel / tile) per second. roughly 75 pixels/second + // 75 pixels/second aligns with the per-frame pixel movement steps in: + // https://github.com/masonicGIT/pacman/blob/master/pacman.js + // and is close to the 75.75757625 pixels/second claimed in: + // https://pacman.holenet.info/#LvlSpecs + public static final float FULL_SPEED = 9.375f; +} diff --git a/core/src/com/me/pacman/PacDude.java b/core/src/com/me/pacman/PacDude.java index 052cce2..bb96e4c 100644 --- a/core/src/com/me/pacman/PacDude.java +++ b/core/src/com/me/pacman/PacDude.java @@ -3,26 +3,19 @@ package com.me.pacman; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.Viewport; -import com.me.pacman.state.HighScoresState; import com.me.pacman.state.MenuState; import com.me.pacman.state.State; public class PacDude extends Game { - public static final String TITLE = "Pac-Dude"; - public static final String VERSION = "v0.1.0"; - - public static final boolean DEBUG = false; - - public static final int LEVEL_WIDTH = 224; - public static final int LEVEL_HEIGHT = 288; - - public HighScores highScores; + public Camera cam; + public Viewport viewport; public Assets assets; public Sound sound; @@ -30,19 +23,16 @@ public class PacDude extends Game { public SpriteBatch batch; public FontRenderer fontRenderer; - public OrthographicCamera cam; - public Viewport viewport; + public HighScores highScores; private State nextState; @Override public void create () { cam = new OrthographicCamera(); - viewport = new FitViewport(LEVEL_WIDTH, LEVEL_HEIGHT, cam); + viewport = new FitViewport(Constants.GAME_WIDTH, Constants.GAME_HEIGHT, cam); viewport.apply(true); - highScores = new HighScores(); - assets = new Assets(); assets.loadAssets(); sound = new Sound(this); @@ -50,6 +40,8 @@ public class PacDude extends Game { batch = new SpriteBatch(); fontRenderer = new FontRenderer(assets.font); + highScores = new HighScores(); + Gdx.gl.glClearColor(0, 0, 0, 1); setNextState(new MenuState(this)); } @@ -57,7 +49,6 @@ public class PacDude extends Game { @Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - if (nextState != null) { Screen currScreen = getScreen(); if (currScreen != null) currScreen.dispose(); @@ -67,8 +58,8 @@ public class PacDude extends Game { } batch.begin(); - if (DEBUG) { - fontRenderer.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond(), 19 * 8, 34 * 8); + if (Constants.DEBUG) { + fontRenderer.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond(), 19 * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE); } super.render(); batch.end(); diff --git a/core/src/com/me/pacman/entity/Blinky.java b/core/src/com/me/pacman/entity/Blinky.java index 97c23c3..2cef977 100644 --- a/core/src/com/me/pacman/entity/Blinky.java +++ b/core/src/com/me/pacman/entity/Blinky.java @@ -1,7 +1,7 @@ package com.me.pacman.entity; import com.badlogic.gdx.math.Vector2; -import com.me.pacman.PacDude; +import com.me.pacman.Constants; import com.me.pacman.entity.ai.BlinkyChaseBehaviour; import com.me.pacman.entity.ai.StaticTargetBehaviour; import com.me.pacman.entity.ai.Target; @@ -10,7 +10,7 @@ import com.me.pacman.state.PlayState; public class Blinky extends Ghost { - public static final Target SCATTER_TARGET = new Target((PacDude.LEVEL_WIDTH / 8) - 2, PacDude.LEVEL_HEIGHT / 8); + public static final Target SCATTER_TARGET = new Target((Constants.GAME_WIDTH / 8) - 2, Constants.GAME_HEIGHT / 8); public Blinky(PlayState state, Vector2 pos, Direction direction) { super(state, pos, direction, 0, new BlinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), false); diff --git a/core/src/com/me/pacman/entity/Entity.java b/core/src/com/me/pacman/entity/Entity.java index f40ba50..77e8da5 100644 --- a/core/src/com/me/pacman/entity/Entity.java +++ b/core/src/com/me/pacman/entity/Entity.java @@ -2,7 +2,7 @@ package com.me.pacman.entity; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; -import com.me.pacman.PacDude; +import com.me.pacman.Constants; import com.me.pacman.entity.ai.Target; import com.me.pacman.level.LevelTile; import com.me.pacman.state.LevelState; @@ -29,8 +29,8 @@ public abstract class Entity { state.drawSprite(texture, pos.x, pos.y); - if (PacDude.DEBUG) { - state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, LevelState.LEVEL_OFFSET_X, LevelState.LEVEL_OFFSET_Y); + if (Constants.DEBUG) { + state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y); } } diff --git a/core/src/com/me/pacman/entity/Ghost.java b/core/src/com/me/pacman/entity/Ghost.java index 6d2738b..2d1c0e8 100644 --- a/core/src/com/me/pacman/entity/Ghost.java +++ b/core/src/com/me/pacman/entity/Ghost.java @@ -2,6 +2,7 @@ package com.me.pacman.entity; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; +import com.me.pacman.Constants; import com.me.pacman.entity.ai.Behaviour; import com.me.pacman.entity.ai.ReturnToBase; import com.me.pacman.entity.ai.Target; @@ -16,7 +17,7 @@ import java.util.ArrayList; public class Ghost extends MovableEntity { public static final float EYES_SPEED = 15f; - public static final float HOUSE_SPEED = PlayState.FULL_SPEED * 0.5f; + public static final float HOUSE_SPEED = Constants.FULL_SPEED * 0.5f; public static final Direction[] GHOST_ORDER = { Direction.UP, Direction.LEFT, Direction.DOWN, Direction.RIGHT }; diff --git a/core/src/com/me/pacman/entity/Inky.java b/core/src/com/me/pacman/entity/Inky.java index 0e0e9e1..ff50422 100644 --- a/core/src/com/me/pacman/entity/Inky.java +++ b/core/src/com/me/pacman/entity/Inky.java @@ -1,7 +1,7 @@ package com.me.pacman.entity; import com.badlogic.gdx.math.Vector2; -import com.me.pacman.PacDude; +import com.me.pacman.Constants; import com.me.pacman.entity.ai.InkyChaseBehaviour; import com.me.pacman.entity.ai.StaticTargetBehaviour; import com.me.pacman.entity.ai.Target; @@ -9,7 +9,7 @@ import com.me.pacman.state.PlayState; public class Inky extends Ghost { - public static final Target SCATTER_TARGET = new Target(PacDude.LEVEL_WIDTH / 8, -1); + public static final Target SCATTER_TARGET = new Target(Constants.GAME_WIDTH / 8, -1); public static final int DOT_LIMIT = 30; diff --git a/core/src/com/me/pacman/entity/Pacman.java b/core/src/com/me/pacman/entity/Pacman.java index 6c06433..d0c1f66 100644 --- a/core/src/com/me/pacman/entity/Pacman.java +++ b/core/src/com/me/pacman/entity/Pacman.java @@ -2,6 +2,7 @@ package com.me.pacman.entity; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; +import com.me.pacman.Constants; import com.me.pacman.level.LevelTile; import com.me.pacman.level.Modifiers; import com.me.pacman.state.PlayState; @@ -22,7 +23,7 @@ public class Pacman extends MovableEntity { public int deathFrame = 0; public Pacman(PlayState state, boolean moving) { - super(state, HOME.x, HOME.y, PlayState.FULL_SPEED * 0.8f, moving, Direction.LEFT, 0.3f); + super(state, HOME.x, HOME.y, Constants.FULL_SPEED * 0.8f, 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/entity/Pinky.java b/core/src/com/me/pacman/entity/Pinky.java index ed2aecf..2bd13a1 100644 --- a/core/src/com/me/pacman/entity/Pinky.java +++ b/core/src/com/me/pacman/entity/Pinky.java @@ -1,7 +1,7 @@ package com.me.pacman.entity; import com.badlogic.gdx.math.Vector2; -import com.me.pacman.PacDude; +import com.me.pacman.Constants; import com.me.pacman.entity.ai.PinkyChaseBehaviour; import com.me.pacman.entity.ai.StaticTargetBehaviour; import com.me.pacman.entity.ai.Target; @@ -9,7 +9,7 @@ import com.me.pacman.state.PlayState; public class Pinky extends Ghost { - public static final Target SCATTER_TARGET = new Target(2, PacDude.LEVEL_HEIGHT / 8); + public static final Target SCATTER_TARGET = new Target(2, Constants.GAME_HEIGHT / 8); public Pinky(PlayState state, Vector2 pos, Direction direction) { super(state, pos, direction, 1, new PinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), true); diff --git a/core/src/com/me/pacman/level/Level.java b/core/src/com/me/pacman/level/Level.java index 7309b4e..3eab01e 100644 --- a/core/src/com/me/pacman/level/Level.java +++ b/core/src/com/me/pacman/level/Level.java @@ -2,6 +2,7 @@ package com.me.pacman.level; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; +import com.me.pacman.Constants; import com.me.pacman.PacDude; public class Level { @@ -90,7 +91,7 @@ public class Level { default: return; } - game.batch.draw(sprite, (tileX * 8) + offsetX, (tileY * 8) + offsetY); + game.batch.draw(sprite, (tileX * Constants.TILE_SIZE) + offsetX, (tileY * Constants.TILE_SIZE) + offsetY); } } diff --git a/core/src/com/me/pacman/level/Modifiers.java b/core/src/com/me/pacman/level/Modifiers.java index 6c287b9..e94f444 100644 --- a/core/src/com/me/pacman/level/Modifiers.java +++ b/core/src/com/me/pacman/level/Modifiers.java @@ -1,6 +1,6 @@ package com.me.pacman.level; -import com.me.pacman.state.PlayState; +import com.me.pacman.Constants; import java.util.Arrays; @@ -35,23 +35,23 @@ public class Modifiers { } public static float getPacmanSpeed(int round) { - return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanSpeed; + return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanSpeed; } public static float getPacmanFrightSpeed(int round) { - return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanFrightSpeed; + return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanFrightSpeed; } public static float getGhostSpeed(int round) { - return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostSpeed; + return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostSpeed; } public static float getGhostFrightSpeed(int round) { - return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostFrightSpeed; + return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostFrightSpeed; } public static float getGhostTunnelSpeed(int round) { - return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostTunnelSpeed; + return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostTunnelSpeed; } public static int getElroy1DotsLeft(int round) { @@ -59,7 +59,7 @@ public class Modifiers { } public static float getElroy1Speed(int round) { - return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy1Speed; + return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy1Speed; } public static int getElroy2DotsLeft(int round) { @@ -67,7 +67,7 @@ public class Modifiers { } public static float getElroy2Speed(int round) { - return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy2Speed; + return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy2Speed; } public static int getForceLeaveSeconds(int round) { diff --git a/core/src/com/me/pacman/state/HighScoreEntryState.java b/core/src/com/me/pacman/state/HighScoreEntryState.java index 418e2bb..2f2c7f7 100644 --- a/core/src/com/me/pacman/state/HighScoreEntryState.java +++ b/core/src/com/me/pacman/state/HighScoreEntryState.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; +import com.me.pacman.Constants; import com.me.pacman.FontRenderer; import com.me.pacman.Score; import com.me.pacman.PacDude; @@ -40,22 +41,22 @@ public class HighScoreEntryState extends State { game.batch.draw(background, 0, 16); game.fontRenderer.setColor(Color.YELLOW); - game.fontRenderer.draw(game.batch, "high scores", (8 * 8) + 4, 25 * 8); + game.fontRenderer.draw(game.batch, "high scores", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 25 * Constants.TILE_SIZE); game.fontRenderer.setColor(Color.CHARTREUSE); - game.fontRenderer.draw(game.batch, "score name", (8 * 8) + 4, 22 * 8); + game.fontRenderer.draw(game.batch, "score name", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 22 * Constants.TILE_SIZE); game.fontRenderer.setColor(Color.BLUE); - game.fontRenderer.draw(game.batch, "" + score.score, (8 * 8) + 4, 18 * 9); + game.fontRenderer.draw(game.batch, "" + score.score, (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 18 * 9); for (int i = 0; i < 3; i++) { - game.fontRenderer.draw(game.batch, String.valueOf((i == currLetter && flash)? '_' : name[i]), (16 + i) * 8 + 4, 18 * 9); + game.fontRenderer.draw(game.batch, String.valueOf((i == currLetter && flash)? '_' : name[i]), (16 + i) * Constants.TILE_SIZE + Constants.TILE_SIZE/2, 18 * 9); } game.fontRenderer.setColor(Color.WHITE); Score[] scores = game.highScores.getHighScores(9); for (int i = 0; i < scores.length; i++) { Score score = scores[i]; - game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * 8) + 4, (17 - i) * 9); + game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (17 - i) * 9); } } diff --git a/core/src/com/me/pacman/state/HighScoresState.java b/core/src/com/me/pacman/state/HighScoresState.java index bd93087..f1efced 100644 --- a/core/src/com/me/pacman/state/HighScoresState.java +++ b/core/src/com/me/pacman/state/HighScoresState.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; +import com.me.pacman.Constants; import com.me.pacman.PacDude; import com.me.pacman.Score; @@ -28,16 +29,16 @@ public class HighScoresState extends State { game.batch.draw(background, 0, 16); game.fontRenderer.setColor(Color.YELLOW); - game.fontRenderer.draw(game.batch, "high scores", (8 * 8) + 4, 25 * 8); + game.fontRenderer.draw(game.batch, "high scores", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 25 * Constants.TILE_SIZE); game.fontRenderer.setColor(Color.CHARTREUSE); - game.fontRenderer.draw(game.batch, "score name", (8 * 8) + 4, 22 * 8); + game.fontRenderer.draw(game.batch, "score name", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 22 * Constants.TILE_SIZE); game.fontRenderer.setColor(Color.WHITE); Score[] scores = game.highScores.getHighScores(10); for (int i = 0; i < scores.length; i++) { Score score = scores[i]; - game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * 8) + 4, (18 - i) * 9); + game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (18 - i) * 9); } } diff --git a/core/src/com/me/pacman/state/LevelState.java b/core/src/com/me/pacman/state/LevelState.java index bcbf2c1..3164757 100644 --- a/core/src/com/me/pacman/state/LevelState.java +++ b/core/src/com/me/pacman/state/LevelState.java @@ -1,14 +1,12 @@ package com.me.pacman.state; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.me.pacman.Constants; import com.me.pacman.PacDude; import com.me.pacman.level.Level; public abstract class LevelState extends State { - public static final int LEVEL_OFFSET_X = 0; - public static final int LEVEL_OFFSET_Y = 16; - public Level level; public LevelState(PacDude game) { @@ -16,7 +14,11 @@ public abstract class LevelState extends State { } public void drawSprite(TextureRegion sprite, float x, float y) { - game.batch.draw(sprite, (int) (x * 8) + (LEVEL_OFFSET_X - 8), (int) (y * 8) + (LEVEL_OFFSET_Y - 8)); + game.batch.draw( + sprite, + (int) (x * Constants.TILE_SIZE) + (Constants.LEVEL_OFFSET_X - Constants.TILE_SIZE), + (int) (y * Constants.TILE_SIZE) + (Constants.LEVEL_OFFSET_Y - Constants.TILE_SIZE) + ); } } diff --git a/core/src/com/me/pacman/state/MenuState.java b/core/src/com/me/pacman/state/MenuState.java index a2087b2..b189990 100644 --- a/core/src/com/me/pacman/state/MenuState.java +++ b/core/src/com/me/pacman/state/MenuState.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.math.Vector2; +import com.me.pacman.Constants; import com.me.pacman.PacDude; import com.me.pacman.Sound; @@ -53,12 +54,12 @@ public class MenuState extends LevelState { game.fontRenderer.setColor(selectedOption == 0 ? Color.BLUE : Color.WHITE); - game.fontRenderer.draw(game.batch, "new", (12 * 8) + 4, (9 * 8) + 4); - game.fontRenderer.draw(game.batch, "game", 12 * 8, (8 * 8) + 4); + game.fontRenderer.draw(game.batch, "new", (12 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (9 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2); + game.fontRenderer.draw(game.batch, "game", 12 * Constants.TILE_SIZE, (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2); game.fontRenderer.setColor(selectedOption == 1 ? Color.BLUE : Color.WHITE); - game.fontRenderer.draw(game.batch, "high", (12 * 8), (6 * 8) + 4); - game.fontRenderer.draw(game.batch, "scores", (11 * 8), (5 * 8) + 4); + game.fontRenderer.draw(game.batch, "high", (12 * Constants.TILE_SIZE), (6 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2); + game.fontRenderer.draw(game.batch, "scores", (11 * Constants.TILE_SIZE), (5 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2); } @Override diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index d984fc0..c4333b6 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -5,9 +5,9 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; +import com.me.pacman.Constants; import com.me.pacman.PacDude; import com.me.pacman.Score; import com.me.pacman.Sound; @@ -22,8 +22,6 @@ import java.util.Random; public class PlayState extends LevelState { - public static final float FULL_SPEED = 9.375f; - public static final Vector2[] GHOST_SPAWN_POINTS = { new Vector2(14f, 19.5f), new Vector2(14f, 16.5f), @@ -269,16 +267,16 @@ public class PlayState extends LevelState { public void render() { game.fontRenderer.setColor(Color.WHITE); - game.fontRenderer.draw(game.batch, "1up", 3 * 8, 35 * 8); + game.fontRenderer.draw(game.batch, "1up", 3 * Constants.TILE_SIZE, 35 * Constants.TILE_SIZE); // Draw score // Determine x position based on score size. String s = score > 0 ? Integer.toString(score) : "00"; - game.fontRenderer.draw(game.batch, s, (7 - s.length()) * 8, 34 * 8); + game.fontRenderer.draw(game.batch, s, (7 - s.length()) * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE); // Draw high score - game.fontRenderer.draw(game.batch, "high score", 9 * 8, 35 * 8); - game.fontRenderer.draw(game.batch, score >= highScore? s : Integer.toString(highScore), 12 * 8, 34 * 8); + game.fontRenderer.draw(game.batch, "high score", 9 * Constants.TILE_SIZE, 35 * Constants.TILE_SIZE); + game.fontRenderer.draw(game.batch, score >= highScore? s : Integer.toString(highScore), 12 * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE); // Draw remaining lives for (int i = 0; i < lives; i++) { @@ -286,14 +284,14 @@ public class PlayState extends LevelState { } // Draw the level tiles - level.render(LEVEL_OFFSET_X, LEVEL_OFFSET_Y); + level.render(Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y); if (state == GameState.ROUND_WON) { // draw flashing level background - game.batch.draw((int) (stateTimer * 4) % 2 == 0? levelBackground : winBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y); + game.batch.draw((int) (stateTimer * 4) % 2 == 0? levelBackground : winBackground, Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y); return; } else { - game.batch.draw(levelBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y); + game.batch.draw(levelBackground, Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y); } if (state != GameState.GHOST_CAUGHT_POINTS_WAIT) { @@ -318,18 +316,18 @@ public class PlayState extends LevelState { if (paused) { game.fontRenderer.setColor(Color.YELLOW); - game.fontRenderer.draw(game.batch, "paused", 11 * 8, 15 * 8); + game.fontRenderer.draw(game.batch, "paused", 11 * Constants.TILE_SIZE, 15 * Constants.TILE_SIZE); } else { switch (state) { case PRE_NEW_GAME: case NEW_ROUND_WAIT: case START_ROUND_WAIT: game.fontRenderer.setColor(Color.YELLOW); - game.fontRenderer.draw(game.batch, "ready!", 11 * 8, 15 * 8); + game.fontRenderer.draw(game.batch, "ready!", 11 * Constants.TILE_SIZE, 15 * Constants.TILE_SIZE); break; case GAME_OVER: game.fontRenderer.setColor(Color.RED); - game.fontRenderer.draw(game.batch, "game over", (9 * 8) + 4, 15 * 8); + game.fontRenderer.draw(game.batch, "game over", (9 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 15 * Constants.TILE_SIZE); break; } } @@ -467,7 +465,7 @@ public class PlayState extends LevelState { return; } - if (PacDude.DEBUG) { + if (Constants.DEBUG) { // Fixed time step for debugger dt = 1/60f; } diff --git a/desktop/src/com/me/pacman/desktop/DesktopLauncher.java b/desktop/src/com/me/pacman/desktop/DesktopLauncher.java index acb5da2..299478c 100644 --- a/desktop/src/com/me/pacman/desktop/DesktopLauncher.java +++ b/desktop/src/com/me/pacman/desktop/DesktopLauncher.java @@ -2,14 +2,15 @@ package com.me.pacman.desktop; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import com.me.pacman.Constants; import com.me.pacman.PacDude; public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); - config.title = PacDude.TITLE + " - " + PacDude.VERSION; - config.width = PacDude.LEVEL_WIDTH * 2; - config.height = PacDude.LEVEL_HEIGHT * 2; + config.title = Constants.TITLE + " - " + Constants.VERSION; + config.width = Constants.GAME_WIDTH * 2; + config.height = Constants.GAME_HEIGHT * 2; config.resizable = true; new LwjglApplication(new PacDude(), config); }