diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-28 13:43:35 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-28 13:43:35 -0500 |
commit | c29a8870d46edd635963d54b3ada87db10352b76 (patch) | |
tree | 8464d9e0d783d4b16e9729032994dd2a31789277 /src | |
parent | bbc04275a73aec87d83f264fcf760407363d5c5b (diff) | |
download | fourpuzzle-c29a8870d46edd635963d54b3ada87db10352b76.tar.gz fourpuzzle-c29a8870d46edd635963d54b3ada87db10352b76.tar.bz2 fourpuzzle-c29a8870d46edd635963d54b3ada87db10352b76.zip |
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.
Diffstat (limited to 'src')
4 files changed, 45 insertions, 54 deletions
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 { | |||
40 | this.moving = moving; | 40 | this.moving = moving; |
41 | } | 41 | } |
42 | 42 | ||
43 | /* TODO Remove the moveDirection field. As direction itself is | 43 | private int moveTimer; |
44 | * always the same as moveDirection when moveDirection is needed, | ||
45 | * it will do fine without having to complicated access modifiers | ||
46 | */ | ||
47 | |||
48 | protected int moveTimer; | ||
49 | protected Direction moveDirection; | ||
50 | public void startMoving(Direction toMove) | 44 | public void startMoving(Direction toMove) |
51 | { | 45 | { |
52 | setDirection(toMove); | 46 | setDirection(toMove); |
@@ -56,7 +50,6 @@ public abstract class AbstractEvent implements Event { | |||
56 | setAnimationStep(2); | 50 | setAnimationStep(2); |
57 | moveTimer = 4; | 51 | moveTimer = 4; |
58 | setMoving(true); | 52 | setMoving(true); |
59 | moveDirection = toMove; | ||
60 | } | 53 | } |
61 | } | 54 | } |
62 | 55 | ||
@@ -73,16 +66,16 @@ public abstract class AbstractEvent implements Event { | |||
73 | setAnimationStep(1); | 66 | setAnimationStep(1); |
74 | moving = false; | 67 | moving = false; |
75 | 68 | ||
76 | if (moveDirection == Direction.North) | 69 | if (getDirection() == Direction.North) |
77 | { | 70 | { |
78 | setLocation(getLocation().x,getLocation().y-1); | 71 | setLocation(getLocation().x,getLocation().y-1); |
79 | } else if (moveDirection == Direction.West) | 72 | } else if (getDirection() == Direction.West) |
80 | { | 73 | { |
81 | setLocation(getLocation().x-1,getLocation().y); | 74 | setLocation(getLocation().x-1,getLocation().y); |
82 | } else if (moveDirection == Direction.South) | 75 | } else if (getDirection() == Direction.South) |
83 | { | 76 | { |
84 | setLocation(getLocation().x,getLocation().y+1); | 77 | setLocation(getLocation().x,getLocation().y+1); |
85 | } else if (moveDirection == Direction.East) | 78 | } else if (getDirection() == Direction.East) |
86 | { | 79 | { |
87 | setLocation(getLocation().x+1,getLocation().y); | 80 | setLocation(getLocation().x+1,getLocation().y); |
88 | } | 81 | } |
@@ -119,4 +112,40 @@ public abstract class AbstractEvent implements Event { | |||
119 | { | 112 | { |
120 | this.parentMap = parentMap; | 113 | this.parentMap = parentMap; |
121 | } | 114 | } |
115 | |||
116 | public int getRenderX() | ||
117 | { | ||
118 | int x = (getLocation().x * 16) - 4; | ||
119 | |||
120 | if (isMoving()) | ||
121 | { | ||
122 | if (getDirection() == Direction.West) | ||
123 | { | ||
124 | x -= (4 - moveTimer) * 4; | ||
125 | } else if (getDirection() == Direction.East) | ||
126 | { | ||
127 | x += (4 - moveTimer) * 4; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return x; | ||
132 | } | ||
133 | |||
134 | public int getRenderY() | ||
135 | { | ||
136 | int y = (getLocation().y * 16) - 16; | ||
137 | |||
138 | if (isMoving()) | ||
139 | { | ||
140 | if (getDirection() == Direction.North) | ||
141 | { | ||
142 | y -= (4 - moveTimer) * 4; | ||
143 | } else if (getDirection() == Direction.South) | ||
144 | { | ||
145 | y += (4 - moveTimer) * 4; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | return y; | ||
150 | } | ||
122 | } | 151 | } |
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 { | |||
25 | public void setLocation(int x, int y); | 25 | public void setLocation(int x, int y); |
26 | 26 | ||
27 | public void render(Graphics g); | 27 | public void render(Graphics g); |
28 | public int getRenderX(); | ||
29 | public int getRenderY(); | ||
28 | 30 | ||
29 | public Direction getDirection(); | 31 | public Direction getDirection(); |
30 | public void setDirection(Direction direction); | 32 | 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 { | |||
32 | 32 | ||
33 | public void render(Graphics g) | 33 | public void render(Graphics g) |
34 | { | 34 | { |
35 | int x = (getLocation().x * 16) - 4; | ||
36 | int y = (getLocation().y * 16) - 16; | ||
37 | |||
38 | if (isMoving()) | ||
39 | { | ||
40 | if (moveDirection == Direction.North) | ||
41 | { | ||
42 | y -= (4 - moveTimer) * 4; | ||
43 | } else if (moveDirection == Direction.West) | ||
44 | { | ||
45 | x -= (4 - moveTimer) * 4; | ||
46 | } else if (moveDirection == Direction.South) | ||
47 | { | ||
48 | y += (4 - moveTimer) * 4; | ||
49 | } else if (moveDirection == Direction.East) | ||
50 | { | ||
51 | x += (4 - moveTimer) * 4; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); | 35 | GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); |
56 | if (!toDraw.getGraphic().equals("blank")) | 36 | if (!toDraw.getGraphic().equals("blank")) |
57 | { | 37 | { |
58 | toDraw.getGraphic().setDirection(direction); | 38 | toDraw.getGraphic().setDirection(direction); |
59 | toDraw.getGraphic().setAnimationStep(animationStep); | 39 | toDraw.getGraphic().setAnimationStep(animationStep); |
60 | g.drawImage(toDraw.getGraphic().getImage(), x, y, null); | 40 | g.drawImage(toDraw.getGraphic().getImage(), getRenderX(), getRenderY(), null); |
61 | } | 41 | } |
62 | } | 42 | } |
63 | 43 | ||
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 { | |||
77 | 77 | ||
78 | public void render(Graphics g) | 78 | public void render(Graphics g) |
79 | { | 79 | { |
80 | int x = (getLocation().x * 16) - 4; | ||
81 | int y = (getLocation().y * 16) - 16; | ||
82 | |||
83 | if (isMoving()) | ||
84 | { | ||
85 | if (moveDirection == Direction.North) | ||
86 | { | ||
87 | y -= (4 - moveTimer) * 4; | ||
88 | } else if (moveDirection == Direction.West) | ||
89 | { | ||
90 | x -= (4 - moveTimer) * 4; | ||
91 | } else if (moveDirection == Direction.South) | ||
92 | { | ||
93 | y += (4 - moveTimer) * 4; | ||
94 | } else if (moveDirection == Direction.East) | ||
95 | { | ||
96 | x += (4 - moveTimer) * 4; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | PossibleEvent toDraw = getPossibleEvent(); | 80 | PossibleEvent toDraw = getPossibleEvent(); |
101 | if (!toDraw.getGraphic().equals(new BlankEventGraphic())) | 81 | if (!toDraw.getGraphic().equals(new BlankEventGraphic())) |
102 | { | 82 | { |
103 | g.drawImage(toDraw.getImage(), x, y, null); | 83 | g.drawImage(toDraw.getImage(), getRenderX(), getRenderY(), null); |
104 | } | 84 | } |
105 | } | 85 | } |
106 | 86 | ||