Add debug rendering of an entity's current tile

This commit is contained in:
Matt Low 2019-12-28 12:55:08 +04:00
parent f6fbad0e6d
commit c32451a597
6 changed files with 31 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

View File

@ -3,7 +3,9 @@ package com.me.pacman.entity;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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.entity.ai.Target; import com.me.pacman.entity.ai.Target;
import com.me.pacman.level.LevelTile;
import com.me.pacman.state.LevelState; import com.me.pacman.state.LevelState;
public abstract class Entity { public abstract class Entity {
@ -24,6 +26,10 @@ public abstract class Entity {
return; return;
} }
batch.draw(texture, (int) (pos.x * 8) + (offsetX - 8), (pos.y * 8) + (offsetY - 8)); batch.draw(texture, (int) (pos.x * 8) + (offsetX - 8), (pos.y * 8) + (offsetY - 8));
if (PacDude.DEBUG) {
state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, offsetX, offsetY);
}
} }
public boolean onSameTile(Entity other) { public boolean onSameTile(Entity other) {

View File

@ -1,6 +1,8 @@
package com.me.pacman.entity; package com.me.pacman.entity;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.me.pacman.level.LevelTile; import com.me.pacman.level.LevelTile;
import com.me.pacman.state.PlayState; import com.me.pacman.state.PlayState;
@ -54,7 +56,7 @@ public class Pacman extends MovableEntity {
deathFrame++; deathFrame++;
} }
LevelTile tile = state.level.getTile(pos.x, pos.y); LevelTile tile = state.level.getTile(pos);
if (tile == null) { if (tile == null) {
return; return;
} }

View File

@ -10,6 +10,7 @@ public class Level {
private TextureRegion pellet; private TextureRegion pellet;
private TextureRegion powerPellet; private TextureRegion powerPellet;
private TextureRegion debug;
// Grid of tiles, [rows][columns] // Grid of tiles, [rows][columns]
public LevelTile[][] tiles; public LevelTile[][] tiles;
@ -23,6 +24,7 @@ public class Level {
pellet = game.assets.level[0][6]; pellet = game.assets.level[0][6];
powerPellet = game.assets.level[0][7]; powerPellet = game.assets.level[0][7];
debug = game.assets.level[1][7];
LevelLoader loader = new LevelLoader(level); LevelLoader loader = new LevelLoader(level);
tiles = loader.loadLevel(); tiles = loader.loadLevel();
@ -68,21 +70,27 @@ public class Level {
for (int i = 0; i < tiles.length; i++) { for (int i = 0; i < tiles.length; i++) {
LevelTile[] row = tiles[i]; LevelTile[] row = tiles[i];
for (int j = 0; j < row.length; j++) { for (int j = 0; j < row.length; j++) {
LevelTile component = row[j]; renderTile(row[j], j, i, offsetX, offsetY);
}
}
}
public void renderTile(LevelTile tile, int tileX, int tileY, int offsetX, int offsetY) {
TextureRegion sprite; TextureRegion sprite;
switch (component) { switch (tile) {
case PELLET: case PELLET:
sprite = pellet; sprite = pellet;
break; break;
case POWER_PELLET: case POWER_PELLET:
sprite = powerPellet; sprite = powerPellet;
break; break;
case DEBUG:
sprite = debug;
break;
default: default:
continue; return;
}
game.batch.draw(sprite, (j * 8) + offsetX, (i * 8) + offsetY);
}
} }
game.batch.draw(sprite, (tileX * 8) + offsetX, (tileY * 8) + offsetY);
} }
} }

View File

@ -9,6 +9,7 @@ public enum LevelTile {
GHOST_CHAMBER, GHOST_CHAMBER,
GHOST_GATE, GHOST_GATE,
EMPTY, EMPTY,
DEBUG,
; ;
public boolean isPassable() { public boolean isPassable() {