From aa3d2a1e1d13b04a8c5801629e077668214bc3ff Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 30 Jan 2009 09:40:40 -0500 Subject: Added viewpoint scrolling Now, maps can be larger than (20,15) and the map will scroll as the hero walks across the middle. However, Southward and Eastward middle-traversing appears to warp reality just a little and there are a few kinks that need to be straightened out. Map layer caching has also been added because the lower and upper layers of a map never change, so they are cached after the first rendering. --- .../fourpuzzle/gamestate/mapview/Map.java | 59 ++++++++++++++++ .../gamestate/mapview/MapViewGameState.java | 80 ++++++++++------------ .../gamestate/mapview/event/AbstractEvent.java | 28 +++++--- .../fourpuzzle/gamestate/mapview/event/Event.java | 3 + .../gamestate/mapview/event/EventCall.java | 1 + 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; import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; import java.util.HashMap; import java.util.Vector; @@ -185,4 +187,61 @@ public abstract class Map { this.music = music; } + BufferedImage lowerLayer = null; + public BufferedImage renderLower() + { + if (lowerLayer == null) + { + lowerLayer = new BufferedImage(size.width*16, size.height*16, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = lowerLayer.createGraphics(); + ChipSet chipSetObj = ChipSet.getChipSet(chipSet); + int i,x,y; + for (i=0;i 10) { - for (y=0;y 7) + { + if (hero.getLocation().y < (currentMap.getSize().height - 7)) + { + y = (hero.getLocation().y - 7) * 16; + y += hero.getMovingY(); + } else { + y = (currentMap.getSize().height - 15) * 16; + } + } else { + y = 0; + } + + g.drawImage(currentMap.renderLower(), 0, 0, Game.WIDTH, Game.HEIGHT, x, y, x+Game.WIDTH, y+Game.HEIGHT, null); + + BufferedImage eventLayer = new BufferedImage(currentMap.getSize().width*16, currentMap.getSize().height*16, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = eventLayer.createGraphics(); + hero.render(g2); EventList events = currentMap.getEvents(); for (LayerEvent event : events) { - event.render(g); + event.render(g2); } - for (i=0;i