summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java')
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java50
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;
17import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; 17import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList;
18import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; 18import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
19import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; 19import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
20import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint;
21import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint;
20import com.fourisland.fourpuzzle.util.Functions; 22import com.fourisland.fourpuzzle.util.Functions;
21import com.fourisland.fourpuzzle.util.ResourceNotFoundException; 23import com.fourisland.fourpuzzle.util.ResourceNotFoundException;
22import java.awt.Graphics2D; 24import java.awt.Graphics2D;
23import java.awt.Point;
24import java.awt.event.KeyEvent; 25import java.awt.event.KeyEvent;
25import java.awt.image.BufferedImage; 26import java.awt.image.BufferedImage;
26import java.util.logging.Level; 27import 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)