summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-24 19:53:58 +0100
committerNao Pross <naopross@thearcway.org>2018-11-24 19:53:58 +0100
commitaab49eed1dc38f3f349ef180d5c5fd3b6ccb9023 (patch)
tree4923737221151b8af95457bc784eb45eca4f616a /src
parentAdd simple PerfView widget to show the deltaTime (diff)
downloadSubconscious-java-aab49eed1dc38f3f349ef180d5c5fd3b6ccb9023.tar.gz
Subconscious-java-aab49eed1dc38f3f349ef180d5c5fd3b6ccb9023.zip
Rename MenuScene to MainMenuScene and minor code cleanup
Diffstat (limited to '')
-rw-r--r--src/subconscious/Actor.java9
-rw-r--r--src/subconscious/Map.java17
-rw-r--r--src/subconscious/graphics/GameWindow.java19
-rw-r--r--src/subconscious/graphics/MainMenuScene.java (renamed from src/subconscious/graphics/MenuScene.java)6
-rw-r--r--src/subconscious/graphics/MapScene.java8
-rw-r--r--src/subconscious/graphics/Scene.java7
-rw-r--r--src/subconscious/graphics/widget/Button.java1
-rw-r--r--src/subconscious/graphics/widget/Dynamic.java4
-rw-r--r--src/subconscious/graphics/widget/PerfView.java5
-rw-r--r--src/subconscious/graphics/widget/Widget.java1
10 files changed, 29 insertions, 48 deletions
diff --git a/src/subconscious/Actor.java b/src/subconscious/Actor.java
index 8280fe8..38e83ff 100644
--- a/src/subconscious/Actor.java
+++ b/src/subconscious/Actor.java
@@ -3,7 +3,7 @@ package subconscious;
public class Actor {
private final String name;
- // TODO: enemy should not be binary (ex clans / groups / factions)
+ // TODO: enemy should not be binary (ex clans / groups / factions)
private boolean isEnemy;
private int hp;
@@ -21,8 +21,8 @@ public class Actor {
private Weapon weapon;
private int actionsLeft;
// TODO: make final
- private int actions = 2;
- // TODO: make bonus / power-ups structure
+ private final int actions = 2;
+ // TODO: make bonus / power-ups structure => use EnumSet
public Actor(String name, int hp, boolean isEnemy, int agility) {
this.name = name;
@@ -32,8 +32,7 @@ public class Actor {
this.skills = new SkillSet();
this.skills.agility = agility;
- // TODO: puch should have infinite durability
- this.weapon = new Weapon("fist", 1, 1, 10000000);
+ this.weapon = new Weapon("fist", 1, 1, -1);
this.resetActions();
}
diff --git a/src/subconscious/Map.java b/src/subconscious/Map.java
index 4402790..21b9ae5 100644
--- a/src/subconscious/Map.java
+++ b/src/subconscious/Map.java
@@ -77,23 +77,6 @@ public class Map {
return out;
}
- public void update(ArrayList<Actor> actorsList, Tile[] tileGrid) {
- // TODO: if this is needed for something, implement copy constructors for Actor and Tile
- // and delete this code
- for (Actor actor : actorsList) {
- Actor newActor = new Actor(actor.getName(), actor.getHP(), actor.isEnemy(), actor.getSkills().agility);
- newActor.place(actor.getX(), actor.getY());
- this.actors.add(newActor);
- }
-
- for (int x = 0; x < this.size.width; x++) {
- for (int y = 0; y < this.size.height; y++) {
- Tile.Type oldTileType = tileGrid[x * this.size.width + y].getType();
- this.grid[x * this.size.width + y] = new Tile(oldTileType, x, y);
- }
- }
- }
-
// TODO: refractor to resetActorActions();
public void resetActors() {
for (Actor actor : this.actors) {
diff --git a/src/subconscious/graphics/GameWindow.java b/src/subconscious/graphics/GameWindow.java
index eb360f5..b26d6a4 100644
--- a/src/subconscious/graphics/GameWindow.java
+++ b/src/subconscious/graphics/GameWindow.java
@@ -32,14 +32,12 @@ public class GameWindow extends Frame implements WindowListener {
private volatile Game game;
- // TODO: remove map editor, start directly on Battle mode
public GameWindow(Game g) {
super("Subconscious");
-
+
this.game = g;
// set up JFrame
- // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WINDOW_SIZE);
this.setPreferredSize(WINDOW_SIZE);
this.setLocationRelativeTo(null);
@@ -61,7 +59,7 @@ public class GameWindow extends Frame implements WindowListener {
// ovserver of this.game
private void loop() {
// load the first scene
- this.loadScene(new MenuScene(this.game));
+ this.loadScene(new MainMenuScene(this.game));
while (this.game.isRunning()) {
// check if the scene has requested a new scene
@@ -80,9 +78,7 @@ public class GameWindow extends Frame implements WindowListener {
Game.State newState = this.game.getState();
Game.State lastState = this.game.getLastState();
- if (lastState == newState) {
- throw new IllegalStateException();
- }
+ assert newState != lastState;
// MAIN_MENU is always the first scene
if (newState == Game.State.MAIN_MENU) {
@@ -130,12 +126,6 @@ public class GameWindow extends Frame implements WindowListener {
this.unloadScene();
}
- // private void unloadScenes(int count) {
- // for (int i = 0; i < count; i++) {
- // this.unloadScene();
- // }
- // }
-
private void unloadScene() {
// close old scene
this.scene.stop();
@@ -167,6 +157,9 @@ public class GameWindow extends Frame implements WindowListener {
this.setVisible(false);
this.dispose();
+ // check that all scene threads have been killed
+ assert this.loadedScenes.empty();
+
System.exit(0);
}
diff --git a/src/subconscious/graphics/MenuScene.java b/src/subconscious/graphics/MainMenuScene.java
index 32d9569..9526b17 100644
--- a/src/subconscious/graphics/MenuScene.java
+++ b/src/subconscious/graphics/MainMenuScene.java
@@ -14,13 +14,13 @@ import java.awt.event.ActionEvent;
@SuppressWarnings("serial")
-public class MenuScene extends Scene implements ActionListener {
+public class MainMenuScene extends Scene implements ActionListener {
- public MenuScene(Game g) {
+ public MainMenuScene(Game g) {
this(g, "");
}
- public MenuScene(Game g, String uniqueName) {
+ public MainMenuScene(Game g, String uniqueName) {
super(g, uniqueName);
this.game = g;
diff --git a/src/subconscious/graphics/MapScene.java b/src/subconscious/graphics/MapScene.java
index 149d03d..77e0c92 100644
--- a/src/subconscious/graphics/MapScene.java
+++ b/src/subconscious/graphics/MapScene.java
@@ -57,13 +57,7 @@ public abstract class MapScene extends Scene {
this.game = g;
this.map = this.game.getMap();
- if (this.canvasSize.width < this.canvasSize.height) {
- this.shorterCanvasLenght = this.canvasSize.width;
- } else {
- this.shorterCanvasLenght = this.canvasSize.height;
- }
-
- this.tileSize = this.shorterCanvasLenght / 10;
+ this.updateCanvasSize(this.canvasSize);
}
protected void renderTiles(Graphics2D g) {
diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java
index 466aa03..50ef323 100644
--- a/src/subconscious/graphics/Scene.java
+++ b/src/subconscious/graphics/Scene.java
@@ -195,7 +195,7 @@ public abstract class Scene extends Panel
// initialize canvas buffer
// the condition checks because the while above can be interrupted by
// changing this.running
- // TODO: this is because of the MenuScene which hides the canvas
+ // TODO: this is because of the MainMenuScene which hides the canvas
// when the scene will be fixed this if can be removed
if (this.canvas.isDisplayable()) {
this.canvas.createBufferStrategy(2);
@@ -244,8 +244,8 @@ public abstract class Scene extends Panel
} else {
try {
Thread.sleep((this.DESIRED_DELTA_LOOP - deltaLoop)/(1000*1000));
- } catch (InterruptedException e ) {
-
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
}
}
@@ -304,6 +304,7 @@ public abstract class Scene extends Panel
/* mouse listener */
@Override
public void mouseClicked(MouseEvent e) {
+ // could be cached
for (Widget w : this.widgets) {
if (w instanceof Clickable) {
((Clickable) w).mouseClick(e.getPoint());
diff --git a/src/subconscious/graphics/widget/Button.java b/src/subconscious/graphics/widget/Button.java
index 47ba810..ea774b9 100644
--- a/src/subconscious/graphics/widget/Button.java
+++ b/src/subconscious/graphics/widget/Button.java
@@ -3,6 +3,7 @@ package subconscious.graphics.widget;
import java.awt.Graphics2D;
import java.awt.Point;
+
public class Button extends Widget implements Clickable {
public Button(String uniqueName, int x, int y, int width, int height) {
diff --git a/src/subconscious/graphics/widget/Dynamic.java b/src/subconscious/graphics/widget/Dynamic.java
index ca0029a..dc26305 100644
--- a/src/subconscious/graphics/widget/Dynamic.java
+++ b/src/subconscious/graphics/widget/Dynamic.java
@@ -1,5 +1,9 @@
package subconscious.graphics.widget;
+
+/* Dynamic interface for Widgets
+ * If a Widget is dynamic, it is updated on every tick of the game.
+ */
public interface Dynamic {
public void update(long deltaNanoTime);
} \ No newline at end of file
diff --git a/src/subconscious/graphics/widget/PerfView.java b/src/subconscious/graphics/widget/PerfView.java
index 8aa7c7e..94c68ab 100644
--- a/src/subconscious/graphics/widget/PerfView.java
+++ b/src/subconscious/graphics/widget/PerfView.java
@@ -3,6 +3,11 @@ package subconscious.graphics.widget;
import java.awt.Graphics2D;
+/* PerfView
+ * Simple example implementation that shows the performance of the game,
+ * it was mainly created for debugging, but could be used to show FPS in the
+ * final game.
+ */
public class PerfView extends Widget implements Dynamic {
public static final int WIDTH = 120;
diff --git a/src/subconscious/graphics/widget/Widget.java b/src/subconscious/graphics/widget/Widget.java
index 31edc9a..0a9e5f6 100644
--- a/src/subconscious/graphics/widget/Widget.java
+++ b/src/subconscious/graphics/widget/Widget.java
@@ -3,6 +3,7 @@ package subconscious.graphics.widget;
import java.awt.Graphics2D;
import java.awt.Rectangle;
+
public abstract class Widget {
public final String UNIQUE_NAME;