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

View File

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

View File

@ -105,15 +105,6 @@ public class Ghost extends MovableEntity {
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);
if (currentPath != null) {
@ -128,6 +119,15 @@ public class Ghost extends MovableEntity {
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 (pos.y >= 17) {
currDirection = Direction.DOWN;

View File

@ -14,6 +14,7 @@ public class ClydeChaseBehaviour extends Behaviour {
public Target getTarget() {
Vector2 pacmanTile = state.pacman.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;
}
}

View File

@ -296,7 +296,7 @@ public class PlayState extends LevelState {
if (paused) {
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 {
switch (state) {
case PRE_NEW_GAME: