diff options
| author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-30 14:03:13 -0500 |
|---|---|---|
| committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-30 14:03:13 -0500 |
| commit | 0526f49e9b06d77f979d3e3ae67ce4f8b827a362 (patch) | |
| tree | dbfd3cb46f522aeb1d0c2eaadf78534885d6ce97 /src/com | |
| parent | bb4a7e26902fd448ec7e041a7373cc30abb8feba (diff) | |
| download | fourpuzzle-0526f49e9b06d77f979d3e3ae67ce4f8b827a362.tar.gz fourpuzzle-0526f49e9b06d77f979d3e3ae67ce4f8b827a362.tar.bz2 fourpuzzle-0526f49e9b06d77f979d3e3ae67ce4f8b827a362.zip | |
Created Viewpoint
Diffstat (limited to 'src/com')
4 files changed, 121 insertions, 51 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) |
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 52b75de..615396b 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | |||
| @@ -17,14 +17,6 @@ import java.util.logging.Logger; | |||
| 17 | * @author hatkirby | 17 | * @author hatkirby |
| 18 | */ | 18 | */ |
| 19 | public class SpecialEvent { | 19 | public class SpecialEvent { |
| 20 | |||
| 21 | /* TODO Create a manager for SpecialEvent action threads that | ||
| 22 | * controls when they are executed and allows MapViewGameState | ||
| 23 | * to poll it to see if it is currently managing any action | ||
| 24 | * threads. If it is, MapViewGameState should be able to prevent | ||
| 25 | * certain actions from occuring (unless the action thread is | ||
| 26 | * ParallelProcess) such as keyboard input. | ||
| 27 | */ | ||
| 28 | 20 | ||
| 29 | /** | 21 | /** |
| 30 | * Display a message on the screen. | 22 | * Display a message on the screen. |
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/AutomaticViewpoint.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/AutomaticViewpoint.java new file mode 100644 index 0000000..6f6d6b0 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/AutomaticViewpoint.java | |||
| @@ -0,0 +1,97 @@ | |||
| 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.viewpoint; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Game; | ||
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | ||
| 10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; | ||
| 11 | import java.awt.Point; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * | ||
| 15 | * @author hatkirby | ||
| 16 | */ | ||
| 17 | public class AutomaticViewpoint implements Viewpoint { | ||
| 18 | |||
| 19 | private Map map; | ||
| 20 | private Point heroLoc; | ||
| 21 | private Point viewpoint; | ||
| 22 | |||
| 23 | public AutomaticViewpoint(Map map) | ||
| 24 | { | ||
| 25 | this.map = map; | ||
| 26 | heroLoc = Game.getHeroEvent().getLocation(); | ||
| 27 | refresh(); | ||
| 28 | } | ||
| 29 | |||
| 30 | public void refresh() | ||
| 31 | { | ||
| 32 | int x,y; | ||
| 33 | HeroEvent hero = Game.getHeroEvent(); | ||
| 34 | heroLoc = hero.getLocation(); | ||
| 35 | |||
| 36 | Point endLoc = new Point(hero.getLocation()); | ||
| 37 | if (hero.isMoving()) | ||
| 38 | { | ||
| 39 | switch (hero.getDirection()) | ||
| 40 | { | ||
| 41 | case North: endLoc.translate(0, -1); break; | ||
| 42 | case West: endLoc.translate(-1, 0); break; | ||
| 43 | case South: endLoc.translate(0, 1); break; | ||
| 44 | case East: endLoc.translate(1, 0); break; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | if (Math.max(endLoc.x,heroLoc.x) > 10) | ||
| 49 | { | ||
| 50 | if (Math.max(endLoc.x,heroLoc.x) < (map.getSize().width - 9)) | ||
| 51 | { | ||
| 52 | x = (heroLoc.x - 10) * 16; | ||
| 53 | x += hero.getMovingX(); | ||
| 54 | } else { | ||
| 55 | x = (map.getSize().width - 20) * 16; | ||
| 56 | } | ||
| 57 | } else { | ||
| 58 | x = 0; | ||
| 59 | } | ||
| 60 | |||
| 61 | if (Math.max(endLoc.y,heroLoc.y) > 7) | ||
| 62 | { | ||
| 63 | if (Math.max(endLoc.y,heroLoc.y) < (map.getSize().height - 7)) | ||
| 64 | { | ||
| 65 | y = (heroLoc.y - 7) * 16; | ||
| 66 | y += hero.getMovingY(); | ||
| 67 | } else { | ||
| 68 | y = (map.getSize().height - 15) * 16; | ||
| 69 | } | ||
| 70 | } else { | ||
| 71 | y = 0; | ||
| 72 | } | ||
| 73 | |||
| 74 | viewpoint = new Point(x,y); | ||
| 75 | } | ||
| 76 | |||
| 77 | public int getX() | ||
| 78 | { | ||
| 79 | if (Game.getHeroEvent().getLocation().equals(heroLoc)) | ||
| 80 | { | ||
| 81 | refresh(); | ||
| 82 | } | ||
| 83 | |||
| 84 | return viewpoint.x; | ||
| 85 | } | ||
| 86 | |||
| 87 | public int getY() | ||
| 88 | { | ||
| 89 | if (!Game.getHeroEvent().getLocation().equals(heroLoc)) | ||
| 90 | { | ||
| 91 | refresh(); | ||
| 92 | } | ||
| 93 | |||
| 94 | return viewpoint.y; | ||
| 95 | } | ||
| 96 | |||
| 97 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/Viewpoint.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/Viewpoint.java new file mode 100644 index 0000000..c46b280 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/Viewpoint.java | |||
| @@ -0,0 +1,17 @@ | |||
| 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.viewpoint; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * | ||
| 10 | * @author hatkirby | ||
| 11 | */ | ||
| 12 | public interface Viewpoint { | ||
| 13 | |||
| 14 | public int getX(); | ||
| 15 | public int getY(); | ||
| 16 | |||
| 17 | } | ||
