Remove unused ShapeRenderer, add FPS counter in DEBUG mode

Move ghost reverse after path logic, which may have been the cause of
ghosts getting stuck inside the house...?

Moved where 'paused' is rendered
This commit is contained in:
Matt Low 2020-01-07 15:47:41 +04:00
parent b8fcfb4de7
commit b05cca6b3f
5 changed files with 20 additions and 18 deletions

View File

@ -5,11 +5,9 @@ import com.badlogic.gdx.Gdx;
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.graphics.glutils.ShapeRenderer;
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.MenuState; import com.me.pacman.state.MenuState;
import com.me.pacman.state.PlayState;
public class PacDude extends Game { public class PacDude extends Game {
@ -22,8 +20,9 @@ public class PacDude extends Game {
public static final int LEVEL_HEIGHT = 288; public static final int LEVEL_HEIGHT = 288;
public Assets assets; public Assets assets;
public Sound sound;
public SpriteBatch batch; public SpriteBatch batch;
public ShapeRenderer sr;
public OrthographicCamera cam; public OrthographicCamera cam;
public Viewport viewport; public Viewport viewport;
@ -36,19 +35,22 @@ public class PacDude extends Game {
assets = new Assets(); assets = new Assets();
assets.loadAssets(); assets.loadAssets();
sound = new Sound(this);
batch = new SpriteBatch(); batch = new SpriteBatch();
sr = new ShapeRenderer();
Gdx.gl.glClearColor(0, 0, 0, 1);
setScreen(new MenuState(this)); setScreen(new MenuState(this));
} }
@Override @Override
public void render () { public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin(); batch.begin();
if (DEBUG) {
assets.getFont().draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 152, 287);
}
super.render(); super.render();
batch.end(); batch.end();
} }
@ -58,7 +60,6 @@ public class PacDude extends Game {
viewport.update(width, height); viewport.update(width, height);
batch.setProjectionMatrix(cam.combined); batch.setProjectionMatrix(cam.combined);
sr.setProjectionMatrix(cam.combined);
super.resize(width, height); super.resize(width, height);
} }

View File

@ -19,6 +19,8 @@ public abstract class Entity {
this.age = 0; this.age = 0;
} }
public abstract TextureRegion getSprite();
public void render() { public void render() {
TextureRegion texture = getSprite(); TextureRegion texture = getSprite();
if (texture == null) { if (texture == null) {
@ -48,8 +50,6 @@ public abstract class Entity {
return new Target(pos.x, pos.y); return new Target(pos.x, pos.y);
} }
public abstract TextureRegion getSprite();
public void update(float dt) { public void update(float dt) {
this.age += 1; this.age += 1;
} }

View File

@ -105,15 +105,6 @@ public class Ghost extends MovableEntity {
speed = getNormalSpeed(); speed = getNormalSpeed();
} }
int tileX = (int) pos.x;
int tileY = (int) pos.y;
if (reverse && (tileX != prevTileX || tileY != prevTileY)) {
setNextDirection(currDirection.getOpposite());
reverse = false;
}
prevTileX = tileX;
prevTileY = tileY;
super.update(dt); super.update(dt);
if (currentPath != null) { if (currentPath != null) {
@ -128,6 +119,15 @@ public class Ghost extends MovableEntity {
currentPath = null; currentPath = null;
} }
int tileX = (int) pos.x;
int tileY = (int) pos.y;
if (reverse && (tileX != prevTileX || tileY != prevTileY)) {
setNextDirection(currDirection.getOpposite());
reverse = false;
}
prevTileX = tileX;
prevTileY = tileY;
if (inHouse) { if (inHouse) {
if (pos.y >= 17) { if (pos.y >= 17) {
currDirection = Direction.DOWN; currDirection = Direction.DOWN;

View File

@ -14,6 +14,7 @@ public class ClydeChaseBehaviour extends Behaviour {
public Target getTarget() { public Target getTarget() {
Vector2 pacmanTile = state.pacman.getTileVector(); Vector2 pacmanTile = state.pacman.getTileVector();
Vector2 clydeTile = state.ghosts[3].getTileVector(); Vector2 clydeTile = state.ghosts[3].getTileVector();
// If clyde > 8 tiles away from pacman, target him directly - else, target Clyde's scatter tile
return pacmanTile.dst2(clydeTile) >= 8*8? new Target(pacmanTile) : Clyde.SCATTER_TARGET; return pacmanTile.dst2(clydeTile) >= 8*8? new Target(pacmanTile) : Clyde.SCATTER_TARGET;
} }
} }

View File

@ -296,7 +296,7 @@ public class PlayState extends LevelState {
if (paused) { if (paused) {
game.assets.getFont().setColor(Color.YELLOW); game.assets.getFont().setColor(Color.YELLOW);
game.assets.getFont().draw(game.batch, "paused", 90, 151); game.assets.getFont().draw(game.batch, "paused", 90, 127);
} else { } else {
switch (state) { switch (state) {
case PRE_NEW_GAME: case PRE_NEW_GAME: