From c29a8870d46edd635963d54b3ada87db10352b76 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 28 Jan 2009 13:43:35 -0500 Subject: Removed the moveDirection field from AbstractEvent As direction itself is always the same as moveDirection when moveDirection is needed, it will do fine without having to complicated access modifiers. --- .../gamestate/mapview/event/AbstractEvent.java | 53 +++++++++++++++++----- .../fourpuzzle/gamestate/mapview/event/Event.java | 2 + .../gamestate/mapview/event/HeroEvent.java | 22 +-------- .../gamestate/mapview/event/LayerEvent.java | 22 +-------- 4 files changed, 45 insertions(+), 54 deletions(-) (limited to 'src/com') diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index e5334c8..a0f4e10 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java @@ -40,13 +40,7 @@ public abstract class AbstractEvent implements Event { this.moving = moving; } - /* TODO Remove the moveDirection field. As direction itself is - * always the same as moveDirection when moveDirection is needed, - * it will do fine without having to complicated access modifiers - */ - - protected int moveTimer; - protected Direction moveDirection; + private int moveTimer; public void startMoving(Direction toMove) { setDirection(toMove); @@ -56,7 +50,6 @@ public abstract class AbstractEvent implements Event { setAnimationStep(2); moveTimer = 4; setMoving(true); - moveDirection = toMove; } } @@ -73,16 +66,16 @@ public abstract class AbstractEvent implements Event { setAnimationStep(1); moving = false; - if (moveDirection == Direction.North) + if (getDirection() == Direction.North) { setLocation(getLocation().x,getLocation().y-1); - } else if (moveDirection == Direction.West) + } else if (getDirection() == Direction.West) { setLocation(getLocation().x-1,getLocation().y); - } else if (moveDirection == Direction.South) + } else if (getDirection() == Direction.South) { setLocation(getLocation().x,getLocation().y+1); - } else if (moveDirection == Direction.East) + } else if (getDirection() == Direction.East) { setLocation(getLocation().x+1,getLocation().y); } @@ -119,4 +112,40 @@ public abstract class AbstractEvent implements Event { { this.parentMap = parentMap; } + + public int getRenderX() + { + int x = (getLocation().x * 16) - 4; + + if (isMoving()) + { + if (getDirection() == Direction.West) + { + x -= (4 - moveTimer) * 4; + } else if (getDirection() == Direction.East) + { + x += (4 - moveTimer) * 4; + } + } + + return x; + } + + public int getRenderY() + { + int y = (getLocation().y * 16) - 16; + + if (isMoving()) + { + if (getDirection() == Direction.North) + { + y -= (4 - moveTimer) * 4; + } else if (getDirection() == Direction.South) + { + y += (4 - moveTimer) * 4; + } + } + + return y; + } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index d6219b3..e614167 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java @@ -25,6 +25,8 @@ public interface Event { public void setLocation(int x, int y); public void render(Graphics g); + public int getRenderX(); + public int getRenderY(); public Direction getDirection(); public void setDirection(Direction direction); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index 17140b9..b7a6ec7 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java @@ -32,32 +32,12 @@ public class HeroEvent extends AbstractEvent implements Event { public void render(Graphics g) { - int x = (getLocation().x * 16) - 4; - int y = (getLocation().y * 16) - 16; - - if (isMoving()) - { - if (moveDirection == Direction.North) - { - y -= (4 - moveTimer) * 4; - } else if (moveDirection == Direction.West) - { - x -= (4 - moveTimer) * 4; - } else if (moveDirection == Direction.South) - { - y += (4 - moveTimer) * 4; - } else if (moveDirection == Direction.East) - { - x += (4 - moveTimer) * 4; - } - } - GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); if (!toDraw.getGraphic().equals("blank")) { toDraw.getGraphic().setDirection(direction); toDraw.getGraphic().setAnimationStep(animationStep); - g.drawImage(toDraw.getGraphic().getImage(), x, y, null); + g.drawImage(toDraw.getGraphic().getImage(), getRenderX(), getRenderY(), null); } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 6be72b7..1fac317 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java @@ -77,30 +77,10 @@ public class LayerEvent extends AbstractEvent implements Event { public void render(Graphics g) { - int x = (getLocation().x * 16) - 4; - int y = (getLocation().y * 16) - 16; - - if (isMoving()) - { - if (moveDirection == Direction.North) - { - y -= (4 - moveTimer) * 4; - } else if (moveDirection == Direction.West) - { - x -= (4 - moveTimer) * 4; - } else if (moveDirection == Direction.South) - { - y += (4 - moveTimer) * 4; - } else if (moveDirection == Direction.East) - { - x += (4 - moveTimer) * 4; - } - } - PossibleEvent toDraw = getPossibleEvent(); if (!toDraw.getGraphic().equals(new BlankEventGraphic())) { - g.drawImage(toDraw.getImage(), x, y, null); + g.drawImage(toDraw.getImage(), getRenderX(), getRenderY(), null); } } -- cgit 1.4.1