LevelComponent -> LevelTile

This commit is contained in:
Matt Low 2019-12-24 22:38:32 +04:00
parent 961b4469c5
commit d8319148b9
4 changed files with 18 additions and 19 deletions

View File

@ -1,6 +1,6 @@
package com.me.pacman.entity; package com.me.pacman.entity;
import com.me.pacman.level.LevelComponent; import com.me.pacman.level.LevelTile;
import com.me.pacman.state.LevelState; import com.me.pacman.state.LevelState;
public abstract class MovableEntity extends Entity { public abstract class MovableEntity extends Entity {
@ -30,7 +30,7 @@ public abstract class MovableEntity extends Entity {
} }
if (nextDirection != null) { if (nextDirection != null) {
LevelComponent nextComponent; LevelTile nextComponent;
boolean turned = false; boolean turned = false;
switch (nextDirection) { switch (nextDirection) {
case NORTH: case NORTH:

View File

@ -1,6 +1,5 @@
package com.me.pacman.level; package com.me.pacman.level;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.me.pacman.PacDude; import com.me.pacman.PacDude;
@ -12,7 +11,7 @@ public class Level {
private TextureRegion powerPellet; private TextureRegion powerPellet;
// Grid of components, [rows][columns] // Grid of components, [rows][columns]
public LevelComponent[][] components; public LevelTile[][] components;
public Level(PacDude game, String level) { public Level(PacDude game, String level) {
@ -25,23 +24,23 @@ public class Level {
components = loader.loadLevel(); components = loader.loadLevel();
} }
public LevelComponent getComponent(int x, int y) { public LevelTile getComponent(int x, int y) {
return components[y][x]; return components[y][x];
} }
public LevelComponent getComponent(float x, float y) { public LevelTile getComponent(float x, float y) {
return getComponent((int) x, (int) y); return getComponent((int) x, (int) y);
} }
public void setComponent(int x, int y, LevelComponent component) { public void setComponent(int x, int y, LevelTile component) {
components[y][x] = component; components[y][x] = component;
} }
public void render(int offsetX, int offsetY) { public void render(int offsetX, int offsetY) {
for (int i = 0; i < components.length; i++) { for (int i = 0; i < components.length; i++) {
LevelComponent[] row = components[i]; LevelTile[] row = components[i];
for (int j = 0; j < row.length; j++) { for (int j = 0; j < row.length; j++) {
LevelComponent component = row[j]; LevelTile component = row[j];
TextureRegion sprite; TextureRegion sprite;
switch (component) { switch (component) {
case PELLET: case PELLET:

View File

@ -11,11 +11,11 @@ public class LevelLoader {
levelFile = Gdx.files.internal("data/" + level + ".txt"); levelFile = Gdx.files.internal("data/" + level + ".txt");
} }
public LevelComponent[][] loadLevel() { public LevelTile[][] loadLevel() {
String levelData = levelFile.readString(); String levelData = levelFile.readString();
String[] lines = levelData.split("\n"); String[] lines = levelData.split("\n");
int rows = lines.length; int rows = lines.length;
LevelComponent[][] components = new LevelComponent[rows][lines[0].length()]; LevelTile[][] components = new LevelTile[rows][lines[0].length()];
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
String line = lines[i]; String line = lines[i];
@ -25,25 +25,25 @@ public class LevelLoader {
int row = rows - i - 1; int row = rows - i - 1;
switch(c) { switch(c) {
case '*': case '*':
components[row][j] = LevelComponent.PELLET; components[row][j] = LevelTile.PELLET;
break; break;
case '%': case '%':
components[row][j] = LevelComponent.POWER_PELLET; components[row][j] = LevelTile.POWER_PELLET;
break; break;
case '#': case '#':
components[row][j] = LevelComponent.WALL; components[row][j] = LevelTile.WALL;
break; break;
case '^': case '^':
components[row][j] = LevelComponent.GHOST_CHAMBER; components[row][j] = LevelTile.GHOST_CHAMBER;
break; break;
case '_': case '_':
components[row][j] = LevelComponent.GHOST_GATE; components[row][j] = LevelTile.GHOST_GATE;
break; break;
case '-': case '-':
components[row][j] = LevelComponent.HALLWAY; components[row][j] = LevelTile.HALLWAY;
break; break;
default: default:
components[row][j] = LevelComponent.EMPTY; components[row][j] = LevelTile.EMPTY;
} }
} }
} }

View File

@ -1,6 +1,6 @@
package com.me.pacman.level; package com.me.pacman.level;
public enum LevelComponent { public enum LevelTile {
PELLET, PELLET,
POWER_PELLET, POWER_PELLET,