diff options
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java')
-rw-r--r-- | src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java | 50 |
1 files changed, 7 insertions, 43 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index e4ecf44..45eadc9 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java | |||
@@ -17,10 +17,11 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.EventHandler; | |||
17 | import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; | 17 | import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; |
18 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; | 18 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; |
19 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; | 19 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; |
20 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; | ||
21 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; | ||
20 | import com.fourisland.fourpuzzle.util.Functions; | 22 | import com.fourisland.fourpuzzle.util.Functions; |
21 | import com.fourisland.fourpuzzle.util.ResourceNotFoundException; | 23 | import com.fourisland.fourpuzzle.util.ResourceNotFoundException; |
22 | import java.awt.Graphics2D; | 24 | import java.awt.Graphics2D; |
23 | import java.awt.Point; | ||
24 | import java.awt.event.KeyEvent; | 25 | import java.awt.event.KeyEvent; |
25 | import java.awt.image.BufferedImage; | 26 | import java.awt.image.BufferedImage; |
26 | import java.util.logging.Level; | 27 | import java.util.logging.Level; |
@@ -35,12 +36,13 @@ public class MapViewGameState implements GameState { | |||
35 | public boolean debugWalkthrough = false; | 36 | public boolean debugWalkthrough = false; |
36 | boolean processInput = true; | 37 | boolean processInput = true; |
37 | Map currentMap; | 38 | Map currentMap; |
39 | Viewpoint currentViewpoint = null; | ||
38 | 40 | ||
39 | public MapViewGameState(String map, int x, int y) | 41 | public MapViewGameState(String map, int x, int y) |
40 | { | 42 | { |
41 | //currentMap = ObjectLoader.getMap(map); | ||
42 | setCurrentMap(map); | 43 | setCurrentMap(map); |
43 | Game.getSaveFile().getHero().setLocation(x, y); | 44 | Game.getSaveFile().getHero().setLocation(x, y); |
45 | currentViewpoint = new AutomaticViewpoint(currentMap); | ||
44 | } | 46 | } |
45 | 47 | ||
46 | public void initalize() | 48 | public void initalize() |
@@ -165,52 +167,14 @@ public class MapViewGameState implements GameState { | |||
165 | 167 | ||
166 | public void render(Graphics2D g) | 168 | public void render(Graphics2D g) |
167 | { | 169 | { |
168 | int x,y; | 170 | int x = currentViewpoint.getX(); |
169 | HeroEvent hero = Game.getHeroEvent(); | 171 | int y = currentViewpoint.getY(); |
170 | Point origLoc = hero.getLocation(); | ||
171 | Point endLoc = new Point(hero.getLocation()); | ||
172 | if (hero.isMoving()) | ||
173 | { | ||
174 | switch (hero.getDirection()) | ||
175 | { | ||
176 | case North: endLoc.translate(0, -1); break; | ||
177 | case West: endLoc.translate(-1, 0); break; | ||
178 | case South: endLoc.translate(0, 1); break; | ||
179 | case East: endLoc.translate(1, 0); break; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | if (Math.max(endLoc.x,origLoc.x) > 10) | ||
184 | { | ||
185 | if (Math.max(endLoc.x,origLoc.x) < (currentMap.getSize().width - 9)) | ||
186 | { | ||
187 | x = (origLoc.x - 10) * 16; | ||
188 | x += hero.getMovingX(); | ||
189 | } else { | ||
190 | x = (currentMap.getSize().width - 20) * 16; | ||
191 | } | ||
192 | } else { | ||
193 | x = 0; | ||
194 | } | ||
195 | |||
196 | if (Math.max(endLoc.y,origLoc.y) > 7) | ||
197 | { | ||
198 | if (Math.max(endLoc.y,origLoc.y) < (currentMap.getSize().height - 7)) | ||
199 | { | ||
200 | y = (origLoc.y - 7) * 16; | ||
201 | y += hero.getMovingY(); | ||
202 | } else { | ||
203 | y = (currentMap.getSize().height - 15) * 16; | ||
204 | } | ||
205 | } else { | ||
206 | y = 0; | ||
207 | } | ||
208 | 172 | ||
209 | g.drawImage(currentMap.renderLower(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); | 173 | g.drawImage(currentMap.renderLower(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); |
210 | 174 | ||
211 | BufferedImage eventLayer = new BufferedImage(currentMap.getSize().width*16, currentMap.getSize().height*16, BufferedImage.TYPE_INT_ARGB); | 175 | BufferedImage eventLayer = new BufferedImage(currentMap.getSize().width*16, currentMap.getSize().height*16, BufferedImage.TYPE_INT_ARGB); |
212 | Graphics2D g2 = eventLayer.createGraphics(); | 176 | Graphics2D g2 = eventLayer.createGraphics(); |
213 | hero.render(g2); | 177 | Game.getHeroEvent().render(g2); |
214 | 178 | ||
215 | EventList events = currentMap.getEvents(); | 179 | EventList events = currentMap.getEvents(); |
216 | for (LayerEvent event : events) | 180 | for (LayerEvent event : events) |