From 1db6402b9171fc13b377b01d49531659a4e1fc76 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 16 Feb 2009 12:38:08 -0500 Subject: Engine: Abstracted action key Because some people prefer to use the space bar as the action key rather than the enter key, KeyInput now has a method that checks if either is down. Action key requiring conditions use this now instead of manually checking the key. --- src/com/fourisland/fourpuzzle/KeyInput.java | 5 +++++ src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java | 3 +-- src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java | 2 +- .../fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java | 2 +- src/com/fourisland/fourpuzzle/window/MessageWindow.java | 3 +-- 5 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/KeyInput.java b/src/com/fourisland/fourpuzzle/KeyInput.java index 37eda77..910eea9 100644 --- a/src/com/fourisland/fourpuzzle/KeyInput.java +++ b/src/com/fourisland/fourpuzzle/KeyInput.java @@ -57,4 +57,9 @@ public class KeyInput { return key; } + + public boolean isActionDown() + { + return ((key == KeyEvent.VK_ENTER) || (key == KeyEvent.VK_SPACE)); + } } \ No newline at end of file diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index d9b9ea1..e87f80a 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java @@ -15,7 +15,6 @@ import com.fourisland.fourpuzzle.database.Music; import com.fourisland.fourpuzzle.database.Transitions; import com.fourisland.fourpuzzle.util.ObjectLoader; import java.awt.Graphics2D; -import java.awt.event.KeyEvent; /** * @@ -35,7 +34,7 @@ public class GameOverGameState implements GameState { public void processInput(KeyInput key) { - if ((key.getKey() == KeyEvent.VK_ENTER) || (key.getKey() == KeyEvent.VK_SPACE)) + if (key.isActionDown()) { Game.setSaveFile(new SaveFile()); diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index 432d245..d40b3f9 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -48,7 +48,7 @@ public class TitleScreenGameState implements GameState { { if (pt.isElapsed()) { - if (key.getKey() == KeyEvent.VK_ENTER) + if (key.isActionDown()) { Audio.playSound(Database.getSound(Sound.Selection)); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 1213b0c..68e611b 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -120,7 +120,7 @@ public class MapViewGameState implements GameState { } } - if ((key.getKey() == KeyEvent.VK_ENTER) || (key.getKey() == KeyEvent.VK_SPACE)) + if (key.isActionDown()) { for (LayerEvent ev : currentMap.getEvents()) { diff --git a/src/com/fourisland/fourpuzzle/window/MessageWindow.java b/src/com/fourisland/fourpuzzle/window/MessageWindow.java index 413805d..0057ca3 100644 --- a/src/com/fourisland/fourpuzzle/window/MessageWindow.java +++ b/src/com/fourisland/fourpuzzle/window/MessageWindow.java @@ -16,7 +16,6 @@ import com.fourisland.fourpuzzle.util.Renderable; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.TexturePaint; -import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; @@ -65,7 +64,7 @@ public class MessageWindow implements Renderable { Inputable in = new Inputable() { public void processInput(KeyInput key) { - if ((key.getKey() == KeyEvent.VK_ENTER) || (key.getKey() == KeyEvent.VK_SPACE)) + if (key.isActionDown()) { if (mw.pushEnter()) { -- cgit 1.4.1