diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-27 15:22:34 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-27 15:22:34 -0500 |
commit | bbc04275a73aec87d83f264fcf760407363d5c5b (patch) | |
tree | 9f82a1cb37c4b5e8d8bc111b51643ffcf5ec3631 /src/com/fourisland | |
parent | 396c5fd662a3b0b21820383d69706d512d16370a (diff) | |
download | fourpuzzle-bbc04275a73aec87d83f264fcf760407363d5c5b.tar.gz fourpuzzle-bbc04275a73aec87d83f264fcf760407363d5c5b.tar.bz2 fourpuzzle-bbc04275a73aec87d83f264fcf760407363d5c5b.zip |
Added parentMap data to Event
StepMoveEvent has an issue where an event could walk off the screen under its influence because it preformed no collision checking, due to the fact that the parent map had to be accessable to preform collision checking. Now, both event styles (unified with an AbstractEvent class that handles functions common to both styles) carries information about its parent map, provided by EventList which is in turn provided by the parent map itself.
Diffstat (limited to 'src/com/fourisland')
7 files changed, 195 insertions, 182 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index 62270bf..bc0073e 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | |||
@@ -6,7 +6,9 @@ | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview; | 6 | package com.fourisland.fourpuzzle.gamestate.mapview; |
7 | 7 | ||
8 | import com.fourisland.fourpuzzle.*; | 8 | import com.fourisland.fourpuzzle.*; |
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; | 10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; |
11 | import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; | ||
10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; | 12 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; |
11 | import java.awt.Dimension; | 13 | import java.awt.Dimension; |
12 | import java.util.HashMap; | 14 | import java.util.HashMap; |
@@ -41,7 +43,7 @@ public abstract class Map { | |||
41 | } | 43 | } |
42 | } | 44 | } |
43 | 45 | ||
44 | private EventList events = new EventList(); | 46 | private EventList events = new EventList(this); |
45 | public EventList getEvents() | 47 | public EventList getEvents() |
46 | { | 48 | { |
47 | return events; | 49 | return events; |
@@ -59,8 +61,11 @@ public abstract class Map { | |||
59 | return null; | 61 | return null; |
60 | } | 62 | } |
61 | 63 | ||
62 | public boolean checkForCollision(int x, int y, Direction toMove) | 64 | public boolean checkForCollision(Event ev, Direction toMove) |
63 | { | 65 | { |
66 | int x = ev.getLocation().x; | ||
67 | int y = ev.getLocation().y; | ||
68 | |||
64 | if ((toMove == Direction.North) && (y == 0)) | 69 | if ((toMove == Direction.North) && (y == 0)) |
65 | { | 70 | { |
66 | return true; | 71 | return true; |
@@ -75,6 +80,11 @@ public abstract class Map { | |||
75 | return true; | 80 | return true; |
76 | } | 81 | } |
77 | 82 | ||
83 | if ((ev instanceof HeroEvent) && (((MapViewGameState) Game.getGameState()).debugWalkthrough)) | ||
84 | { | ||
85 | return false; | ||
86 | } | ||
87 | |||
78 | if ((toMove == Direction.North) && (checkForEventCollision(x, y-1))) | 88 | if ((toMove == Direction.North) && (checkForEventCollision(x, y-1))) |
79 | { | 89 | { |
80 | return true; | 90 | return true; |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 48653c0..0604dd0 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java | |||
@@ -29,7 +29,7 @@ import java.util.logging.Logger; | |||
29 | */ | 29 | */ |
30 | public class MapViewGameState implements GameState { | 30 | public class MapViewGameState implements GameState { |
31 | 31 | ||
32 | boolean debugWalkthrough = false; | 32 | public boolean debugWalkthrough = false; |
33 | boolean processInput = true; | 33 | boolean processInput = true; |
34 | Map currentMap; | 34 | Map currentMap; |
35 | 35 | ||
@@ -99,12 +99,7 @@ public class MapViewGameState implements GameState { | |||
99 | 99 | ||
100 | if (letsMove) | 100 | if (letsMove) |
101 | { | 101 | { |
102 | if (debugWalkthrough || (!currentMap.checkForCollision(hero.getLocation().x, hero.getLocation().y, toMove))) | 102 | hero.startMoving(toMove); |
103 | { | ||
104 | hero.startMoving(toMove); | ||
105 | } else { | ||
106 | hero.setDirection(toMove); | ||
107 | } | ||
108 | } | 103 | } |
109 | 104 | ||
110 | if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) | 105 | if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java new file mode 100644 index 0000000..e5334c8 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java | |||
@@ -0,0 +1,122 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | ||
10 | import com.fourisland.fourpuzzle.util.Functions; | ||
11 | import java.awt.Point; | ||
12 | |||
13 | /** | ||
14 | * | ||
15 | * @author hatkirby | ||
16 | */ | ||
17 | public abstract class AbstractEvent implements Event { | ||
18 | |||
19 | private Point location = new Point(); | ||
20 | public Point getLocation() | ||
21 | { | ||
22 | return location; | ||
23 | } | ||
24 | public void setLocation(Point location) | ||
25 | { | ||
26 | this.location = location; | ||
27 | } | ||
28 | public void setLocation(int x, int y) | ||
29 | { | ||
30 | location.setLocation(x, y); | ||
31 | } | ||
32 | |||
33 | private boolean moving = false; | ||
34 | public boolean isMoving() | ||
35 | { | ||
36 | return moving; | ||
37 | } | ||
38 | public void setMoving(boolean moving) | ||
39 | { | ||
40 | this.moving = moving; | ||
41 | } | ||
42 | |||
43 | /* TODO Remove the moveDirection field. As direction itself is | ||
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) | ||
51 | { | ||
52 | setDirection(toMove); | ||
53 | |||
54 | if (!getParentMap().checkForCollision(this, toMove)) | ||
55 | { | ||
56 | setAnimationStep(2); | ||
57 | moveTimer = 4; | ||
58 | setMoving(true); | ||
59 | moveDirection = toMove; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | public void processMoving() | ||
64 | { | ||
65 | if (isMoving()) | ||
66 | { | ||
67 | moveTimer--; | ||
68 | if (moveTimer == 2) | ||
69 | { | ||
70 | setAnimationStep(0); | ||
71 | } else if (moveTimer == 0) | ||
72 | { | ||
73 | setAnimationStep(1); | ||
74 | moving = false; | ||
75 | |||
76 | if (moveDirection == Direction.North) | ||
77 | { | ||
78 | setLocation(getLocation().x,getLocation().y-1); | ||
79 | } else if (moveDirection == Direction.West) | ||
80 | { | ||
81 | setLocation(getLocation().x-1,getLocation().y); | ||
82 | } else if (moveDirection == Direction.South) | ||
83 | { | ||
84 | setLocation(getLocation().x,getLocation().y+1); | ||
85 | } else if (moveDirection == Direction.East) | ||
86 | { | ||
87 | setLocation(getLocation().x+1,getLocation().y); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | public boolean isOccupyingSpace(int x, int y) | ||
94 | { | ||
95 | if (getLocation().equals(new Point(x,y))) | ||
96 | { | ||
97 | return true; | ||
98 | } | ||
99 | |||
100 | if (Functions.isMovingTo(this, x, y)) | ||
101 | { | ||
102 | return true; | ||
103 | } | ||
104 | |||
105 | return false; | ||
106 | } | ||
107 | |||
108 | private Map parentMap = null; | ||
109 | public Map getParentMap() | ||
110 | { | ||
111 | if (parentMap == null) | ||
112 | { | ||
113 | throw new NullPointerException(); | ||
114 | } | ||
115 | |||
116 | return parentMap; | ||
117 | } | ||
118 | public void setParentMap(Map parentMap) | ||
119 | { | ||
120 | this.parentMap = parentMap; | ||
121 | } | ||
122 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index 71b507f..d6219b3 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java | |||
@@ -7,6 +7,7 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; | |||
7 | 7 | ||
8 | import com.fourisland.fourpuzzle.Direction; | 8 | import com.fourisland.fourpuzzle.Direction; |
9 | import com.fourisland.fourpuzzle.Layer; | 9 | import com.fourisland.fourpuzzle.Layer; |
10 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | ||
10 | import java.awt.Graphics; | 11 | import java.awt.Graphics; |
11 | import java.awt.Point; | 12 | import java.awt.Point; |
12 | 13 | ||
@@ -34,4 +35,10 @@ public interface Event { | |||
34 | public Layer getLayer(); | 35 | public Layer getLayer(); |
35 | 36 | ||
36 | public boolean isOccupyingSpace(int x, int y); | 37 | public boolean isOccupyingSpace(int x, int y); |
38 | |||
39 | public void setAnimationStep(int animStep); | ||
40 | public int getAnimationStep(); | ||
41 | |||
42 | public void setParentMap(Map parentMap); | ||
43 | public Map getParentMap(); | ||
37 | } | 44 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java index a10aadc..8de4e3c 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java | |||
@@ -5,6 +5,7 @@ | |||
5 | 5 | ||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; |
7 | 7 | ||
8 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | ||
8 | import java.util.Vector; | 9 | import java.util.Vector; |
9 | 10 | ||
10 | /** | 11 | /** |
@@ -13,6 +14,11 @@ import java.util.Vector; | |||
13 | */ | 14 | */ |
14 | public class EventList extends Vector<LayerEvent> { | 15 | public class EventList extends Vector<LayerEvent> { |
15 | 16 | ||
17 | public EventList(Map parentMap) | ||
18 | { | ||
19 | setParentMap(parentMap); | ||
20 | } | ||
21 | |||
16 | @Override | 22 | @Override |
17 | public boolean add(LayerEvent o) | 23 | public boolean add(LayerEvent o) |
18 | { | 24 | { |
@@ -27,7 +33,7 @@ public class EventList extends Vector<LayerEvent> { | |||
27 | return false; | 33 | return false; |
28 | } | 34 | } |
29 | 35 | ||
30 | for (Event ev : this) | 36 | for (LayerEvent ev : this) |
31 | { | 37 | { |
32 | if (ev.getLabel().equals(o.getLabel())) | 38 | if (ev.getLabel().equals(o.getLabel())) |
33 | { | 39 | { |
@@ -36,7 +42,27 @@ public class EventList extends Vector<LayerEvent> { | |||
36 | } | 42 | } |
37 | } | 43 | } |
38 | 44 | ||
45 | if (parentMap != null) | ||
46 | { | ||
47 | o.setParentMap(parentMap); | ||
48 | } | ||
49 | |||
39 | return super.add(o); | 50 | return super.add(o); |
40 | } | 51 | } |
52 | |||
53 | private Map parentMap = null; | ||
54 | public Map getParentMap() | ||
55 | { | ||
56 | return parentMap; | ||
57 | } | ||
58 | public void setParentMap(Map parentMap) | ||
59 | { | ||
60 | this.parentMap = parentMap; | ||
61 | |||
62 | for (LayerEvent ev : this) | ||
63 | { | ||
64 | ev.setParentMap(parentMap); | ||
65 | } | ||
66 | } | ||
41 | 67 | ||
42 | } | 68 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index d488e7d..17140b9 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java | |||
@@ -11,18 +11,18 @@ import java.awt.Point; | |||
11 | import com.fourisland.fourpuzzle.Direction; | 11 | import com.fourisland.fourpuzzle.Direction; |
12 | import com.fourisland.fourpuzzle.Game; | 12 | import com.fourisland.fourpuzzle.Game; |
13 | import com.fourisland.fourpuzzle.GameCharacter; | 13 | import com.fourisland.fourpuzzle.GameCharacter; |
14 | import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; | 14 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; |
15 | import com.fourisland.fourpuzzle.util.Functions; | 15 | import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * | 18 | * |
19 | * @author hatkirby | 19 | * @author hatkirby |
20 | */ | 20 | */ |
21 | public class HeroEvent implements Event { | 21 | public class HeroEvent extends AbstractEvent implements Event { |
22 | 22 | ||
23 | public HeroEvent() | 23 | public HeroEvent() |
24 | { | 24 | { |
25 | location = new Point(); | 25 | setLocation(new Point()); |
26 | } | 26 | } |
27 | 27 | ||
28 | public String getLabel() | 28 | public String getLabel() |
@@ -30,26 +30,12 @@ public class HeroEvent implements Event { | |||
30 | return "Hero"; | 30 | return "Hero"; |
31 | } | 31 | } |
32 | 32 | ||
33 | private Point location; | ||
34 | public Point getLocation() | ||
35 | { | ||
36 | return location; | ||
37 | } | ||
38 | public void setLocation(Point location) | ||
39 | { | ||
40 | this.location = location; | ||
41 | } | ||
42 | public void setLocation(int x, int y) | ||
43 | { | ||
44 | location.setLocation(x, y); | ||
45 | } | ||
46 | |||
47 | public void render(Graphics g) | 33 | public void render(Graphics g) |
48 | { | 34 | { |
49 | int x = (location.x * 16) - 4; | 35 | int x = (getLocation().x * 16) - 4; |
50 | int y = (location.y * 16) - 16; | 36 | int y = (getLocation().y * 16) - 16; |
51 | 37 | ||
52 | if (moving) | 38 | if (isMoving()) |
53 | { | 39 | { |
54 | if (moveDirection == Direction.North) | 40 | if (moveDirection == Direction.North) |
55 | { | 41 | { |
@@ -75,57 +61,6 @@ public class HeroEvent implements Event { | |||
75 | } | 61 | } |
76 | } | 62 | } |
77 | 63 | ||
78 | |||
79 | private boolean moving = false; | ||
80 | public boolean isMoving() | ||
81 | { | ||
82 | return moving; | ||
83 | } | ||
84 | public void setMoving(boolean moving) | ||
85 | { | ||
86 | this.moving = moving; | ||
87 | } | ||
88 | |||
89 | private int moveTimer; | ||
90 | private Direction moveDirection; | ||
91 | public void startMoving(Direction toMove) | ||
92 | { | ||
93 | setDirection(toMove); | ||
94 | setAnimationStep(2); | ||
95 | moveTimer = 4; | ||
96 | moving = true; | ||
97 | moveDirection = toMove; | ||
98 | } | ||
99 | public void processMoving() | ||
100 | { | ||
101 | if (moving) | ||
102 | { | ||
103 | moveTimer--; | ||
104 | if (moveTimer == 2) | ||
105 | { | ||
106 | setAnimationStep(0); | ||
107 | } else if (moveTimer == 0) | ||
108 | { | ||
109 | setAnimationStep(1); | ||
110 | moving = false; | ||
111 | |||
112 | if (moveDirection == Direction.North) | ||
113 | { | ||
114 | setLocation(getLocation().x,getLocation().y-1); | ||
115 | } else if (moveDirection == Direction.West) | ||
116 | { | ||
117 | setLocation(getLocation().x-1,getLocation().y); | ||
118 | } else if (moveDirection == Direction.South) | ||
119 | { | ||
120 | setLocation(getLocation().x,getLocation().y+1); | ||
121 | } else if (moveDirection == Direction.East) | ||
122 | { | ||
123 | setLocation(getLocation().x+1,getLocation().y); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | private Direction direction = Direction.South; | 64 | private Direction direction = Direction.South; |
130 | public Direction getDirection() | 65 | public Direction getDirection() |
131 | { | 66 | { |
@@ -151,19 +86,10 @@ public class HeroEvent implements Event { | |||
151 | return Layer.Middle; | 86 | return Layer.Middle; |
152 | } | 87 | } |
153 | 88 | ||
154 | public boolean isOccupyingSpace(int x, int y) | 89 | @Override |
90 | public Map getParentMap() | ||
155 | { | 91 | { |
156 | if (getLocation().equals(new Point(x,y))) | 92 | return ((MapViewGameState) Game.getGameState()).getCurrentMap(); |
157 | { | ||
158 | return true; | ||
159 | } | ||
160 | |||
161 | if (Functions.isMovingTo(this, x, y)) | ||
162 | { | ||
163 | return true; | ||
164 | } | ||
165 | |||
166 | return false; | ||
167 | } | 93 | } |
168 | 94 | ||
169 | } | 95 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index f42cdf0..6be72b7 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java | |||
@@ -7,17 +7,16 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; | |||
7 | 7 | ||
8 | import com.fourisland.fourpuzzle.Layer; | 8 | import com.fourisland.fourpuzzle.Layer; |
9 | import java.awt.Graphics; | 9 | import java.awt.Graphics; |
10 | import java.awt.Point; | ||
11 | import java.util.ArrayList; | 10 | import java.util.ArrayList; |
12 | import com.fourisland.fourpuzzle.Direction; | 11 | import com.fourisland.fourpuzzle.Direction; |
13 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | 12 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; |
14 | import com.fourisland.fourpuzzle.util.Functions; | 13 | import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic; |
15 | 14 | ||
16 | /** | 15 | /** |
17 | * | 16 | * |
18 | * @author hatkirby | 17 | * @author hatkirby |
19 | */ | 18 | */ |
20 | public class LayerEvent implements Event { | 19 | public class LayerEvent extends AbstractEvent implements Event { |
21 | 20 | ||
22 | /** Create a new Event instance | 21 | /** Create a new Event instance |
23 | * | 22 | * |
@@ -26,7 +25,7 @@ public class LayerEvent implements Event { | |||
26 | */ | 25 | */ |
27 | public LayerEvent(int x, int y) | 26 | public LayerEvent(int x, int y) |
28 | { | 27 | { |
29 | location = new Point(x,y); | 28 | setLocation(x,y); |
30 | events = new ArrayList<PossibleEvent>(); | 29 | events = new ArrayList<PossibleEvent>(); |
31 | label = "Unlabelled"; | 30 | label = "Unlabelled"; |
32 | } | 31 | } |
@@ -49,20 +48,6 @@ public class LayerEvent implements Event { | |||
49 | return label; | 48 | return label; |
50 | } | 49 | } |
51 | 50 | ||
52 | private Point location; | ||
53 | public Point getLocation() | ||
54 | { | ||
55 | return location; | ||
56 | } | ||
57 | public void setLocation(Point location) | ||
58 | { | ||
59 | this.location = location; | ||
60 | } | ||
61 | public void setLocation(int x, int y) | ||
62 | { | ||
63 | location.setLocation(x, y); | ||
64 | } | ||
65 | |||
66 | private ArrayList<PossibleEvent> events; | 51 | private ArrayList<PossibleEvent> events; |
67 | public void addEvent(PossibleEvent pe) | 52 | public void addEvent(PossibleEvent pe) |
68 | { | 53 | { |
@@ -92,10 +77,10 @@ public class LayerEvent implements Event { | |||
92 | 77 | ||
93 | public void render(Graphics g) | 78 | public void render(Graphics g) |
94 | { | 79 | { |
95 | int x = (location.x * 16) - 4; | 80 | int x = (getLocation().x * 16) - 4; |
96 | int y = (location.y * 16) - 16; | 81 | int y = (getLocation().y * 16) - 16; |
97 | 82 | ||
98 | if (moving) | 83 | if (isMoving()) |
99 | { | 84 | { |
100 | if (moveDirection == Direction.North) | 85 | if (moveDirection == Direction.North) |
101 | { | 86 | { |
@@ -113,72 +98,19 @@ public class LayerEvent implements Event { | |||
113 | } | 98 | } |
114 | 99 | ||
115 | PossibleEvent toDraw = getPossibleEvent(); | 100 | PossibleEvent toDraw = getPossibleEvent(); |
116 | if (!toDraw.getGraphic().equals("blank")) | 101 | if (!toDraw.getGraphic().equals(new BlankEventGraphic())) |
117 | { | 102 | { |
118 | g.drawImage(toDraw.getImage(), x, y, null); | 103 | g.drawImage(toDraw.getImage(), x, y, null); |
119 | } | 104 | } |
120 | } | 105 | } |
121 | 106 | ||
122 | |||
123 | private boolean moving = false; | ||
124 | public boolean isMoving() | ||
125 | { | ||
126 | return moving; | ||
127 | } | ||
128 | public void setMoving(boolean moving) | ||
129 | { | ||
130 | this.moving = moving; | ||
131 | } | ||
132 | |||
133 | private int moveTimer; | ||
134 | private Direction moveDirection; | ||
135 | public void startMoving(Map map) | 107 | public void startMoving(Map map) |
136 | { | 108 | { |
137 | Direction toMove = getPossibleEvent().getMovement().nextMovement(); | 109 | Direction toMove = getPossibleEvent().getMovement().nextMovement(); |
138 | 110 | ||
139 | if (toMove != null) | 111 | if (toMove != null) |
140 | { | 112 | { |
141 | if (!map.checkForCollision(getLocation().x, getLocation().y, toMove)) | 113 | startMoving(toMove); |
142 | { | ||
143 | startMoving(toMove); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | public void startMoving(Direction toMove) | ||
148 | { | ||
149 | getPossibleEvent().setDirection(toMove); | ||
150 | getPossibleEvent().setAnimationStep(2); | ||
151 | moveTimer = 4; | ||
152 | moving = true; | ||
153 | moveDirection = toMove; | ||
154 | } | ||
155 | public void processMoving() | ||
156 | { | ||
157 | if (moving) | ||
158 | { | ||
159 | moveTimer--; | ||
160 | if (moveTimer == 2) | ||
161 | { | ||
162 | getPossibleEvent().setAnimationStep(0); | ||
163 | } else if (moveTimer == 0) | ||
164 | { | ||
165 | getPossibleEvent().setAnimationStep(1); | ||
166 | moving = false; | ||
167 | |||
168 | if (moveDirection == Direction.North) | ||
169 | { | ||
170 | setLocation(getLocation().x,getLocation().y-1); | ||
171 | } else if (moveDirection == Direction.West) | ||
172 | { | ||
173 | setLocation(getLocation().x-1,getLocation().y); | ||
174 | } else if (moveDirection == Direction.South) | ||
175 | { | ||
176 | setLocation(getLocation().x,getLocation().y+1); | ||
177 | } else if (moveDirection == Direction.East) | ||
178 | { | ||
179 | setLocation(getLocation().x+1,getLocation().y); | ||
180 | } | ||
181 | } | ||
182 | } | 114 | } |
183 | } | 115 | } |
184 | 116 | ||
@@ -209,20 +141,15 @@ public class LayerEvent implements Event { | |||
209 | public void setLabel(String string) { | 141 | public void setLabel(String string) { |
210 | this.label = string; | 142 | this.label = string; |
211 | } | 143 | } |
144 | |||
145 | public void setAnimationStep(int animStep) | ||
146 | { | ||
147 | getPossibleEvent().setAnimationStep(animStep); | ||
148 | } | ||
212 | 149 | ||
213 | public boolean isOccupyingSpace(int x, int y) | 150 | public int getAnimationStep() |
214 | { | 151 | { |
215 | if (getLocation().equals(new Point(x,y))) | 152 | return getPossibleEvent().getAnimationStep(); |
216 | { | ||
217 | return true; | ||
218 | } | ||
219 | |||
220 | if (Functions.isMovingTo(this, x, y)) | ||
221 | { | ||
222 | return true; | ||
223 | } | ||
224 | |||
225 | return false; | ||
226 | } | 153 | } |
227 | 154 | ||
228 | } \ No newline at end of file | 155 | } \ No newline at end of file |