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

View File

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

View File

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

View File

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