aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/Subconscious.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/Subconscious.java')
-rw-r--r--src/main/java/Subconscious.java23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/main/java/Subconscious.java b/src/main/java/Subconscious.java
index 3e66800..d462385 100644
--- a/src/main/java/Subconscious.java
+++ b/src/main/java/Subconscious.java
@@ -42,21 +42,23 @@ public class Subconscious
public Subconscious() {
createWindow();
+ // setup component
+ addMouseListener(this);
+ addKeyListener(this);
+ addComponentListener(this);
setFocusable(true);
requestFocus();
// TODO remove demo
currentScene = new WorldScene(new Dimension(200, 200), 50);
- addMouseListener(this);
- addKeyListener(this);
- addComponentListener(this);
}
private void createWindow() {
window = new JFrame(TITLE);
window.setSize(new Dimension(800, 600));
window.setMinimumSize(getSize());
- window.setLocationRelativeTo(null); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.add(this);
+ window.setLocationRelativeTo(null); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ window.add(this);
}
/* game logic */
@@ -99,19 +101,15 @@ public class Subconscious
while (running) {
gameLoop();
gameRender();
- repaint();
-
+ repaint();
// could be better with NanoSeconds, but this is
// probably enough for this
afterTime = System.currentTimeMillis();
sleepTime = RENDER_PERIOD_MS - (beforeTime - afterTime);
try {
- // TODO replace with correct timing
Thread.sleep(sleepTime);
- } catch (InterruptedException ex) {
- //
- }
+ } catch (InterruptedException ex) {}
beforeTime = System.currentTimeMillis();
}
@@ -127,7 +125,7 @@ public class Subconscious
g.drawImage(dbImage, 0, 0, null);
}
- Toolkit.getDefaultToolkit().sync();
+ Toolkit.getDefaultToolkit().sync(); // needed on linux
g.dispose();
}
@@ -137,8 +135,7 @@ public class Subconscious
@Override public void mouseEntered(MouseEvent e) {}
@Override public void mouseExited(MouseEvent e) {}
@Override public void mouseClicked(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
+ currentScene.mouseClicked(e.getX(), e.getY());
}
@Override public void keyPressed(KeyEvent e) {}