diff options
author | Nao Pross <naopross@thearcway.org> | 2018-02-10 19:40:08 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-02-10 19:40:08 +0100 |
commit | 221aec874940378f5d8b6411e8b5c141816d5a1e (patch) | |
tree | 4ca7cb54583d50666d4e17230a505739813a3ab5 /src/main/java/Subconscious.java | |
parent | Add missing @Override(s) (diff) | |
download | Subconscious-old-221aec874940378f5d8b6411e8b5c141816d5a1e.tar.gz Subconscious-old-221aec874940378f5d8b6411e8b5c141816d5a1e.zip |
Add simple mouseclick listener to scenes
Diffstat (limited to '')
-rw-r--r-- | src/main/java/Subconscious.java | 23 |
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) {} |