Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More structural things, level loading is almost done. Rendering comin…
…g soon.
  • Loading branch information
wjg12004 committed Feb 20, 2016
1 parent 1f15729 commit e7d3ec2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/game/Launcher.java
Expand Up @@ -9,5 +9,6 @@ public class Launcher {

// Testing file loading
LevelHandler test = new LevelHandler("res/levels/test.txt");
test.printTiles();
}
}
24 changes: 21 additions & 3 deletions src/level/LevelHandler.java
Expand Up @@ -10,7 +10,7 @@ import level.tiles.Tile;
// Creates and manages the level when the game is running.
public class LevelHandler {

private Tile[][] tiles;
private Tile[][] tiles = new Tile[30][30];
private List<Entity> entities;
private int width;
private int height;
Expand All @@ -24,13 +24,22 @@ public class LevelHandler {
}
}

// TODO: Change this to use and XML file instead of a text file
// TODO: Make work, preferably using JSON
private void loadLevelFromFile() {
try {
FileReader fileReader = new FileReader(levelPath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
levelName = bufferedReader.readLine();

String line = "";
int yMarker = 0;
while((line = bufferedReader.readLine()) != null) {
int xMarker = 0;
for (String currentID : line.split("\\s")) {
tiles[yMarker][xMarker] = Tile.getTile(Integer.parseInt(currentID));
xMarker++;
}
yMarker++;
}
bufferedReader.close();
} catch (IOException e) {
System.err.println(e.getMessage());
Expand All @@ -52,4 +61,13 @@ public class LevelHandler {
public String getLevelName() {
return levelName;
}

public void printTiles() {
for (Tile[] y : tiles) {
for (Tile x : y) {
System.out.print(x + " ");
}
System.out.println();
}
}
}
10 changes: 5 additions & 5 deletions src/level/tiles/Tile.java
Expand Up @@ -10,7 +10,7 @@ public abstract class Tile {
private Color color;

// Contains all tiles in the game, where the index is the tile ID.
private Tile[] gameTiles = new Tile[32];
private static Tile[] gameTiles = new Tile[32];

public Tile(int id, boolean isFloor, boolean isWall, Color color) {
this.id = id;
Expand All @@ -19,7 +19,7 @@ public abstract class Tile {
this.color = color;

// Populate this with all tiles that exist
// gameTiles[1] =
gameTiles[1] = new SmoothFloor();
}

public int getId() {
Expand All @@ -34,9 +34,9 @@ public abstract class Tile {
return isWall;
}

// public Tile getTile(int tileID) {
//
// }
public static Tile getTile(int tileID) {
return gameTiles[tileID];
}

public abstract void tick();

Expand Down

0 comments on commit e7d3ec2

Please sign in to comment.