From 0a37b19bc1afc4369c7e423bb07f432196273bc9 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 3 Feb 2009 16:45:25 -0500 Subject: Added support for OnHeroTouch events Also fixed two bugs: 1. In the condition where a StepMoveEvent is called upon an Event whose animation type does not allow them to turn in the desired direction, they will move in the direction they are already in and walk off the screen while doing so. This was fixed by checking (after the event's direction has been set during the startMoving() process) that the event was able to face in the correct direction. 2. If a StepMoveEvent was enacted on an event that was already moving, it would be skipped. This has been fixed by waiting for the desired event to complete moving at the start of MoveEventThread. --- .../gamestate/mapview/MapViewGameState.java | 34 +++++++++++++++++++++- .../gamestate/mapview/event/AbstractEvent.java | 5 ++++ .../gamestate/mapview/event/LayerEvent.java | 1 - .../mapview/event/specialmove/MoveEventThread.java | 9 ++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index c4194d9..9c66a9c 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -106,7 +106,22 @@ public class MapViewGameState implements GameState { if (letsMove) { - hero.startMoving(toMove); + if (!hero.startMoving(toMove)) + { + for (LayerEvent ev : currentMap.getEvents()) + { + if (ev.getCalltime() == EventCallTime.OnHeroTouch) + { + if (ev.getLayer() == Layer.Middle) + { + if (Functions.isFacing(hero, ev)) + { + ev.getCallback().activate(ev.getCalltime()); + } + } + } + } + } } if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) @@ -143,6 +158,23 @@ public class MapViewGameState implements GameState { if (hero.isMoving()) { hero.processMoving(); + + if (!hero.isMoving()) + { + for (LayerEvent ev : currentMap.getEvents()) + { + if (ev.getCalltime() == EventCallTime.OnHeroTouch) + { + if (ev.getLayer() != Layer.Middle) + { + if (hero.getLocation().equals(ev.getLocation())) + { + ev.getCallback().activate(ev.getCalltime()); + } + } + } + } + } } for (LayerEvent ev : currentMap.getEvents()) diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index 7e8dd0d..483ce49 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java @@ -50,6 +50,11 @@ public abstract class AbstractEvent implements Event { setDirection(toMove); + if (getDirection() != toMove) + { + return false; + } + if (!getParentMap().checkForCollision(this, toMove)) { setAnimationStep(2); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index b31705d..530af6f 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java @@ -9,7 +9,6 @@ import com.fourisland.fourpuzzle.Layer; import java.awt.Graphics; import java.util.ArrayList; import com.fourisland.fourpuzzle.Direction; -import com.fourisland.fourpuzzle.gamestate.mapview.Map; import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic; /** diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java index 2ee4dca..df4f4ee 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java @@ -36,6 +36,15 @@ public class MoveEventThread implements Runnable { public void run() { + while (ev.isMoving()) + { + try { + Thread.sleep(2); + } catch (InterruptedException ex) { + Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); + } + } + events.add(ev); MoveEventThread.countMoveEventThreads++; -- cgit 1.4.1