Refactor some constants to Constants class
Use TILE_SIZE everywhere a magic 8 appears (in the context of a tile size)
This commit is contained in:
parent
fb6f77b72c
commit
b19daafc2b
32
core/src/com/me/pacman/Constants.java
Normal file
32
core/src/com/me/pacman/Constants.java
Normal file
@ -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;
|
||||||
|
}
|
@ -3,26 +3,19 @@ package com.me.pacman;
|
|||||||
import com.badlogic.gdx.Game;
|
import com.badlogic.gdx.Game;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
|
import com.badlogic.gdx.graphics.Camera;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||||
import com.me.pacman.state.HighScoresState;
|
|
||||||
import com.me.pacman.state.MenuState;
|
import com.me.pacman.state.MenuState;
|
||||||
import com.me.pacman.state.State;
|
import com.me.pacman.state.State;
|
||||||
|
|
||||||
public class PacDude extends Game {
|
public class PacDude extends Game {
|
||||||
|
|
||||||
public static final String TITLE = "Pac-Dude";
|
public Camera cam;
|
||||||
public static final String VERSION = "v0.1.0";
|
public Viewport viewport;
|
||||||
|
|
||||||
public static final boolean DEBUG = false;
|
|
||||||
|
|
||||||
public static final int LEVEL_WIDTH = 224;
|
|
||||||
public static final int LEVEL_HEIGHT = 288;
|
|
||||||
|
|
||||||
public HighScores highScores;
|
|
||||||
|
|
||||||
public Assets assets;
|
public Assets assets;
|
||||||
public Sound sound;
|
public Sound sound;
|
||||||
@ -30,19 +23,16 @@ public class PacDude extends Game {
|
|||||||
public SpriteBatch batch;
|
public SpriteBatch batch;
|
||||||
public FontRenderer fontRenderer;
|
public FontRenderer fontRenderer;
|
||||||
|
|
||||||
public OrthographicCamera cam;
|
public HighScores highScores;
|
||||||
public Viewport viewport;
|
|
||||||
|
|
||||||
private State nextState;
|
private State nextState;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
cam = new OrthographicCamera();
|
cam = new OrthographicCamera();
|
||||||
viewport = new FitViewport(LEVEL_WIDTH, LEVEL_HEIGHT, cam);
|
viewport = new FitViewport(Constants.GAME_WIDTH, Constants.GAME_HEIGHT, cam);
|
||||||
viewport.apply(true);
|
viewport.apply(true);
|
||||||
|
|
||||||
highScores = new HighScores();
|
|
||||||
|
|
||||||
assets = new Assets();
|
assets = new Assets();
|
||||||
assets.loadAssets();
|
assets.loadAssets();
|
||||||
sound = new Sound(this);
|
sound = new Sound(this);
|
||||||
@ -50,6 +40,8 @@ public class PacDude extends Game {
|
|||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
fontRenderer = new FontRenderer(assets.font);
|
fontRenderer = new FontRenderer(assets.font);
|
||||||
|
|
||||||
|
highScores = new HighScores();
|
||||||
|
|
||||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||||
setNextState(new MenuState(this));
|
setNextState(new MenuState(this));
|
||||||
}
|
}
|
||||||
@ -57,7 +49,6 @@ public class PacDude extends Game {
|
|||||||
@Override
|
@Override
|
||||||
public void render () {
|
public void render () {
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
if (nextState != null) {
|
if (nextState != null) {
|
||||||
Screen currScreen = getScreen();
|
Screen currScreen = getScreen();
|
||||||
if (currScreen != null) currScreen.dispose();
|
if (currScreen != null) currScreen.dispose();
|
||||||
@ -67,8 +58,8 @@ public class PacDude extends Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
if (DEBUG) {
|
if (Constants.DEBUG) {
|
||||||
fontRenderer.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond(), 19 * 8, 34 * 8);
|
fontRenderer.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond(), 19 * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE);
|
||||||
}
|
}
|
||||||
super.render();
|
super.render();
|
||||||
batch.end();
|
batch.end();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.me.pacman.entity;
|
package com.me.pacman.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
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.BlinkyChaseBehaviour;
|
||||||
import com.me.pacman.entity.ai.StaticTargetBehaviour;
|
import com.me.pacman.entity.ai.StaticTargetBehaviour;
|
||||||
import com.me.pacman.entity.ai.Target;
|
import com.me.pacman.entity.ai.Target;
|
||||||
@ -10,7 +10,7 @@ import com.me.pacman.state.PlayState;
|
|||||||
|
|
||||||
public class Blinky extends Ghost {
|
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) {
|
public Blinky(PlayState state, Vector2 pos, Direction direction) {
|
||||||
super(state, pos, direction, 0, new BlinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), false);
|
super(state, pos, direction, 0, new BlinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), false);
|
||||||
|
@ -2,7 +2,7 @@ package com.me.pacman.entity;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
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.entity.ai.Target;
|
||||||
import com.me.pacman.level.LevelTile;
|
import com.me.pacman.level.LevelTile;
|
||||||
import com.me.pacman.state.LevelState;
|
import com.me.pacman.state.LevelState;
|
||||||
@ -29,8 +29,8 @@ public abstract class Entity {
|
|||||||
|
|
||||||
state.drawSprite(texture, pos.x, pos.y);
|
state.drawSprite(texture, pos.x, pos.y);
|
||||||
|
|
||||||
if (PacDude.DEBUG) {
|
if (Constants.DEBUG) {
|
||||||
state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, LevelState.LEVEL_OFFSET_X, LevelState.LEVEL_OFFSET_Y);
|
state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.me.pacman.entity;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.entity.ai.Behaviour;
|
import com.me.pacman.entity.ai.Behaviour;
|
||||||
import com.me.pacman.entity.ai.ReturnToBase;
|
import com.me.pacman.entity.ai.ReturnToBase;
|
||||||
import com.me.pacman.entity.ai.Target;
|
import com.me.pacman.entity.ai.Target;
|
||||||
@ -16,7 +17,7 @@ import java.util.ArrayList;
|
|||||||
public class Ghost extends MovableEntity {
|
public class Ghost extends MovableEntity {
|
||||||
|
|
||||||
public static final float EYES_SPEED = 15f;
|
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 };
|
public static final Direction[] GHOST_ORDER = { Direction.UP, Direction.LEFT, Direction.DOWN, Direction.RIGHT };
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.me.pacman.entity;
|
package com.me.pacman.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
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.InkyChaseBehaviour;
|
||||||
import com.me.pacman.entity.ai.StaticTargetBehaviour;
|
import com.me.pacman.entity.ai.StaticTargetBehaviour;
|
||||||
import com.me.pacman.entity.ai.Target;
|
import com.me.pacman.entity.ai.Target;
|
||||||
@ -9,7 +9,7 @@ import com.me.pacman.state.PlayState;
|
|||||||
|
|
||||||
public class Inky extends Ghost {
|
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;
|
public static final int DOT_LIMIT = 30;
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.me.pacman.entity;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.level.LevelTile;
|
import com.me.pacman.level.LevelTile;
|
||||||
import com.me.pacman.level.Modifiers;
|
import com.me.pacman.level.Modifiers;
|
||||||
import com.me.pacman.state.PlayState;
|
import com.me.pacman.state.PlayState;
|
||||||
@ -22,7 +23,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, 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;
|
this.state = state;
|
||||||
sprite = state.getGame().assets.pacman;
|
sprite = state.getGame().assets.pacman;
|
||||||
death = state.getGame().assets.deathAnimation;
|
death = state.getGame().assets.deathAnimation;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.me.pacman.entity;
|
package com.me.pacman.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
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.PinkyChaseBehaviour;
|
||||||
import com.me.pacman.entity.ai.StaticTargetBehaviour;
|
import com.me.pacman.entity.ai.StaticTargetBehaviour;
|
||||||
import com.me.pacman.entity.ai.Target;
|
import com.me.pacman.entity.ai.Target;
|
||||||
@ -9,7 +9,7 @@ import com.me.pacman.state.PlayState;
|
|||||||
|
|
||||||
public class Pinky extends Ghost {
|
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) {
|
public Pinky(PlayState state, Vector2 pos, Direction direction) {
|
||||||
super(state, pos, direction, 1, new PinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), true);
|
super(state, pos, direction, 1, new PinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), true);
|
||||||
|
@ -2,6 +2,7 @@ package com.me.pacman.level;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
|
|
||||||
public class Level {
|
public class Level {
|
||||||
@ -90,7 +91,7 @@ public class Level {
|
|||||||
default:
|
default:
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.me.pacman.level;
|
package com.me.pacman.level;
|
||||||
|
|
||||||
import com.me.pacman.state.PlayState;
|
import com.me.pacman.Constants;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -35,23 +35,23 @@ public class Modifiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float getPacmanSpeed(int round) {
|
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) {
|
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) {
|
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) {
|
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) {
|
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) {
|
public static int getElroy1DotsLeft(int round) {
|
||||||
@ -59,7 +59,7 @@ public class Modifiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float getElroy1Speed(int round) {
|
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) {
|
public static int getElroy2DotsLeft(int round) {
|
||||||
@ -67,7 +67,7 @@ public class Modifiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float getElroy2Speed(int round) {
|
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) {
|
public static int getForceLeaveSeconds(int round) {
|
||||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.Input;
|
|||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
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.me.pacman.Constants;
|
||||||
import com.me.pacman.FontRenderer;
|
import com.me.pacman.FontRenderer;
|
||||||
import com.me.pacman.Score;
|
import com.me.pacman.Score;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
@ -40,22 +41,22 @@ public class HighScoreEntryState extends State {
|
|||||||
game.batch.draw(background, 0, 16);
|
game.batch.draw(background, 0, 16);
|
||||||
|
|
||||||
game.fontRenderer.setColor(Color.YELLOW);
|
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.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.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++) {
|
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);
|
game.fontRenderer.setColor(Color.WHITE);
|
||||||
Score[] scores = game.highScores.getHighScores(9);
|
Score[] scores = game.highScores.getHighScores(9);
|
||||||
for (int i = 0; i < scores.length; i++) {
|
for (int i = 0; i < scores.length; i++) {
|
||||||
Score score = scores[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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.Input;
|
|||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
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.me.pacman.Constants;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
import com.me.pacman.Score;
|
import com.me.pacman.Score;
|
||||||
|
|
||||||
@ -28,16 +29,16 @@ public class HighScoresState extends State {
|
|||||||
game.batch.draw(background, 0, 16);
|
game.batch.draw(background, 0, 16);
|
||||||
|
|
||||||
game.fontRenderer.setColor(Color.YELLOW);
|
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.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);
|
game.fontRenderer.setColor(Color.WHITE);
|
||||||
Score[] scores = game.highScores.getHighScores(10);
|
Score[] scores = game.highScores.getHighScores(10);
|
||||||
for (int i = 0; i < scores.length; i++) {
|
for (int i = 0; i < scores.length; i++) {
|
||||||
Score score = scores[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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package com.me.pacman.state;
|
package com.me.pacman.state;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
import com.me.pacman.level.Level;
|
import com.me.pacman.level.Level;
|
||||||
|
|
||||||
public abstract class LevelState extends State {
|
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 Level level;
|
||||||
|
|
||||||
public LevelState(PacDude game) {
|
public LevelState(PacDude game) {
|
||||||
@ -16,7 +14,11 @@ public abstract class LevelState extends State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawSprite(TextureRegion sprite, float x, float y) {
|
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)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.InputAdapter;
|
|||||||
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.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
import com.me.pacman.Sound;
|
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.setColor(selectedOption == 0 ? Color.BLUE : Color.WHITE);
|
||||||
game.fontRenderer.draw(game.batch, "new", (12 * 8) + 4, (9 * 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 * 8, (8 * 8) + 4);
|
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.setColor(selectedOption == 1 ? Color.BLUE : Color.WHITE);
|
||||||
game.fontRenderer.draw(game.batch, "high", (12 * 8), (6 * 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 * 8), (5 * 8) + 4);
|
game.fontRenderer.draw(game.batch, "scores", (11 * Constants.TILE_SIZE), (5 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,9 +5,9 @@ import com.badlogic.gdx.Input;
|
|||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
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.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
import com.me.pacman.Score;
|
import com.me.pacman.Score;
|
||||||
import com.me.pacman.Sound;
|
import com.me.pacman.Sound;
|
||||||
@ -22,8 +22,6 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class PlayState extends LevelState {
|
public class PlayState extends LevelState {
|
||||||
|
|
||||||
public static final float FULL_SPEED = 9.375f;
|
|
||||||
|
|
||||||
public static final Vector2[] GHOST_SPAWN_POINTS = {
|
public static final Vector2[] GHOST_SPAWN_POINTS = {
|
||||||
new Vector2(14f, 19.5f),
|
new Vector2(14f, 19.5f),
|
||||||
new Vector2(14f, 16.5f),
|
new Vector2(14f, 16.5f),
|
||||||
@ -269,16 +267,16 @@ public class PlayState extends LevelState {
|
|||||||
public void render() {
|
public void render() {
|
||||||
|
|
||||||
game.fontRenderer.setColor(Color.WHITE);
|
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
|
// Draw score
|
||||||
// Determine x position based on score size.
|
// Determine x position based on score size.
|
||||||
String s = score > 0 ? Integer.toString(score) : "00";
|
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
|
// Draw high score
|
||||||
game.fontRenderer.draw(game.batch, "high score", 9 * 8, 35 * 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 * 8, 34 * 8);
|
game.fontRenderer.draw(game.batch, score >= highScore? s : Integer.toString(highScore), 12 * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE);
|
||||||
|
|
||||||
// Draw remaining lives
|
// Draw remaining lives
|
||||||
for (int i = 0; i < lives; i++) {
|
for (int i = 0; i < lives; i++) {
|
||||||
@ -286,14 +284,14 @@ public class PlayState extends LevelState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw the level tiles
|
// 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) {
|
if (state == GameState.ROUND_WON) {
|
||||||
// draw flashing level background
|
// 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;
|
return;
|
||||||
} else {
|
} 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) {
|
if (state != GameState.GHOST_CAUGHT_POINTS_WAIT) {
|
||||||
@ -318,18 +316,18 @@ public class PlayState extends LevelState {
|
|||||||
|
|
||||||
if (paused) {
|
if (paused) {
|
||||||
game.fontRenderer.setColor(Color.YELLOW);
|
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 {
|
} else {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case PRE_NEW_GAME:
|
case PRE_NEW_GAME:
|
||||||
case NEW_ROUND_WAIT:
|
case NEW_ROUND_WAIT:
|
||||||
case START_ROUND_WAIT:
|
case START_ROUND_WAIT:
|
||||||
game.fontRenderer.setColor(Color.YELLOW);
|
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;
|
break;
|
||||||
case GAME_OVER:
|
case GAME_OVER:
|
||||||
game.fontRenderer.setColor(Color.RED);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,7 +465,7 @@ public class PlayState extends LevelState {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PacDude.DEBUG) {
|
if (Constants.DEBUG) {
|
||||||
// Fixed time step for debugger
|
// Fixed time step for debugger
|
||||||
dt = 1/60f;
|
dt = 1/60f;
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,15 @@ package com.me.pacman.desktop;
|
|||||||
|
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||||
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
|
|
||||||
public class DesktopLauncher {
|
public class DesktopLauncher {
|
||||||
public static void main (String[] arg) {
|
public static void main (String[] arg) {
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||||
config.title = PacDude.TITLE + " - " + PacDude.VERSION;
|
config.title = Constants.TITLE + " - " + Constants.VERSION;
|
||||||
config.width = PacDude.LEVEL_WIDTH * 2;
|
config.width = Constants.GAME_WIDTH * 2;
|
||||||
config.height = PacDude.LEVEL_HEIGHT * 2;
|
config.height = Constants.GAME_HEIGHT * 2;
|
||||||
config.resizable = true;
|
config.resizable = true;
|
||||||
new LwjglApplication(new PacDude(), config);
|
new LwjglApplication(new PacDude(), config);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user