diff options
author | Nao Pross <naopross@thearcway.org> | 2018-02-10 14:41:49 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-02-10 14:41:49 +0100 |
commit | d677dbead66c2c52c2ffc51a64ece0a06114d2ad (patch) | |
tree | 188a7a6fc693dd47de18648577fba3c247361f2c /src/main/java | |
parent | Implement barebone game engine (diff) | |
download | Subconscious-old-d677dbead66c2c52c2ffc51a64ece0a06114d2ad.tar.gz Subconscious-old-d677dbead66c2c52c2ffc51a64ece0a06114d2ad.zip |
Switch to gradle, update gitignore
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/Actor.java | 3 | ||||
-rw-r--r-- | src/main/java/Map.java | 28 | ||||
-rw-r--r-- | src/main/java/Scene.java | 5 | ||||
-rw-r--r-- | src/main/java/Subconscious.java | 79 | ||||
-rw-r--r-- | src/main/java/Tile.java | 15 | ||||
-rw-r--r-- | src/main/java/WorldScene.java | 32 |
6 files changed, 162 insertions, 0 deletions
diff --git a/src/main/java/Actor.java b/src/main/java/Actor.java new file mode 100644 index 0000000..207d6e6 --- /dev/null +++ b/src/main/java/Actor.java @@ -0,0 +1,3 @@ +public class Actor { + +} diff --git a/src/main/java/Map.java b/src/main/java/Map.java new file mode 100644 index 0000000..031e922 --- /dev/null +++ b/src/main/java/Map.java @@ -0,0 +1,28 @@ +import java.awt.Dimension; + +public class Map { + + public final Dimension size; + public final Tile grid[]; + + // TODO load map from file + // public Map(File filename) { + public Map(Dimension size) { + this.size = size; + + // populate grid + this.grid = new Tile[this.size.width * this.size.height]; + for (int y = 0; y < this.size.width; y++) { + for (int x = 0; x < this.size.height; x++) { + this.grid[y * this.size.width + x] = new Tile(Tile.Type.GRASS, x, y); + } + } + } + + // public void load() {} + + /* accessors */ + public Tile getTile(int x, int y) { + return this.grid[y * this.size.width + y]; + } +} diff --git a/src/main/java/Scene.java b/src/main/java/Scene.java new file mode 100644 index 0000000..a2949fd --- /dev/null +++ b/src/main/java/Scene.java @@ -0,0 +1,5 @@ +import java.awt.Graphics; + +public abstract class Scene { + abstract void render(Graphics g); +} diff --git a/src/main/java/Subconscious.java b/src/main/java/Subconscious.java new file mode 100644 index 0000000..b63eb23 --- /dev/null +++ b/src/main/java/Subconscious.java @@ -0,0 +1,79 @@ +import javax.swing.JFrame; +import javax.swing.JPanel; + +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Dimension; + + +public class Subconscious extends JPanel { + + public static final String TITLE = "Subconscious"; + + /* graphics */ + public JFrame window; + // public Graphics dbGraphics; // double buffered graphics + // public Image dbImage = null; // double buffered image + + public Scene currentScene; + + /* game */ + public boolean gameOver = false; + public boolean running = false; + + public Subconscious() { + createWindow(); + + // TODO remove demo + currentScene = new WorldScene(new Dimension(200, 200), 50); + } + + public void createWindow() { + window = new JFrame(TITLE); + window.setSize(new Dimension(800, 600)); + window.setLocationRelativeTo(null); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.add(this); + } + + /* game logic */ + public void gameLoop() { + + } + + public void gameRender() { + + } + + public void start() { + running = true; + gameOver = false; + + window.setVisible(true); + + while (running) { + gameLoop(); + gameRender(); + repaint(); + + try { + // TODO replace with correct timing + Thread.sleep(20); + } catch (InterruptedException ex) { + // + } + } + } + + /* graphics */ + @Override + public void paintComponent(Graphics g) { + currentScene.render(g); + } + + /* main */ + public static void main(String args[]) { + Subconscious game = new Subconscious(); + game.start(); + } +} diff --git a/src/main/java/Tile.java b/src/main/java/Tile.java new file mode 100644 index 0000000..cbdeda4 --- /dev/null +++ b/src/main/java/Tile.java @@ -0,0 +1,15 @@ +public class Tile { + + public enum Type { + GRASS, + }; + + public final int x, y; + public final Type type; + + public Tile(Type type, int x, int y) { + this.type = type; + this.x = x; + this.y = y; + } +} diff --git a/src/main/java/WorldScene.java b/src/main/java/WorldScene.java new file mode 100644 index 0000000..6dff04a --- /dev/null +++ b/src/main/java/WorldScene.java @@ -0,0 +1,32 @@ +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; + + +public class WorldScene extends Scene { + + private Actor actors[]; + private Map map; + + private int tileSize; + + public WorldScene(Dimension gridSize, int tileSize) { + this.tileSize = tileSize; + map = new Map(gridSize); + } + + @Override + public void render(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + + for (Tile tile : this.map.grid) { + g2d.setColor(Color.GREEN); + g2d.fillRect( + this.tileSize * tile.x, + this.tileSize * tile.y, + this.tileSize, this.tileSize + ); + } + } +} |