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 18, 2016
1 parent 88bc588 commit 1f15729
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 10 deletions.
7 changes: 7 additions & 0 deletions res/levels/test.txt
@@ -0,0 +1,7 @@
test
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
3 changes: 0 additions & 3 deletions src/Game.java

This file was deleted.

6 changes: 6 additions & 0 deletions src/entities/Entity.java
@@ -0,0 +1,6 @@
package entities;

public abstract class Entity {

public abstract void tick();
}
5 changes: 5 additions & 0 deletions src/entities/EntityHandler.java
@@ -0,0 +1,5 @@
package entities;

public class EntityHandler {

}
22 changes: 22 additions & 0 deletions src/game/Game.java
@@ -0,0 +1,22 @@
package game;

import javax.swing.JFrame;
import gfx.Screen;
import level.LevelHandler;

public class Game extends JFrame{

private Screen screen;

public Game() {
setSize(800, 600);
setTitle(screen.getLevelName());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}

public void setLevel(LevelHandler newLevel) {
screen = new Screen(newLevel);
}
}
1 change: 1 addition & 0 deletions src/InputHandler.java → src/game/InputHandler.java
@@ -1,3 +1,4 @@
package game;
public class InputHandler {

}
13 changes: 13 additions & 0 deletions src/game/Launcher.java
@@ -0,0 +1,13 @@
package game;

import level.LevelHandler;

public class Launcher {

public static void main(String[] args) {
//new Menu().run();

// Testing file loading
LevelHandler test = new LevelHandler("res/levels/test.txt");
}
}
1 change: 1 addition & 0 deletions src/MouseHandler.java → src/game/MouseHandler.java
@@ -1,3 +1,4 @@
package game;
public class MouseHandler {

}
1 change: 1 addition & 0 deletions src/WindowHandler.java → src/game/WindowHandler.java
@@ -1,3 +1,4 @@
package game;
public class WindowHandler {

}
23 changes: 23 additions & 0 deletions src/gfx/Screen.java
@@ -0,0 +1,23 @@
package gfx;

import java.awt.Dimension;
import javax.swing.JPanel;
import level.LevelHandler;

// This class will contain and render a specific level/entities
// The game.Game class will contain one screen at a time to display that level.
public class Screen extends JPanel {

private String levelName;
private LevelHandler level;

public Screen(LevelHandler level) {
this.level = level;
this.setPreferredSize(new Dimension(700, 600));
}

public String getLevelName() {
return levelName;
}

}
40 changes: 37 additions & 3 deletions src/level/LevelHandler.java
@@ -1,11 +1,20 @@
package level;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import entities.Entity;
import level.tiles.Tile;

// Creates and manages the level when the game is running.
public class LevelHandler {

private Integer[] tiles;
private Tile[][] tiles;
private List<Entity> entities;
private int width;
private int height;

private String levelName;
private String levelPath;

public LevelHandler(String levelPath) {
Expand All @@ -15,7 +24,32 @@ public class LevelHandler {
}
}

// TODO: Change this to use and XML file instead of a text file
private void loadLevelFromFile() {

try {
FileReader fileReader = new FileReader(levelPath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
levelName = bufferedReader.readLine();

bufferedReader.close();
} catch (IOException e) {
System.err.println(e.getMessage());
}
}

public void tick() {
for (Tile[] tileArray : tiles) {
for (Tile t : tileArray) {
t.tick();
}
}

for (Entity e : entities) {
e.tick();
}
}

public String getLevelName() {
return levelName;
}
}
25 changes: 25 additions & 0 deletions src/level/tiles/SmoothFloor.java
@@ -0,0 +1,25 @@
package level.tiles;

import java.awt.Color;

public class SmoothFloor extends Tile{

private float friction = 1;

public SmoothFloor() {
super(1, true, false, Color.gray);
}

public void tick() {

}

public void render() {

}

public float getFriction() {
return friction;
}

}
19 changes: 15 additions & 4 deletions src/level/tiles/Tile.java
@@ -1,17 +1,25 @@
package level.tiles;

import java.awt.Color;

public abstract class Tile {

protected int id;
protected boolean isFloor;
protected boolean isWall;
private int color;

public Tile(int id, boolean isFloor, boolean isWall, int color) {
private Color color;

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

public Tile(int id, boolean isFloor, boolean isWall, Color color) {
this.id = id;
this.isFloor = isFloor;
this.isWall = isWall;
this.color = color;

// Populate this with all tiles that exist
// gameTiles[1] =
}

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

// public Tile getTile(int tileID) {
//
// }

public abstract void tick();

//Not sure what needs to be passed in here just yet, will become apparent when the rendering is closer to being done.
public abstract void render();
}
24 changes: 24 additions & 0 deletions src/menu/Menu.java
@@ -0,0 +1,24 @@
package menu;

import java.io.FileNotFoundException;
import java.io.IOException;

import game.Game;
import level.LevelHandler;

public class Menu {

// Will display options. This is the main menu.
// Currently jumps right to a game.
public void run() throws IOException{
Game game = new Game();
// Show menu options here

// Control flow to select level, game modes, etc.

// Pretend a test level was selected
LevelHandler chosenLevel = new LevelHandler("/res/test.txt");
game.setLevel(chosenLevel);
}

}

0 comments on commit 1f15729

Please sign in to comment.