aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Actor.java3
-rw-r--r--src/EntityType.java3
-rw-r--r--src/MainPanel.java265
-rw-r--r--src/Map.java28
-rw-r--r--src/Scene.java5
-rw-r--r--src/Subconscious.java87
-rw-r--r--src/Tile.java27
-rw-r--r--src/TileType.java3
-rw-r--r--src/WorldScene.java32
9 files changed, 149 insertions, 304 deletions
diff --git a/src/Actor.java b/src/Actor.java
new file mode 100644
index 0000000..207d6e6
--- /dev/null
+++ b/src/Actor.java
@@ -0,0 +1,3 @@
+public class Actor {
+
+}
diff --git a/src/EntityType.java b/src/EntityType.java
deleted file mode 100644
index a4ccf30..0000000
--- a/src/EntityType.java
+++ /dev/null
@@ -1,3 +0,0 @@
-public enum EntityType {
- NULL, PLAYER, ENEMY, TREE
-}
diff --git a/src/MainPanel.java b/src/MainPanel.java
deleted file mode 100644
index 8af12ee..0000000
--- a/src/MainPanel.java
+++ /dev/null
@@ -1,265 +0,0 @@
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.Random;
-
-public class MainPanel extends JPanel implements MouseListener, MouseMotionListener {
-
- public int width = 20;
- public Tile[][] tileArray = new Tile[width][width];
- public int size;
- public boolean selectionMode = false;
- public boolean attackMode = false;
- public boolean action = false;
- public boolean miss = false;
- public int[] selection = {0, 0};
- public int[] attaction = {0, 0};
- public int[] location = {0, 0};
- private int len;
- private Color RED = new Color(165, 66, 66);
- private Color YELLOW = new Color(250, 198, 116);
- private Color GREEN = new Color(181, 189, 104);
- private Color BLACK = new Color(29, 31, 33);
- private Color WHITE = new Color(197, 200, 198);
- private Color BLUE = new Color(95, 129, 157);
- private Color ORANGE = new Color(222, 147, 95);
- private Color DARKGREEN = new Color(140, 148, 64);
- private Color BROWN = new Color(51, 41, 33);
- private Random rand = new Random();
-
- public MainPanel () {
- for (int row = 0; row < width; row++) {
- for (int col = 0; col < width; col++) {
- tileArray[row][col] = new Tile(row, col, this.size, this.width);
- }
- }
-
- tileArray[0][0].entityType = EntityType.PLAYER;
- for (int i = 0; i < 35; i++) {
- int row = rand.nextInt(width);
- int col = rand.nextInt(width);
- int type = rand.nextInt(4);
- if (tileArray[row][col].entityType == EntityType.NULL) {
- if (type == 0) {
- tileArray[row][col].entityType = EntityType.ENEMY;
- } else {
- tileArray[row][col].entityType = EntityType.TREE;
- }
- }
- }
-
- this.addMouseListener(this);
- this.addMouseMotionListener(this);
- }
-
- public void paintComponent(Graphics g) {
- if (this.getWidth() > this.getHeight()) {
- this.size = this.getHeight();
- } else {
- this.size = this.getWidth();
- }
-
- super.paintComponent(g);
-
- Graphics2D g2d = (Graphics2D) g.create();
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
-
- int bar = this.size/20;
-
- g2d.setColor(WHITE);
- g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
- g2d.setColor(BLACK);
- g2d.fillRect(0, this.size-bar, this.size-bar, bar);
- g2d.setColor(WHITE);
- g2d.setFont(new Font("Arial", Font.BOLD, bar-bar/10));
- if (this.miss) {
- g2d.drawString("MISS", this.size-bar-(bar-bar/10)*3, this.size-bar/10);
- }
-
- if (action) {
- g2d.drawString("PAS", 0, this.size-bar/10);
- g2d.drawString("ATK", (bar-bar/10)*3, this.size-bar/10);
- }
-
- for (int row = 0; row < width; row++) {
- for (int col = 0; col < width; col++) {
- this.tileArray[row][col].calc(row, col, this.size-bar);
- int x = this.tileArray[row][col].x;
- int y = this.tileArray[row][col].y;
- this.len = this.tileArray[row][col].len;
-
- int border = len/100;
-
- if (this.tileArray[row][col].tileType == TileType.GRASS) {
- g2d.setColor(GREEN);
- g2d.fillRect(x, y, len, len);
- g2d.setColor(BLACK);
- g2d.setStroke(new BasicStroke(len/50));
- g2d.drawRect(x, y, len, len);
- } else if (
- this.tileArray[row][col].tileType == TileType.WATER) {
- g2d.setColor(Color.BLUE);
- g2d.fillRect(x, y, len, len);
- g2d.setColor(BLACK);
- g2d.setStroke(new BasicStroke(len/50));
- g2d.drawRect(x, y, len, len);
- }
-
- int spacing = len/12;
-
-
- if (this.tileArray[row][col].entityType == EntityType.PLAYER) {
- g2d.setColor(BLUE);
- g2d.fillRect(
- x+spacing, y+spacing, len-spacing*2, len-spacing*2);
- this.location[0] = x;
- this.location[1] = y;
- this.selection[0] = row;
- this.selection[1] = col;
- }
-
- if (this.tileArray[row][col].entityType == EntityType.ENEMY) {
- g2d.setColor(RED);
- g2d.fillRect(
- x+spacing, y+spacing, len-spacing*2, len-spacing*2);
- }
-
- if (this.tileArray[row][col].entityType == EntityType.TREE) {
- g2d.setColor(DARKGREEN);
- g2d.fillRect(
- x+spacing, y+spacing, len-spacing*2, len-spacing*2);
- g2d.setColor(BROWN);
- g2d.fillRect(x+len/3, y+len/3, len/3, len/3);
- }
-
- if (this.tileArray[row][col].selected) {
- if (this.tileArray[row][col].entityType == EntityType.NULL) {
- g2d.setColor(YELLOW);
- g2d.fillRect(x+len/3, y+len/3, len/3, len/3);
- }
- }
-
- if (this.tileArray[row][col].attack) {
- g2d.setColor(ORANGE);
- g2d.setStroke(new BasicStroke(this.len/6));
- g2d.drawRect(x+len/4, y+len/4, len*2/4, len*2/4);
- }
- }
- }
-
- }
-
- public void mousePressed(MouseEvent e) {}
- public void mouseReleased(MouseEvent e) {}
- public void mouseEntered(MouseEvent e) {}
- public void mouseMoved(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
-
- if (attackMode) {
- for (int row = 0; row < width; row++) {
- for (int col = 0; col < width; col++) {
- this.tileArray[row][col].attack = false;
- if (
- x > this.tileArray[row][col].x
- && x < this.tileArray[row][col].x
- + this.tileArray[row][col].len
- && y > this.tileArray[row][col].y
- && y < this.tileArray[row][col].y
- + this.tileArray[row][col].len
- ) {
- this.tileArray[row][col].attack = true;
- }
- }
- }
- }
- this.repaint();
- }
- public void mouseExited(MouseEvent e) {}
- public void mouseDragged(MouseEvent e) {}
-
- public void mouseClicked(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
- int bar = this.size/20;
- boolean stop = false;
- this.miss = false;
-
- if (
- x > 0
- && x < (bar-bar/10)*3
- && y > this.size-bar
- && y < this.size
- ) {
- this.action = false;
- } else if (
- x > (bar-bar/10)*3
- && x < (bar-bar/10)*6
- && y > this.size-bar
- && y < this.size
- ) {
- this.attackMode = true;
- this.action = false;
- } else {
- for (int row = 0; row < width; row++) {
- for (int col = 0; col < width; col++) {
- if (
- x > this.tileArray[row][col].x
- && x < this.tileArray[row][col].x
- + this.tileArray[row][col].len
- && y > this.tileArray[row][col].y
- && y < this.tileArray[row][col].y
- + this.tileArray[row][col].len
- ) {
- if (this.selectionMode) {
- if (this.tileArray[row][col].selected) {
- this.tileArray[this.selection[0]][this.selection[1]].entityType = EntityType.NULL;
- this.tileArray[row][col].entityType = EntityType.PLAYER;
- this.selectionMode = false;
- this.action = true;
- }
- } else if (this.attackMode) {
- int dist = (int) Math.sqrt(Math.pow(row - this.selection[0], 2)
- + Math.pow(col - this.selection[1], 2));
- if (rand.nextInt(13) > dist) {
- if (this.tileArray[row][col].entityType == EntityType.ENEMY) {
- this.tileArray[row][col].entityType = EntityType.NULL;
- } else if (this.tileArray[row][col].entityType == EntityType.TREE) {
- this.tileArray[row][col].entityType = EntityType.NULL;
- }
- } else {
- this.miss = true;
- }
- this.tileArray[row][col].attack = false;
- this.attackMode = false;
- } else if (this.tileArray[row][col].entityType == EntityType.PLAYER) {
- this.selectionMode = true;
- this.selection[0] = row;
- this.selection[1] = col;
- for (int srow = -4; srow <= 4; srow++) {
- for (int scol = -4; scol <= 4; scol++) {
- if (Math.abs(srow) + Math.abs(scol) <= 4) {
- try {
- if (this.tileArray[row+srow][col+scol].entityType == EntityType.NULL) {
- this.tileArray[row+srow][col+scol].selected = true;
- }
- } catch (ArrayIndexOutOfBoundsException ex) {}
- }
- }
- }
- }
- }
- }
- }
- if (!selectionMode) {
- for (int row = 0; row < width; row++) {
- for (int col = 0; col < width; col++) {
- this.tileArray[row][col].selected = false;
- }
- }
- }
- }
- this.repaint();
- }
-}
diff --git a/src/Map.java b/src/Map.java
new file mode 100644
index 0000000..031e922
--- /dev/null
+++ b/src/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/Scene.java b/src/Scene.java
new file mode 100644
index 0000000..a2949fd
--- /dev/null
+++ b/src/Scene.java
@@ -0,0 +1,5 @@
+import java.awt.Graphics;
+
+public abstract class Scene {
+ abstract void render(Graphics g);
+}
diff --git a/src/Subconscious.java b/src/Subconscious.java
index dc15964..b63eb23 100644
--- a/src/Subconscious.java
+++ b/src/Subconscious.java
@@ -1,24 +1,79 @@
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
-public class Subconscious {
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Dimension;
- public static final Dimension WINDOW_SIZE = new Dimension(400, 400);
- public Subconscious() {
- JFrame frame = new JFrame("Subconscious");
+public class Subconscious extends JPanel {
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(WINDOW_SIZE);
- frame.setLocationRelativeTo(null);
+ public static final String TITLE = "Subconscious";
- MainPanel mainPanel= new MainPanel();
- frame.add(mainPanel);
+ /* graphics */
+ public JFrame window;
+ // public Graphics dbGraphics; // double buffered graphics
+ // public Image dbImage = null; // double buffered image
+
+ public Scene currentScene;
- frame.setVisible(true);
- }
+ /* game */
+ public boolean gameOver = false;
+ public boolean running = false;
- public static void main(String[] args) {
- Subconscious subconscious = new Subconscious();
- }
+ 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/Tile.java b/src/Tile.java
index 8624f08..cbdeda4 100644
--- a/src/Tile.java
+++ b/src/Tile.java
@@ -1,22 +1,15 @@
public class Tile {
- public int x;
- public int y;
- public int len;
- public TileType tileType = TileType.GRASS;
- public EntityType entityType = EntityType.NULL;
- public boolean selected = false;
- public boolean attack = false;
- public int width;
+ public enum Type {
+ GRASS,
+ };
- public Tile (int row, int col, int window, int width) {
- this.width = width;
- this.calc(row, col, window);
- }
+ public final int x, y;
+ public final Type type;
- public void calc (int row, int col, int window) {
- this.len = (int) (window/(double)this.width);
- this.x = col*len;
- this.y = row*len;
- }
+ public Tile(Type type, int x, int y) {
+ this.type = type;
+ this.x = x;
+ this.y = y;
+ }
}
diff --git a/src/TileType.java b/src/TileType.java
deleted file mode 100644
index 82a5b5b..0000000
--- a/src/TileType.java
+++ /dev/null
@@ -1,3 +0,0 @@
-public enum TileType {
- GRASS, ROAD, HOUSE, WATER
-}
diff --git a/src/WorldScene.java b/src/WorldScene.java
new file mode 100644
index 0000000..6dff04a
--- /dev/null
+++ b/src/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
+ );
+ }
+ }
+}