diff options
Diffstat (limited to 'src/com')
5 files changed, 118 insertions, 53 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index bc0073e..d02c7ed 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | |||
@@ -11,6 +11,8 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; | |||
11 | import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; | 11 | import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; |
12 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; | 12 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; |
13 | import java.awt.Dimension; | 13 | import java.awt.Dimension; |
14 | import java.awt.Graphics2D; | ||
15 | import java.awt.image.BufferedImage; | ||
14 | import java.util.HashMap; | 16 | import java.util.HashMap; |
15 | import java.util.Vector; | 17 | import java.util.Vector; |
16 | 18 | ||
@@ -185,4 +187,61 @@ public abstract class Map { | |||
185 | this.music = music; | 187 | this.music = music; |
186 | } | 188 | } |
187 | 189 | ||
190 | BufferedImage lowerLayer = null; | ||
191 | public BufferedImage renderLower() | ||
192 | { | ||
193 | if (lowerLayer == null) | ||
194 | { | ||
195 | lowerLayer = new BufferedImage(size.width*16, size.height*16, BufferedImage.TYPE_INT_ARGB); | ||
196 | Graphics2D g = lowerLayer.createGraphics(); | ||
197 | ChipSet chipSetObj = ChipSet.getChipSet(chipSet); | ||
198 | int i,x,y; | ||
199 | for (i=0;i<mapData.size();i++) | ||
200 | { | ||
201 | for (y=0;y<size.height;y++) | ||
202 | { | ||
203 | for (x=0;x<size.width;x++) | ||
204 | { | ||
205 | int tile = mapData.get(i).get(x+(y*size.width)); | ||
206 | if (chipSetObj.getChipSetData().get(tile).getLayer() != Layer.Above) | ||
207 | { | ||
208 | g.drawImage(chipSetObj.getImage(tile), x*16, y*16, null); | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | |||
215 | return lowerLayer; | ||
216 | |||
217 | } | ||
218 | |||
219 | BufferedImage upperLayer = null; | ||
220 | public BufferedImage renderUpper() | ||
221 | { | ||
222 | if (upperLayer == null) | ||
223 | { | ||
224 | upperLayer = new BufferedImage(size.width*16, size.height*16, BufferedImage.TYPE_INT_ARGB); | ||
225 | Graphics2D g = upperLayer.createGraphics(); | ||
226 | ChipSet chipSetObj = ChipSet.getChipSet(chipSet); | ||
227 | int i,x,y; | ||
228 | for (i=0;i<mapData.size();i++) | ||
229 | { | ||
230 | for (y=0;y<size.height;y++) | ||
231 | { | ||
232 | for (x=0;x<size.width;x++) | ||
233 | { | ||
234 | int tile = mapData.get(i).get(x+(y*size.width)); | ||
235 | if (chipSetObj.getChipSetData().get(tile).getLayer() == Layer.Above) | ||
236 | { | ||
237 | g.drawImage(chipSetObj.getImage(tile), x*16, y*16, null); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | } | ||
242 | } | ||
243 | |||
244 | return upperLayer; | ||
245 | } | ||
246 | |||
188 | } | 247 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 36406af..dbc8aca 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java | |||
@@ -21,6 +21,7 @@ import com.fourisland.fourpuzzle.util.Functions; | |||
21 | import com.fourisland.fourpuzzle.util.ResourceNotFoundException; | 21 | import com.fourisland.fourpuzzle.util.ResourceNotFoundException; |
22 | import java.awt.Graphics2D; | 22 | import java.awt.Graphics2D; |
23 | import java.awt.event.KeyEvent; | 23 | import java.awt.event.KeyEvent; |
24 | import java.awt.image.BufferedImage; | ||
24 | import java.util.logging.Level; | 25 | import java.util.logging.Level; |
25 | import java.util.logging.Logger; | 26 | import java.util.logging.Logger; |
26 | 27 | ||
@@ -162,59 +163,54 @@ public class MapViewGameState implements GameState { | |||
162 | } | 163 | } |
163 | 164 | ||
164 | public void render(Graphics2D g) | 165 | public void render(Graphics2D g) |
165 | { | 166 | { |
166 | /* TODO Add code that checks to see if the map has been switched | 167 | /* TODO Fix viewpoint scrolling code. Currently, when the Hero moves |
167 | * or if the hero has moved in such a way so as to move the | 168 | * South or East across the scroll barrier, it warps reality a little, |
168 | * viewpoint. If one or more of these conditions are filled, the | 169 | * while the other two directions scroll fine. |
169 | * already existing below code should run along with a snippet that | ||
170 | * saves a cache of the current viewpoint. If not, the previously | ||
171 | * mentioned cache should be displayed rather than re-rendering the | ||
172 | * map. | ||
173 | */ | 170 | */ |
174 | ChipSet chipSet = ChipSet.getChipSet(currentMap.getChipSet()); | 171 | |
175 | int i,x,y; | 172 | int x,y; |
176 | for (i=0;i<currentMap.getMapData().size();i++) | 173 | HeroEvent hero = Game.getHeroEvent(); |
174 | if (hero.getLocation().x > 10) | ||
177 | { | 175 | { |
178 | for (y=0;y<currentMap.getSize().height;y++) | 176 | if (hero.getLocation().x < (currentMap.getSize().width - 9)) |
179 | { | 177 | { |
180 | for (x=0;x<currentMap.getSize().width;x++) | 178 | x = (hero.getLocation().x - 10) * 16; |
181 | { | 179 | x += hero.getMovingX(); |
182 | int tile = currentMap.getMapData().get(i).get(x+(y*currentMap.getSize().width)); | 180 | } else { |
183 | if (chipSet.getChipSetData().get(tile).getLayer() != Layer.Above) | 181 | x = (currentMap.getSize().width - 20) * 16; |
184 | { | ||
185 | g.drawImage(chipSet.getImage(tile), x*16, y*16, null); | ||
186 | } | ||
187 | } | ||
188 | } | 182 | } |
183 | } else { | ||
184 | x = 0; | ||
189 | } | 185 | } |
190 | /* | 186 | |
191 | MapViewer mv = new MapViewer(currentMap, new com.alienfactory.javamappy.viewer.render.J2SE14Renderer(currentMap), Game.WIDTH, Game.HEIGHT); | 187 | if (hero.getLocation().y > 7) |
192 | mv.setBlockX(Game.getSaveFile().getHero().getLocation().x); | 188 | { |
193 | mv.setBlockY(Game.getSaveFile().getHero().getLocation().y); | 189 | if (hero.getLocation().y < (currentMap.getSize().height - 7)) |
194 | mv.setPixelX((4 - Game.getSaveFile().getHero().getMoveTimer()) * 4); | 190 | { |
195 | mv.draw(g, true);*/ | 191 | y = (hero.getLocation().y - 7) * 16; |
196 | Game.getSaveFile().getHero().render(g); | 192 | y += hero.getMovingY(); |
193 | } else { | ||
194 | y = (currentMap.getSize().height - 15) * 16; | ||
195 | } | ||
196 | } else { | ||
197 | y = 0; | ||
198 | } | ||
199 | |||
200 | g.drawImage(currentMap.renderLower(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); | ||
201 | |||
202 | BufferedImage eventLayer = new BufferedImage(currentMap.getSize().width*16, currentMap.getSize().height*16, BufferedImage.TYPE_INT_ARGB); | ||
203 | Graphics2D g2 = eventLayer.createGraphics(); | ||
204 | hero.render(g2); | ||
197 | 205 | ||
198 | EventList events = currentMap.getEvents(); | 206 | EventList events = currentMap.getEvents(); |
199 | for (LayerEvent event : events) | 207 | for (LayerEvent event : events) |
200 | { | 208 | { |
201 | event.render(g); | 209 | event.render(g2); |
202 | } | 210 | } |
203 | 211 | ||
204 | for (i=0;i<currentMap.getMapData().size();i++) | 212 | g.drawImage(eventLayer, 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); |
205 | { | 213 | g.drawImage(currentMap.renderUpper(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); |
206 | for (y=0;y<currentMap.getSize().height;y++) | ||
207 | { | ||
208 | for (x=0;x<currentMap.getSize().width;x++) | ||
209 | { | ||
210 | int tile = currentMap.getMapData().get(i).get(x+(y*currentMap.getSize().width)); | ||
211 | if (chipSet.getChipSetData().get(tile).getLayer() == Layer.Above) | ||
212 | { | ||
213 | g.drawImage(chipSet.getImage(tile), x*16, y*16, null); | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | } | ||
218 | } | 214 | } |
219 | 215 | ||
220 | public void initCurrentMap(String mapName) | 216 | public void initCurrentMap(String mapName) |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index c0ea634..7e8dd0d 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java | |||
@@ -124,37 +124,43 @@ public abstract class AbstractEvent implements Event { | |||
124 | 124 | ||
125 | public int getRenderX() | 125 | public int getRenderX() |
126 | { | 126 | { |
127 | int x = (getLocation().x * 16) - 4; | 127 | return (getLocation().x * 16) - 4 + getMovingX(); |
128 | 128 | } | |
129 | |||
130 | public int getRenderY() | ||
131 | { | ||
132 | return (getLocation().y * 16) - 16 + getMovingY(); | ||
133 | } | ||
134 | |||
135 | public int getMovingX() | ||
136 | { | ||
129 | if (isMoving()) | 137 | if (isMoving()) |
130 | { | 138 | { |
131 | if (getDirection() == Direction.West) | 139 | if (getDirection() == Direction.West) |
132 | { | 140 | { |
133 | x -= (4 - moveTimer) * 4; | 141 | return -((4 - moveTimer) * 4); |
134 | } else if (getDirection() == Direction.East) | 142 | } else if (getDirection() == Direction.East) |
135 | { | 143 | { |
136 | x += (4 - moveTimer) * 4; | 144 | return (4 - moveTimer) * 4; |
137 | } | 145 | } |
138 | } | 146 | } |
139 | 147 | ||
140 | return x; | 148 | return 0; |
141 | } | 149 | } |
142 | 150 | ||
143 | public int getRenderY() | 151 | public int getMovingY() |
144 | { | 152 | { |
145 | int y = (getLocation().y * 16) - 16; | ||
146 | |||
147 | if (isMoving()) | 153 | if (isMoving()) |
148 | { | 154 | { |
149 | if (getDirection() == Direction.North) | 155 | if (getDirection() == Direction.North) |
150 | { | 156 | { |
151 | y -= (4 - moveTimer) * 4; | 157 | return -((4 - moveTimer) * 4); |
152 | } else if (getDirection() == Direction.South) | 158 | } else if (getDirection() == Direction.South) |
153 | { | 159 | { |
154 | y += (4 - moveTimer) * 4; | 160 | return (4 - moveTimer) * 4; |
155 | } | 161 | } |
156 | } | 162 | } |
157 | 163 | ||
158 | return y; | 164 | return 0; |
159 | } | 165 | } |
160 | } | 166 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index 310c2a2..887e52b 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java | |||
@@ -28,6 +28,9 @@ public interface Event { | |||
28 | public int getRenderX(); | 28 | public int getRenderX(); |
29 | public int getRenderY(); | 29 | public int getRenderY(); |
30 | 30 | ||
31 | public int getMovingX(); | ||
32 | public int getMovingY(); | ||
33 | |||
31 | public Direction getDirection(); | 34 | public Direction getDirection(); |
32 | public void setDirection(Direction direction); | 35 | public void setDirection(Direction direction); |
33 | 36 | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java index 64ca592..c0c2c3b 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.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.concurrent.Future; | 9 | import java.util.concurrent.Future; |
9 | 10 | ||
10 | /** | 11 | /** |