Compare commits
No commits in common. "dev" and "highscores" have entirely different histories.
dev
...
highscores
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.3 KiB |
@ -1,44 +0,0 @@
|
||||
package com.me.pacman;
|
||||
|
||||
import com.me.pacman.entity.Direction;
|
||||
|
||||
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;
|
||||
|
||||
// Ghost spawn directions, should remain constant assuming they always exit the ghost house
|
||||
// from the top
|
||||
public static final Direction[] GHOST_SPAWN_DIRS = {
|
||||
Direction.LEFT, // Blinky
|
||||
Direction.UP, // Pinky
|
||||
Direction.DOWN, // Inky
|
||||
Direction.DOWN, // Clyde
|
||||
};
|
||||
|
||||
}
|
@ -9,11 +9,10 @@ public class FontRenderer {
|
||||
|
||||
public static final char[] CHARS = "abcdefghijklmnopqrstuvwxyz0123456789!?()[]<>$&*:#^~-_/\\".toCharArray();
|
||||
public static final int[] CHAR_TO_INDEX = new int[256];
|
||||
|
||||
private final TextureRegion[][] sprites;
|
||||
|
||||
private Color color = Color.WHITE;
|
||||
|
||||
private TextureRegion[][] sprites;
|
||||
|
||||
public FontRenderer(TextureRegion[][] sprites) {
|
||||
this.sprites = sprites;
|
||||
}
|
||||
@ -32,7 +31,8 @@ public class FontRenderer {
|
||||
continue;
|
||||
}
|
||||
int i = CHAR_TO_INDEX[c];
|
||||
batch.draw(sprites[i / 8][i % 8], x, y);
|
||||
TextureRegion region = sprites[i / 8][i % 8];
|
||||
batch.draw(region, x, y);
|
||||
x += 8;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
*
|
||||
* Scores are saved in a simple text file
|
||||
*/
|
||||
public class HighScoreManager {
|
||||
public class HighScores {
|
||||
|
||||
public static final String FILE = "scores.dat";
|
||||
|
||||
@ -17,7 +17,7 @@ public class HighScoreManager {
|
||||
|
||||
private Array<Score> scores = new Array<>(10);
|
||||
|
||||
public HighScoreManager() {
|
||||
public HighScores() {
|
||||
file = Gdx.files.local(FILE);
|
||||
loadScores();
|
||||
}
|
@ -3,45 +3,53 @@ 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 Camera cam;
|
||||
public Viewport viewport;
|
||||
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 Assets assets;
|
||||
public SoundManager sound;
|
||||
public Sound sound;
|
||||
|
||||
public SpriteBatch batch;
|
||||
public FontRenderer fontRenderer;
|
||||
|
||||
public HighScoreManager highScores;
|
||||
public OrthographicCamera cam;
|
||||
public Viewport viewport;
|
||||
|
||||
private State nextState;
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
cam = new OrthographicCamera();
|
||||
viewport = new FitViewport(Constants.GAME_WIDTH, Constants.GAME_HEIGHT, cam);
|
||||
viewport = new FitViewport(LEVEL_WIDTH, LEVEL_HEIGHT, cam);
|
||||
viewport.apply(true);
|
||||
|
||||
highScores = new HighScores();
|
||||
|
||||
assets = new Assets();
|
||||
assets.loadAssets();
|
||||
sound = new SoundManager(this);
|
||||
sound = new Sound(this);
|
||||
|
||||
batch = new SpriteBatch();
|
||||
fontRenderer = new FontRenderer(assets.font);
|
||||
|
||||
highScores = new HighScoreManager();
|
||||
|
||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||
setNextState(new MenuState(this));
|
||||
}
|
||||
@ -49,6 +57,7 @@ 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();
|
||||
@ -58,8 +67,8 @@ public class PacDude extends Game {
|
||||
}
|
||||
|
||||
batch.begin();
|
||||
if (Constants.DEBUG) {
|
||||
fontRenderer.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond(), 19 * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE);
|
||||
if (DEBUG) {
|
||||
fontRenderer.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond(), 19 * 8, 34 * 8);
|
||||
}
|
||||
super.render();
|
||||
batch.end();
|
||||
|
@ -2,7 +2,7 @@ package com.me.pacman;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SoundManager {
|
||||
public class Sound {
|
||||
|
||||
public enum Effect {
|
||||
BEGINNING,
|
||||
@ -28,7 +28,7 @@ public class SoundManager {
|
||||
private long[] playing;
|
||||
private long[] looping;
|
||||
|
||||
public SoundManager(PacDude game) {
|
||||
public Sound(PacDude game) {
|
||||
this.game = game;
|
||||
this.playing = new long[Effect.values().length];
|
||||
this.looping = new long[Effect.values().length];
|
@ -1,16 +1,16 @@
|
||||
package com.me.pacman.entity;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.me.pacman.Constants;
|
||||
import com.me.pacman.PacDude;
|
||||
import com.me.pacman.entity.ai.BlinkyChaseBehaviour;
|
||||
import com.me.pacman.entity.ai.StaticTargetBehaviour;
|
||||
import com.me.pacman.entity.ai.Target;
|
||||
import com.me.pacman.RoundModifiers;
|
||||
import com.me.pacman.level.Modifiers;
|
||||
import com.me.pacman.state.PlayState;
|
||||
|
||||
public class Blinky extends Ghost {
|
||||
|
||||
public static final Target SCATTER_TARGET = new Target((Constants.GAME_WIDTH / 8) - 2, Constants.GAME_HEIGHT / 8);
|
||||
public static final Target SCATTER_TARGET = new Target((PacDude.LEVEL_WIDTH / 8) - 2, PacDude.LEVEL_HEIGHT / 8);
|
||||
|
||||
public Blinky(PlayState state, Vector2 pos, Direction direction) {
|
||||
super(state, pos, direction, 0, new BlinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), false);
|
||||
@ -20,10 +20,10 @@ public class Blinky extends Ghost {
|
||||
protected float getNormalSpeed() {
|
||||
int round = state.round;
|
||||
if (!state.hasDied || !state.ghosts[3].inHouse) {
|
||||
if (state.level.getPelletsRemaining() <= RoundModifiers.getElroy2DotsLeft(round)) {
|
||||
return RoundModifiers.getElroy2Speed(round);
|
||||
} else if (state.level.getPelletsRemaining() <= RoundModifiers.getElroy1DotsLeft(round)) {
|
||||
return RoundModifiers.getElroy1Speed(round);
|
||||
if (state.pelletsRemaining <= Modifiers.getElroy2DotsLeft(round)) {
|
||||
return Modifiers.getElroy2Speed(round);
|
||||
} else if (state.pelletsRemaining <= Modifiers.getElroy1DotsLeft(round)) {
|
||||
return Modifiers.getElroy1Speed(round);
|
||||
}
|
||||
}
|
||||
return super.getNormalSpeed();
|
||||
|
@ -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.Constants;
|
||||
import com.me.pacman.PacDude;
|
||||
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 (Constants.DEBUG) {
|
||||
state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y);
|
||||
if (PacDude.DEBUG) {
|
||||
state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, LevelState.LEVEL_OFFSET_X, LevelState.LEVEL_OFFSET_Y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,14 +2,13 @@ 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;
|
||||
import com.me.pacman.entity.path.EnterGhostHousePath;
|
||||
import com.me.pacman.entity.path.ExitGhostHousePath;
|
||||
import com.me.pacman.level.LevelTile;
|
||||
import com.me.pacman.RoundModifiers;
|
||||
import com.me.pacman.level.Modifiers;
|
||||
import com.me.pacman.state.PlayState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -17,7 +16,7 @@ import java.util.ArrayList;
|
||||
public class Ghost extends MovableEntity {
|
||||
|
||||
public static final float EYES_SPEED = 15f;
|
||||
public static final float HOUSE_SPEED = Constants.FULL_SPEED * 0.5f;
|
||||
public static final float HOUSE_SPEED = PlayState.FULL_SPEED * 0.5f;
|
||||
|
||||
public static final Direction[] GHOST_ORDER = { Direction.UP, Direction.LEFT, Direction.DOWN, Direction.RIGHT };
|
||||
|
||||
@ -44,7 +43,7 @@ public class Ghost extends MovableEntity {
|
||||
|
||||
public Ghost(PlayState state, Vector2 pos, Direction direction, int spriteIndex,
|
||||
Behaviour chaseBehaviour, Behaviour scatterBehaviour, boolean inHouse) {
|
||||
super(state, pos.x, pos.y, RoundModifiers.getGhostSpeed(0), true, direction, 0.1f);
|
||||
super(state, pos.x, pos.y, Modifiers.getGhostSpeed(0), true, direction, 0.1f);
|
||||
this.state = state;
|
||||
this.spriteIndex = spriteIndex;
|
||||
this.chaseBehaviour = chaseBehaviour;
|
||||
@ -84,7 +83,7 @@ public class Ghost extends MovableEntity {
|
||||
}
|
||||
|
||||
protected float getNormalSpeed() {
|
||||
return RoundModifiers.getGhostSpeed(state.round);
|
||||
return Modifiers.getGhostSpeed(state.round);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,9 +94,9 @@ public class Ghost extends MovableEntity {
|
||||
|
||||
LevelTile currentTile = state.level.getTile(pos);
|
||||
if (currentTile == null || currentTile == LevelTile.TUNNEL) {
|
||||
speed = RoundModifiers.getGhostTunnelSpeed(state.round);
|
||||
speed = Modifiers.getGhostTunnelSpeed(state.round);
|
||||
} else if (currentBehaviour instanceof FrightenedBehaviour) {
|
||||
speed = RoundModifiers.getGhostFrightSpeed(state.round);
|
||||
speed = Modifiers.getGhostFrightSpeed(state.round);
|
||||
} else if (currentBehaviour instanceof ReturnToBase) {
|
||||
speed = EYES_SPEED;
|
||||
} else if (inHouse) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.me.pacman.entity;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.me.pacman.Constants;
|
||||
import com.me.pacman.PacDude;
|
||||
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(Constants.GAME_WIDTH / 8, -1);
|
||||
public static final Target SCATTER_TARGET = new Target(PacDude.LEVEL_WIDTH / 8, -1);
|
||||
|
||||
public static final int DOT_LIMIT = 30;
|
||||
|
||||
|
@ -2,9 +2,8 @@ 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.RoundModifiers;
|
||||
import com.me.pacman.level.Modifiers;
|
||||
import com.me.pacman.state.PlayState;
|
||||
|
||||
public class Pacman extends MovableEntity {
|
||||
@ -23,7 +22,7 @@ public class Pacman extends MovableEntity {
|
||||
public int deathFrame = 0;
|
||||
|
||||
public Pacman(PlayState state, boolean moving) {
|
||||
super(state, HOME.x, HOME.y, Constants.FULL_SPEED * 0.8f, moving, Direction.LEFT, 0.3f);
|
||||
super(state, HOME.x, HOME.y, PlayState.FULL_SPEED * 0.8f, moving, Direction.LEFT, 0.3f);
|
||||
this.state = state;
|
||||
sprite = state.getGame().assets.pacman;
|
||||
death = state.getGame().assets.deathAnimation;
|
||||
@ -50,9 +49,9 @@ public class Pacman extends MovableEntity {
|
||||
}
|
||||
|
||||
if (state.frightTimer > 0) {
|
||||
speed = RoundModifiers.getPacmanFrightSpeed(state.round);
|
||||
speed = Modifiers.getPacmanFrightSpeed(state.round);
|
||||
} else {
|
||||
speed = RoundModifiers.getPacmanSpeed(state.round);
|
||||
speed = Modifiers.getPacmanSpeed(state.round);
|
||||
}
|
||||
|
||||
super.update(dt);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.me.pacman.entity;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.me.pacman.Constants;
|
||||
import com.me.pacman.PacDude;
|
||||
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, Constants.GAME_HEIGHT / 8);
|
||||
public static final Target SCATTER_TARGET = new Target(2, PacDude.LEVEL_HEIGHT / 8);
|
||||
|
||||
public Pinky(PlayState state, Vector2 pos, Direction direction) {
|
||||
super(state, pos, direction, 1, new PinkyChaseBehaviour(state), new StaticTargetBehaviour(state, SCATTER_TARGET), true);
|
||||
|
@ -2,18 +2,10 @@ 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 {
|
||||
|
||||
public static final Vector2[] GHOST_SPAWN_POINTS = {
|
||||
new Vector2(14f, 19.5f),
|
||||
new Vector2(14f, 16.5f),
|
||||
new Vector2(12f, 16.5f),
|
||||
new Vector2(16f, 16.5f),
|
||||
};
|
||||
|
||||
private PacDude game;
|
||||
|
||||
private TextureRegion pellet;
|
||||
@ -23,12 +15,9 @@ public class Level {
|
||||
// Grid of tiles, [rows][columns]
|
||||
public LevelTile[][] tiles;
|
||||
|
||||
// Level width and height in tiles
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
private int pellets;
|
||||
private int pelletsRemaining;
|
||||
|
||||
public Level(PacDude game, String level) {
|
||||
this.game = game;
|
||||
@ -42,20 +31,6 @@ public class Level {
|
||||
|
||||
height = tiles.length;
|
||||
width = tiles[0].length;
|
||||
|
||||
pellets = pelletsRemaining = getTileCount(LevelTile.PELLET) + getTileCount(LevelTile.POWER_PELLET);
|
||||
}
|
||||
|
||||
public int getPelletCount() {
|
||||
return pellets;
|
||||
}
|
||||
|
||||
public int getPelletsRemaining() {
|
||||
return pelletsRemaining;
|
||||
}
|
||||
|
||||
public int getPelletsEaten() {
|
||||
return pellets - pelletsRemaining;
|
||||
}
|
||||
|
||||
public LevelTile getTile(int x, int y) {
|
||||
@ -71,10 +46,6 @@ public class Level {
|
||||
}
|
||||
|
||||
public void setTile(int x, int y, LevelTile tile) {
|
||||
LevelTile exist = tiles[y][x];
|
||||
if (exist.isPellet() && !tile.isPellet()) {
|
||||
pelletsRemaining--;
|
||||
}
|
||||
tiles[y][x] = tile;
|
||||
}
|
||||
|
||||
@ -119,7 +90,7 @@ public class Level {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
game.batch.draw(sprite, (tileX * Constants.TILE_SIZE) + offsetX, (tileY * Constants.TILE_SIZE) + offsetY);
|
||||
game.batch.draw(sprite, (tileX * 8) + offsetX, (tileY * 8) + offsetY);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,22 +13,7 @@ public enum LevelTile {
|
||||
;
|
||||
|
||||
public boolean isPassable() {
|
||||
switch (this) {
|
||||
case WALL:
|
||||
case GHOST_CHAMBER:
|
||||
case GHOST_GATE:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPellet() {
|
||||
switch (this) {
|
||||
case PELLET:
|
||||
case POWER_PELLET:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return this != WALL && this != GHOST_CHAMBER && this != GHOST_GATE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.me.pacman;
|
||||
package com.me.pacman.level;
|
||||
|
||||
import com.me.pacman.state.PlayState;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class RoundModifiers {
|
||||
public class Modifiers {
|
||||
|
||||
private static final RoundModifiers[] ROUND_MODIFIERS;
|
||||
private static final Modifiers[] ROUND_MODIFIERS;
|
||||
|
||||
private float frightTime;
|
||||
|
||||
@ -33,23 +35,23 @@ public class RoundModifiers {
|
||||
}
|
||||
|
||||
public static float getPacmanSpeed(int round) {
|
||||
return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanSpeed;
|
||||
return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanSpeed;
|
||||
}
|
||||
|
||||
public static float getPacmanFrightSpeed(int round) {
|
||||
return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanFrightSpeed;
|
||||
return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].pacmanFrightSpeed;
|
||||
}
|
||||
|
||||
public static float getGhostSpeed(int round) {
|
||||
return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostSpeed;
|
||||
return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostSpeed;
|
||||
}
|
||||
|
||||
public static float getGhostFrightSpeed(int round) {
|
||||
return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostFrightSpeed;
|
||||
return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostFrightSpeed;
|
||||
}
|
||||
|
||||
public static float getGhostTunnelSpeed(int round) {
|
||||
return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostTunnelSpeed;
|
||||
return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].ghostTunnelSpeed;
|
||||
}
|
||||
|
||||
public static int getElroy1DotsLeft(int round) {
|
||||
@ -57,7 +59,7 @@ public class RoundModifiers {
|
||||
}
|
||||
|
||||
public static float getElroy1Speed(int round) {
|
||||
return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy1Speed;
|
||||
return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy1Speed;
|
||||
}
|
||||
|
||||
public static int getElroy2DotsLeft(int round) {
|
||||
@ -65,7 +67,7 @@ public class RoundModifiers {
|
||||
}
|
||||
|
||||
public static float getElroy2Speed(int round) {
|
||||
return Constants.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy2Speed;
|
||||
return PlayState.FULL_SPEED * ROUND_MODIFIERS[cap(round)].elroy2Speed;
|
||||
}
|
||||
|
||||
public static int getForceLeaveSeconds(int round) {
|
||||
@ -76,8 +78,8 @@ public class RoundModifiers {
|
||||
return ROUND_MODIFIERS[cap(round)].scatterChaseSwitchTimings[scatterChaseTransition];
|
||||
}
|
||||
|
||||
public RoundModifiers clone() {
|
||||
RoundModifiers mod = new RoundModifiers();
|
||||
public Modifiers clone() {
|
||||
Modifiers mod = new Modifiers();
|
||||
mod.frightTime = frightTime;
|
||||
mod.pacmanSpeed = pacmanSpeed;
|
||||
mod.pacmanFrightSpeed = pacmanFrightSpeed;
|
||||
@ -98,11 +100,11 @@ public class RoundModifiers {
|
||||
}
|
||||
|
||||
static {
|
||||
ROUND_MODIFIERS = new RoundModifiers[21];
|
||||
ROUND_MODIFIERS = new Modifiers[21];
|
||||
int round = 0;
|
||||
|
||||
// Round 1
|
||||
RoundModifiers mod = new RoundModifiers();
|
||||
Modifiers mod = new Modifiers();
|
||||
mod.frightTime = 6f;
|
||||
mod.pacmanSpeed = 0.8f;
|
||||
mod.pacmanFrightSpeed = 0.9f;
|
@ -5,40 +5,28 @@ 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.math.Vector2;
|
||||
import com.me.pacman.Constants;
|
||||
import com.me.pacman.FontRenderer;
|
||||
import com.me.pacman.Score;
|
||||
import com.me.pacman.PacDude;
|
||||
import com.me.pacman.entity.Direction;
|
||||
|
||||
import static com.me.pacman.state.HighScoresState.BUTTON;
|
||||
|
||||
public class HighScoreEntryState extends State {
|
||||
|
||||
private Texture background;
|
||||
private Score score;
|
||||
|
||||
private final int position;
|
||||
private int currLetter;
|
||||
private char[] name;
|
||||
|
||||
private boolean flash;
|
||||
private float elapsed;
|
||||
|
||||
private boolean buttonPressed;
|
||||
|
||||
private Direction nextDirection;
|
||||
|
||||
public HighScoreEntryState(PacDude game, Score score, int position) {
|
||||
public HighScoreEntryState(PacDude game, Score score) {
|
||||
super(game);
|
||||
this.position = position;
|
||||
this.score = score;
|
||||
this.currLetter = 0;
|
||||
this.flash = false;
|
||||
this.elapsed = 0f;
|
||||
this.name = score.scorer.toCharArray();
|
||||
this.nextDirection = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,31 +40,24 @@ public class HighScoreEntryState extends State {
|
||||
game.batch.draw(background, 0, 16);
|
||||
|
||||
game.fontRenderer.setColor(Color.YELLOW);
|
||||
game.fontRenderer.draw(game.batch, "high scores", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 25 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "high scores", (8 * 8) + 4, 25 * 8);
|
||||
|
||||
game.fontRenderer.setColor(Color.CHARTREUSE);
|
||||
game.fontRenderer.draw(game.batch, "score name", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 22 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "score name", (8 * 8) + 4, 23 * 8);
|
||||
|
||||
Score[] scores = game.highScores.getHighScores(9);
|
||||
for (int n = 0; n < scores.length + 1; n++) {
|
||||
int y = (18 - n) * 9;
|
||||
|
||||
if (n == position) {
|
||||
game.fontRenderer.setColor(Color.BLUE);
|
||||
game.fontRenderer.draw(game.batch, "" + score.score, (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, y);
|
||||
|
||||
game.fontRenderer.draw(game.batch, "" + score.score, (8 * 8) + 4, 18 * 9);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
game.fontRenderer.draw(game.batch, String.valueOf((i == currLetter && flash)? '_' : name[i]), (16 + i) * Constants.TILE_SIZE + Constants.TILE_SIZE/2, y);
|
||||
}
|
||||
} else {
|
||||
Score score = scores[n > position? n - 1 : n];
|
||||
game.fontRenderer.setColor(Color.WHITE);
|
||||
game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, y);
|
||||
}
|
||||
game.fontRenderer.draw(game.batch, String.valueOf((i == currLetter && flash)? '_' : name[i]), (16 + i) * 8 + 4, 18 * 9);
|
||||
}
|
||||
|
||||
game.fontRenderer.setColor(buttonPressed ? Color.BLUE : Color.WHITE);
|
||||
game.fontRenderer.draw(game.batch, "save", 12 * Constants.TILE_SIZE, 5 * Constants.TILE_SIZE - 1);
|
||||
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, (16 - i) * 9);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,42 +67,6 @@ public class HighScoreEntryState extends State {
|
||||
elapsed = 0f;
|
||||
flash = !flash;
|
||||
}
|
||||
|
||||
if (nextDirection != null) {
|
||||
switch (nextDirection) {
|
||||
case UP:
|
||||
int nextIndex = FontRenderer.CHAR_TO_INDEX[name[currLetter]] - 1;
|
||||
if (nextIndex < 0) {
|
||||
nextIndex = 25;
|
||||
}
|
||||
flash = false;
|
||||
name[currLetter] = FontRenderer.CHARS[nextIndex];
|
||||
break;
|
||||
case DOWN:
|
||||
nextIndex = FontRenderer.CHAR_TO_INDEX[name[currLetter]] + 1;
|
||||
if (nextIndex > 25) {
|
||||
nextIndex = 0;
|
||||
}
|
||||
flash = false;
|
||||
name[currLetter] = FontRenderer.CHARS[nextIndex];
|
||||
break;
|
||||
case LEFT:
|
||||
currLetter--;
|
||||
if (currLetter < 0) {
|
||||
currLetter = 2;
|
||||
}
|
||||
flash = true;
|
||||
break;
|
||||
case RIGHT:
|
||||
currLetter++;
|
||||
if (currLetter > 2) {
|
||||
currLetter = 0;
|
||||
}
|
||||
flash = true;
|
||||
break;
|
||||
}
|
||||
nextDirection = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,93 +74,51 @@ public class HighScoreEntryState extends State {
|
||||
Gdx.input.setInputProcessor(null);
|
||||
}
|
||||
|
||||
private void saveScoreAndReturn() {
|
||||
score.scorer = String.valueOf(name);
|
||||
game.highScores.addScore(score);
|
||||
game.setNextState(new HighScoresState(game));
|
||||
}
|
||||
|
||||
private final class Controller extends InputAdapter {
|
||||
|
||||
int downX;
|
||||
int downY;
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
switch(keycode) {
|
||||
case Input.Keys.DOWN:
|
||||
nextDirection = Direction.DOWN;
|
||||
int nextIndex = FontRenderer.CHAR_TO_INDEX[name[currLetter]] - 1;
|
||||
if (nextIndex < 0) {
|
||||
nextIndex = 25;
|
||||
}
|
||||
flash = false;
|
||||
name[currLetter] = FontRenderer.CHARS[nextIndex];
|
||||
break;
|
||||
case Input.Keys.UP:
|
||||
nextDirection = Direction.UP;
|
||||
nextIndex = FontRenderer.CHAR_TO_INDEX[name[currLetter]] + 1;
|
||||
if (nextIndex > 25) {
|
||||
nextIndex = 0;
|
||||
}
|
||||
flash = false;
|
||||
name[currLetter] = FontRenderer.CHARS[nextIndex];
|
||||
break;
|
||||
case Input.Keys.RIGHT:
|
||||
nextDirection = Direction.RIGHT;
|
||||
currLetter++;
|
||||
if (currLetter > 2) {
|
||||
currLetter = 0;
|
||||
}
|
||||
flash = true;
|
||||
break;
|
||||
case Input.Keys.LEFT:
|
||||
nextDirection = Direction.LEFT;
|
||||
currLetter--;
|
||||
if (currLetter < 0) {
|
||||
currLetter = 2;
|
||||
}
|
||||
flash = true;
|
||||
break;
|
||||
case Input.Keys.ENTER:
|
||||
case Input.Keys.BACK:
|
||||
case Input.Keys.ESCAPE:
|
||||
saveScoreAndReturn();
|
||||
score.scorer = String.valueOf(name);
|
||||
game.highScores.addScore(score);
|
||||
game.setNextState(new HighScoresState(game));
|
||||
break;
|
||||
}
|
||||
elapsed = 0f;
|
||||
return super.keyDown(keycode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||
if (BUTTON.contains(coords)) {
|
||||
buttonPressed = true;
|
||||
}
|
||||
downX = screenX;
|
||||
downY = screenY;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||
if (buttonPressed) {
|
||||
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||
if (BUTTON.contains(coords)) {
|
||||
saveScoreAndReturn();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
buttonPressed = false;
|
||||
|
||||
|
||||
int relaX = screenX - downX;
|
||||
int relaY = screenY - downY;
|
||||
|
||||
if (Math.abs(relaX) < 50 && Math.abs(relaY) < 50) {
|
||||
// didn't move enough to consider a swipe
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Math.abs(relaX) > Math.abs(relaY)) {
|
||||
// x > y, so moving left-right
|
||||
if (relaX > 0) {
|
||||
nextDirection = Direction.RIGHT;
|
||||
} else {
|
||||
nextDirection = Direction.LEFT;
|
||||
}
|
||||
} else {
|
||||
// else, moving up/down
|
||||
int nextIndex;
|
||||
if (relaY > 0) {
|
||||
nextDirection = Direction.DOWN;
|
||||
} else {
|
||||
nextDirection = Direction.UP;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,25 +5,14 @@ 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.math.Vector2;
|
||||
import com.me.pacman.Constants;
|
||||
import com.me.pacman.PacDude;
|
||||
import com.me.pacman.Score;
|
||||
|
||||
public class HighScoresState extends State {
|
||||
|
||||
public static final MenuState.BoundingBox BUTTON = new MenuState.BoundingBox(
|
||||
11 * Constants.TILE_SIZE,
|
||||
5 * Constants.TILE_SIZE,
|
||||
17 * Constants.TILE_SIZE,
|
||||
6 * Constants.TILE_SIZE);
|
||||
|
||||
|
||||
private Texture background;
|
||||
|
||||
private boolean buttonPressed = false;
|
||||
|
||||
|
||||
public HighScoresState(PacDude game) {
|
||||
super(game);
|
||||
}
|
||||
@ -39,20 +28,17 @@ public class HighScoresState extends State {
|
||||
game.batch.draw(background, 0, 16);
|
||||
|
||||
game.fontRenderer.setColor(Color.YELLOW);
|
||||
game.fontRenderer.draw(game.batch, "high scores", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 25 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "high scores", (8 * 8) + 4, 25 * 8);
|
||||
|
||||
game.fontRenderer.setColor(Color.CHARTREUSE);
|
||||
game.fontRenderer.draw(game.batch, "score name", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 22 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "score name", (8 * 8) + 4, 23 * 8);
|
||||
|
||||
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 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (18 - i) * 9);
|
||||
game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * 8) + 4, (17 - i) * 9);
|
||||
}
|
||||
|
||||
game.fontRenderer.setColor(buttonPressed ? Color.BLUE : Color.WHITE);
|
||||
game.fontRenderer.draw(game.batch, "return", 11 * Constants.TILE_SIZE, 5 * Constants.TILE_SIZE - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,7 +55,6 @@ public class HighScoresState extends State {
|
||||
public boolean keyDown(int keycode) {
|
||||
switch(keycode) {
|
||||
case Input.Keys.ENTER:
|
||||
case Input.Keys.BACK:
|
||||
case Input.Keys.ESCAPE:
|
||||
game.setNextState(new MenuState(game));
|
||||
break;
|
||||
@ -77,30 +62,6 @@ public class HighScoresState extends State {
|
||||
return super.keyDown(keycode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||
if (BUTTON.contains(coords)) {
|
||||
buttonPressed = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||
if (!buttonPressed) {
|
||||
return true;
|
||||
}
|
||||
buttonPressed = false;
|
||||
|
||||
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||
if (BUTTON.contains(coords)) {
|
||||
game.setNextState(new MenuState(game));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
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) {
|
||||
@ -14,11 +16,7 @@ public abstract class LevelState extends State {
|
||||
}
|
||||
|
||||
public void drawSprite(TextureRegion sprite, float x, float y) {
|
||||
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)
|
||||
);
|
||||
game.batch.draw(sprite, (int) (x * 8) + (LEVEL_OFFSET_X - 8), (int) (y * 8) + (LEVEL_OFFSET_Y - 8));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,9 +6,8 @@ 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.SoundManager;
|
||||
import com.me.pacman.Sound;
|
||||
|
||||
public class MenuState extends LevelState {
|
||||
|
||||
@ -19,8 +18,8 @@ public class MenuState extends LevelState {
|
||||
public static final int NEW_GAME = 0;
|
||||
public static final int HIGH_SCORES = 1;
|
||||
|
||||
private static final BoundingBox NEW_GAME_BOX = new BoundingBox(88, 66, 136, 84);
|
||||
private static final BoundingBox HIGH_SCORE_BOX = new BoundingBox(88, 42, 136, 60);
|
||||
private BoundingBox NEW_GAME_BOX = new BoundingBox(88, 66, 136, 84);
|
||||
private BoundingBox HIGH_SCORE_BOX = new BoundingBox(88, 42, 136, 60);
|
||||
|
||||
private int selectedOption;
|
||||
|
||||
@ -35,11 +34,10 @@ public class MenuState extends LevelState {
|
||||
logo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
||||
|
||||
Gdx.input.setInputProcessor(this.new Controller());
|
||||
game.sound.play(SoundManager.Effect.BEGINNING);
|
||||
game.sound.play(Sound.Effect.BEGINNING);
|
||||
|
||||
switch(Gdx.app.getType()) {
|
||||
case Android:
|
||||
case iOS:
|
||||
selectedOption = -1;
|
||||
break;
|
||||
default:
|
||||
@ -55,12 +53,12 @@ public class MenuState extends LevelState {
|
||||
|
||||
|
||||
game.fontRenderer.setColor(selectedOption == 0 ? Color.BLUE : Color.WHITE);
|
||||
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.draw(game.batch, "new", (12 * 8) + 4, (9 * 8) + 4);
|
||||
game.fontRenderer.draw(game.batch, "game", 12 * 8, (8 * 8) + 4);
|
||||
|
||||
game.fontRenderer.setColor(selectedOption == 1 ? Color.BLUE : Color.WHITE);
|
||||
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);
|
||||
game.fontRenderer.draw(game.batch, "high", (12 * 8), (6 * 8) + 4);
|
||||
game.fontRenderer.draw(game.batch, "scores", (11 * 8), (5 * 8) + 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,11 +71,11 @@ public class MenuState extends LevelState {
|
||||
switch (keycode) {
|
||||
case Input.Keys.UP:
|
||||
selectedOption = selectedOption > 0 ? --selectedOption : 1;
|
||||
game.sound.play(SoundManager.Effect.CHOMP_1);
|
||||
game.sound.play(Sound.Effect.CHOMP_1);
|
||||
break;
|
||||
case Input.Keys.DOWN:
|
||||
selectedOption = selectedOption < 1 ? ++selectedOption : 0;
|
||||
game.sound.play(SoundManager.Effect.CHOMP_2);
|
||||
game.sound.play(Sound.Effect.CHOMP_2);
|
||||
break;
|
||||
case Input.Keys.ENTER:
|
||||
switch (selectedOption) {
|
||||
|
@ -5,28 +5,47 @@ 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.SoundManager;
|
||||
import com.me.pacman.Sound;
|
||||
import com.me.pacman.entity.*;
|
||||
import com.me.pacman.entity.ai.ReturnToBase;
|
||||
import com.me.pacman.entity.path.EnterGhostHousePath;
|
||||
import com.me.pacman.level.Level;
|
||||
import com.me.pacman.level.LevelTile;
|
||||
import com.me.pacman.RoundModifiers;
|
||||
import com.me.pacman.level.Modifiers;
|
||||
|
||||
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),
|
||||
new Vector2(12f, 16.5f),
|
||||
new Vector2(16f, 16.5f),
|
||||
};
|
||||
|
||||
public static final Direction[] GHOST_SPAWN_DIRS = {
|
||||
Direction.LEFT,
|
||||
Direction.UP,
|
||||
Direction.DOWN,
|
||||
Direction.DOWN,
|
||||
};
|
||||
|
||||
private Texture levelBackground, winBackground;
|
||||
private TextureRegion lifeSprite;
|
||||
|
||||
public Random random;
|
||||
|
||||
public int pelletsRemaining;
|
||||
private int pelletsEaten;
|
||||
|
||||
public int pelletsEatenSinceDeath;
|
||||
public boolean pelletsEatenSinceDeathCounterEnabled;
|
||||
public boolean hasDied;
|
||||
@ -85,25 +104,25 @@ public class PlayState extends LevelState {
|
||||
for (Ghost ghost : ghosts) {
|
||||
if ((ghost.currentBehaviour instanceof ReturnToBase
|
||||
|| ghost.currentPath instanceof EnterGhostHousePath) && !ghost.inHouse) {
|
||||
if (!game.sound.isLooping(SoundManager.Effect.RETURN_BASE)) {
|
||||
if (!game.sound.isLooping(Sound.Effect.RETURN_BASE)) {
|
||||
game.sound.stopLoops();
|
||||
game.sound.loop(SoundManager.Effect.RETURN_BASE);
|
||||
game.sound.loop(Sound.Effect.RETURN_BASE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (frightTimer > 0) {
|
||||
if (!game.sound.isLooping(SoundManager.Effect.FRIGHT)) {
|
||||
if (!game.sound.isLooping(Sound.Effect.FRIGHT)) {
|
||||
game.sound.stopLoops();
|
||||
game.sound.loop(SoundManager.Effect.FRIGHT);
|
||||
game.sound.loop(Sound.Effect.FRIGHT);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!game.sound.isLooping(SoundManager.Effect.SIREN)) {
|
||||
if (!game.sound.isLooping(Sound.Effect.SIREN)) {
|
||||
game.sound.stopLoops();
|
||||
game.sound.loop(SoundManager.Effect.SIREN);
|
||||
game.sound.loop(Sound.Effect.SIREN);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,17 +134,17 @@ public class PlayState extends LevelState {
|
||||
|
||||
private void spawnGhosts() {
|
||||
ghosts = new Ghost[4];
|
||||
ghosts[0] = new Blinky(this, new Vector2(Level.GHOST_SPAWN_POINTS[0]), Constants.GHOST_SPAWN_DIRS[0]);
|
||||
ghosts[1] = new Pinky(this, new Vector2(Level.GHOST_SPAWN_POINTS[1]), Constants.GHOST_SPAWN_DIRS[1]);
|
||||
ghosts[2] = new Inky(this, new Vector2(Level.GHOST_SPAWN_POINTS[2]), Constants.GHOST_SPAWN_DIRS[2]);
|
||||
ghosts[3] = new Clyde(this, new Vector2(Level.GHOST_SPAWN_POINTS[3]), Constants.GHOST_SPAWN_DIRS[3]);
|
||||
ghosts[0] = new Blinky(this, new Vector2(GHOST_SPAWN_POINTS[0]), GHOST_SPAWN_DIRS[0]);
|
||||
ghosts[1] = new Pinky(this, new Vector2(GHOST_SPAWN_POINTS[1]), GHOST_SPAWN_DIRS[1]);
|
||||
ghosts[2] = new Inky(this, new Vector2(GHOST_SPAWN_POINTS[2]), GHOST_SPAWN_DIRS[2]);
|
||||
ghosts[3] = new Clyde(this, new Vector2(GHOST_SPAWN_POINTS[3]), GHOST_SPAWN_DIRS[3]);
|
||||
}
|
||||
|
||||
public void resetGhosts() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (ghosts[i] == null) continue;
|
||||
ghosts[i].pos = new Vector2(Level.GHOST_SPAWN_POINTS[i]);
|
||||
ghosts[i].currDirection = Constants.GHOST_SPAWN_DIRS[i];
|
||||
ghosts[i].pos = new Vector2(GHOST_SPAWN_POINTS[i]);
|
||||
ghosts[i].currDirection = GHOST_SPAWN_DIRS[i];
|
||||
ghosts[i].currentPath = null;
|
||||
ghosts[i].caught = false;
|
||||
ghosts[i].inHouse = i > 0;
|
||||
@ -135,6 +154,7 @@ public class PlayState extends LevelState {
|
||||
|
||||
private void initializeLevel() {
|
||||
level = new Level(game,"level");
|
||||
pelletsRemaining = level.getTileCount(LevelTile.PELLET) + level.getTileCount(LevelTile.POWER_PELLET);
|
||||
pacman = new Pacman(this, false);
|
||||
}
|
||||
|
||||
@ -142,6 +162,7 @@ public class PlayState extends LevelState {
|
||||
scatter = true;
|
||||
scatterChaseTransition = 0;
|
||||
|
||||
pelletsEaten = 0;
|
||||
pelletsEatenSinceDeath = 0;
|
||||
pelletsEatenSinceDeathCounterEnabled = false;
|
||||
hasDied = false;
|
||||
@ -155,7 +176,7 @@ public class PlayState extends LevelState {
|
||||
lastGhostCaptured = null;
|
||||
secondsSinceLastDot = 0;
|
||||
|
||||
scatterChaseTimer = RoundModifiers.getScatterChaseTimer(round, scatterChaseTransition);
|
||||
scatterChaseTimer = Modifiers.getScatterChaseTimer(round, scatterChaseTransition);
|
||||
|
||||
random = new Random(897198256012865L);
|
||||
|
||||
@ -175,7 +196,7 @@ public class PlayState extends LevelState {
|
||||
initializeLevel();
|
||||
|
||||
game.sound.stopAll();
|
||||
game.sound.play(SoundManager.Effect.BEGINNING);
|
||||
game.sound.play(Sound.Effect.BEGINNING);
|
||||
}
|
||||
|
||||
private void newGame() {
|
||||
@ -192,36 +213,14 @@ public class PlayState extends LevelState {
|
||||
round++;
|
||||
|
||||
game.sound.stopAll();
|
||||
game.sound.play(SoundManager.Effect.BEGINNING_ALT);
|
||||
game.sound.play(Sound.Effect.BEGINNING_ALT);
|
||||
}
|
||||
|
||||
private void startGame() {
|
||||
game.sound.loop(SoundManager.Effect.SIREN);
|
||||
game.sound.loop(Sound.Effect.SIREN);
|
||||
pacman.moving = true;
|
||||
}
|
||||
|
||||
private GameState endGame() {
|
||||
Score[] scores = game.highScores.getHighScores(10);
|
||||
|
||||
boolean addToScores = scores.length < 10;
|
||||
int scorePosition = scores.length;
|
||||
|
||||
for (int i = 0; i < scores.length; i++) {
|
||||
if (score > scores[i].score) {
|
||||
addToScores = true;
|
||||
scorePosition = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (addToScores) {
|
||||
game.setNextState(new HighScoreEntryState(game, new Score("aaa", score), scorePosition));
|
||||
return null;
|
||||
}
|
||||
|
||||
return GameState.PRE_NEW_GAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
levelBackground = game.assets.getLevelBackground();
|
||||
@ -249,12 +248,16 @@ public class PlayState extends LevelState {
|
||||
newRound();
|
||||
return GameState.NEW_ROUND_WAIT;
|
||||
case GAME_OVER:
|
||||
return endGame();
|
||||
if (score > highScore) {
|
||||
game.setNextState(new HighScoreEntryState(game, new Score("aaa", score)));
|
||||
return null;
|
||||
}
|
||||
return GameState.PRE_NEW_GAME;
|
||||
case GHOST_CAUGHT_POINTS_WAIT:
|
||||
updateBackgroundAudio();
|
||||
return GameState.PLAYING;
|
||||
case PACMAN_CAUGHT_WAIT:
|
||||
game.sound.play(SoundManager.Effect.DEATH);
|
||||
game.sound.play(Sound.Effect.DEATH);
|
||||
pacman.alive = false;
|
||||
return GameState.PACMAN_CAUGHT;
|
||||
}
|
||||
@ -265,16 +268,16 @@ public class PlayState extends LevelState {
|
||||
public void render() {
|
||||
|
||||
game.fontRenderer.setColor(Color.WHITE);
|
||||
game.fontRenderer.draw(game.batch, "1up", 3 * Constants.TILE_SIZE, 35 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "1up", 3 * 8, 35 * 8);
|
||||
|
||||
// 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()) * Constants.TILE_SIZE, 34 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, s, (7 - s.length()) * 8, 34 * 8);
|
||||
|
||||
// Draw high score
|
||||
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);
|
||||
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);
|
||||
|
||||
// Draw remaining lives
|
||||
for (int i = 0; i < lives; i++) {
|
||||
@ -282,14 +285,14 @@ public class PlayState extends LevelState {
|
||||
}
|
||||
|
||||
// Draw the level tiles
|
||||
level.render(Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y);
|
||||
level.render(LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
||||
|
||||
if (state == GameState.ROUND_WON) {
|
||||
// draw flashing level background
|
||||
game.batch.draw((int) (stateTimer * 4) % 2 == 0? levelBackground : winBackground, Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y);
|
||||
game.batch.draw((int) (stateTimer * 4) % 2 == 0? levelBackground : winBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
||||
return;
|
||||
} else {
|
||||
game.batch.draw(levelBackground, Constants.LEVEL_OFFSET_X, Constants.LEVEL_OFFSET_Y);
|
||||
game.batch.draw(levelBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
||||
}
|
||||
|
||||
if (state != GameState.GHOST_CAUGHT_POINTS_WAIT) {
|
||||
@ -314,18 +317,18 @@ public class PlayState extends LevelState {
|
||||
|
||||
if (paused) {
|
||||
game.fontRenderer.setColor(Color.YELLOW);
|
||||
game.fontRenderer.draw(game.batch, "paused", 11 * Constants.TILE_SIZE, 15 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "paused", 11 * 8, 15 * 8);
|
||||
} 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 * Constants.TILE_SIZE, 15 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "ready!", 11 * 8, 15 * 8);
|
||||
break;
|
||||
case GAME_OVER:
|
||||
game.fontRenderer.setColor(Color.RED);
|
||||
game.fontRenderer.draw(game.batch, "game over", (9 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 15 * Constants.TILE_SIZE);
|
||||
game.fontRenderer.draw(game.batch, "game over", (9 * 8) + 4, 15 * 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -334,7 +337,10 @@ public class PlayState extends LevelState {
|
||||
private void pelletEaten(float x, float y) {
|
||||
level.setTile(x, y, LevelTile.EMPTY);
|
||||
|
||||
game.sound.play(level.getPelletsEaten() % 2 == 0? SoundManager.Effect.CHOMP_1 : SoundManager.Effect.CHOMP_2);
|
||||
game.sound.play(pelletsEaten % 2 == 0? Sound.Effect.CHOMP_1 : Sound.Effect.CHOMP_2);
|
||||
|
||||
pelletsEaten++;
|
||||
pelletsRemaining--;
|
||||
|
||||
if (pelletsEatenSinceDeathCounterEnabled) {
|
||||
// Increase global dot counter when enabled
|
||||
@ -353,7 +359,7 @@ public class PlayState extends LevelState {
|
||||
|
||||
secondsSinceLastDot = 0;
|
||||
|
||||
if (level.getPelletsRemaining() == 0) {
|
||||
if (pelletsRemaining == 0) {
|
||||
game.sound.stopLoops();
|
||||
setGameState(GameState.ROUND_WON_WAIT);
|
||||
}
|
||||
@ -372,7 +378,7 @@ public class PlayState extends LevelState {
|
||||
ghost.currentBehaviour = ghost.frightBehaviour;
|
||||
ghost.reverse = true;
|
||||
}
|
||||
frightTimer = RoundModifiers.getFrightTime(round);
|
||||
frightTimer = Modifiers.getFrightTime(round);
|
||||
ghostsCaught = 0;
|
||||
score += 50;
|
||||
|
||||
@ -380,7 +386,7 @@ public class PlayState extends LevelState {
|
||||
}
|
||||
|
||||
private void pacmanCaught() {
|
||||
game.sound.stopLooping(SoundManager.Effect.SIREN);
|
||||
game.sound.stopLooping(Sound.Effect.SIREN);
|
||||
pacman.moving = false;
|
||||
pelletsEatenSinceDeath = 0;
|
||||
pelletsEatenSinceDeathCounterEnabled = true;
|
||||
@ -397,7 +403,7 @@ public class PlayState extends LevelState {
|
||||
ghostsCaught++;
|
||||
score += ghostsCaught * 200;
|
||||
|
||||
game.sound.play(SoundManager.Effect.EAT_GHOST);
|
||||
game.sound.play(Sound.Effect.EAT_GHOST);
|
||||
setGameState(GameState.GHOST_CAUGHT_POINTS_WAIT);
|
||||
}
|
||||
|
||||
@ -407,7 +413,7 @@ public class PlayState extends LevelState {
|
||||
if (scatterChaseTimer <= 0) {
|
||||
scatter = !scatter;
|
||||
scatterChaseTransition++;
|
||||
scatterChaseTimer = RoundModifiers.getScatterChaseTimer(round, scatterChaseTransition);
|
||||
scatterChaseTimer = Modifiers.getScatterChaseTimer(round, scatterChaseTransition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -427,7 +433,7 @@ public class PlayState extends LevelState {
|
||||
|
||||
private void updateSecondsSinceLastDot(float dt) {
|
||||
secondsSinceLastDot += dt;
|
||||
if (secondsSinceLastDot >= RoundModifiers.getForceLeaveSeconds(round)) {
|
||||
if (secondsSinceLastDot >= Modifiers.getForceLeaveSeconds(round)) {
|
||||
// It's been 4 seconds since pacman last ate a dot, he's tryin' to avoid ghosts coming out!
|
||||
// We'll get him...
|
||||
for (int i = 1; i < 4; i++) {
|
||||
@ -460,7 +466,7 @@ public class PlayState extends LevelState {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Constants.DEBUG) {
|
||||
if (PacDude.DEBUG) {
|
||||
// Fixed time step for debugger
|
||||
dt = 1/60f;
|
||||
}
|
||||
|
@ -2,15 +2,14 @@ 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 = Constants.TITLE + " - " + Constants.VERSION;
|
||||
config.width = Constants.GAME_WIDTH * 2;
|
||||
config.height = Constants.GAME_HEIGHT * 2;
|
||||
config.title = PacDude.TITLE + " - " + PacDude.VERSION;
|
||||
config.width = PacDude.LEVEL_WIDTH * 2;
|
||||
config.height = PacDude.LEVEL_HEIGHT * 2;
|
||||
config.resizable = true;
|
||||
new LwjglApplication(new PacDude(), config);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user