diff --git a/bin/RabiClone.jar b/bin/RabiClone.jar index 24ee248..f36c28b 100644 Binary files a/bin/RabiClone.jar and b/bin/RabiClone.jar differ diff --git a/maps/world1.map b/maps/world1.map index b81cc11..25705bb 100644 Binary files a/maps/world1.map and b/maps/world1.map differ diff --git a/src/sig/map/Maps.java b/src/sig/map/Maps.java index a3740cf..47a63ad 100644 --- a/src/sig/map/Maps.java +++ b/src/sig/map/Maps.java @@ -41,7 +41,7 @@ public enum Maps { public View getView(int x,int y) { int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X; if (index<0||index>=this.map.views.length) { - return View.DIRECT_FOLLOW; + return View.FIXED; } else { return View.values()[this.map.views[index]]; } diff --git a/src/sig/map/View.java b/src/sig/map/View.java index 1b9842a..f11a323 100644 --- a/src/sig/map/View.java +++ b/src/sig/map/View.java @@ -1,7 +1,6 @@ package sig.map; public enum View { - DIRECT_FOLLOW, //Follows the player directly. LIGHT_FOLLOW, // Follows the player loosely, but makes sure there's // still a border between the edge of the screen and the player. diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index aadde23..39c0132 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -36,6 +36,7 @@ public class Player extends Object{ final double viewBoundaryX=RabiClone.BASE_WIDTH/3; final double viewBoundaryY=RabiClone.BASE_HEIGHT/3; + View lastCameraView = View.FIXED; public Player(Panel panel) { super(panel); @@ -55,45 +56,85 @@ public class Player extends Object{ private void handleCameraRoomMovement() { int tileX = (int)(getX())/Tile.TILE_WIDTH; int tileY = (int)(getY())/Tile.TILE_HEIGHT; + double newX=RabiClone.level_renderer.getX(),newY=RabiClone.level_renderer.getY(); //By default we use a fixed view. View currentView = RabiClone.CURRENT_MAP.getView(tileX, tileY); + if (currentView!=lastCameraView) { + lastCameraView=currentView; + newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH; + newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT; + } switch (currentView) { - case DIRECT_FOLLOW: - RabiClone.level_renderer.setX(getX()-RabiClone.BASE_WIDTH/2); - RabiClone.level_renderer.setY(getY()-RabiClone.BASE_HEIGHT/2); - break; - case FIXED: - RabiClone.level_renderer.setX((tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH); - RabiClone.level_renderer.setY((tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT); - break; case LIGHT_FOLLOW: if (getX()-RabiClone.level_renderer.getX()RabiClone.BASE_WIDTH-viewBoundaryX) { - RabiClone.level_renderer.setX(getX()-(RabiClone.BASE_WIDTH-viewBoundaryX)); + newX=getX()-(RabiClone.BASE_WIDTH-viewBoundaryX); + int newTileX = (int)(getX()+viewBoundaryX)/Tile.TILE_WIDTH; + View newView = RabiClone.CURRENT_MAP.getView(newTileX, tileY); + if (newView!=currentView) { + newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH; + } } if (getY()-RabiClone.level_renderer.getY()RabiClone.BASE_HEIGHT-viewBoundaryY) { - RabiClone.level_renderer.setY(getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY)); + newY=getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY); + int newTileY = (int)(getY()+viewBoundaryY)/Tile.TILE_HEIGHT; + View newView = RabiClone.CURRENT_MAP.getView(tileX, newTileY); + if (newView!=currentView) { + newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT; + } } break; case LIGHT_HORIZONTAL_FOLLOW: if (getX()-RabiClone.level_renderer.getX()RabiClone.BASE_WIDTH-viewBoundaryX) { - RabiClone.level_renderer.setX(getX()-(RabiClone.BASE_WIDTH-viewBoundaryX)); + newX=getX()-(RabiClone.BASE_WIDTH-viewBoundaryX); + int newTileX = (int)(getX()+viewBoundaryX)/Tile.TILE_WIDTH; + View newView = RabiClone.CURRENT_MAP.getView(newTileX, tileY); + if (newView!=currentView) { + newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH; + } } - RabiClone.level_renderer.setY((tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT); + newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT; break; case LIGHT_VERTICAL_FOLLOW: - RabiClone.level_renderer.setX((tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH); + newX=(tileX/Tile.TILE_SCREEN_COUNT_X)*Map.MAP_WIDTH; if (getY()-RabiClone.level_renderer.getY()RabiClone.BASE_HEIGHT-viewBoundaryY) { - RabiClone.level_renderer.setY(getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY)); + newY=getY()-(RabiClone.BASE_HEIGHT-viewBoundaryY); + int newTileY = (int)(getY()+viewBoundaryY)/Tile.TILE_HEIGHT; + View newView = RabiClone.CURRENT_MAP.getView(tileX, newTileY); + if (newView!=currentView) { + newY=(tileY/Tile.TILE_SCREEN_COUNT_Y)*Map.MAP_HEIGHT; + } } break; } + RabiClone.level_renderer.setX(newX); + RabiClone.level_renderer.setY(newY); }