From a28082cae3dbfd81d900ed224a97f96ab08e48d5 Mon Sep 17 00:00:00 2001 From: Mathew Velasquez Date: Fri, 20 Nov 2015 21:08:00 -0500 Subject: [PATCH] Rudimentary map wrapping added --- binding-mri/tilemap-binding.cpp | 2 ++ scripts/Game_Character 2.rb | 7 +++++++ scripts/Game_Map.rb | 6 ++++++ scripts/Map.rb | 4 ++++ scripts/Spriteset_Map.rb | 2 ++ src/tilemap.cpp | 5 ++++- src/tilemap.h | 1 + 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/binding-mri/tilemap-binding.cpp b/binding-mri/tilemap-binding.cpp index 2217012..a204f83 100644 --- a/binding-mri/tilemap-binding.cpp +++ b/binding-mri/tilemap-binding.cpp @@ -136,6 +136,7 @@ DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data") DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities") DEF_PROP_B(Tilemap, Visible) +DEF_PROP_B(Tilemap, Wrapping) DEF_PROP_I(Tilemap, OX) DEF_PROP_I(Tilemap, OY) @@ -165,6 +166,7 @@ tilemapBindingInit() INIT_PROP_BIND( Tilemap, FlashData, "flash_data" ); INIT_PROP_BIND( Tilemap, Priorities, "priorities" ); INIT_PROP_BIND( Tilemap, Visible, "visible" ); + INIT_PROP_BIND( Tilemap, Wrapping, "wrapping" ); INIT_PROP_BIND( Tilemap, OX, "ox" ); INIT_PROP_BIND( Tilemap, OY, "oy" ); } diff --git a/scripts/Game_Character 2.rb b/scripts/Game_Character 2.rb index e9e2621..764793e 100644 --- a/scripts/Game_Character 2.rb +++ b/scripts/Game_Character 2.rb @@ -108,6 +108,13 @@ class Game_Character # Increase animation count by 1 @anime_count += 1 end + # Wrap position + if @x * 128 == @real_x && @y * 128 == @real_y + @x %= $game_map.width + @y %= $game_map.height + @real_x = @x * 128 + @real_y = @y * 128 + end end #-------------------------------------------------------------------------- # * Frame Update (stop) diff --git a/scripts/Game_Map.rb b/scripts/Game_Map.rb index c8579a0..fe24411 100644 --- a/scripts/Game_Map.rb +++ b/scripts/Game_Map.rb @@ -27,6 +27,7 @@ class Game_Map attr_accessor :bg_name # bg file name attr_accessor :particles_type # particles name attr_accessor :clamped_panorama # panorama is clamped? + attr_accessor :wrapping # map is wrapping? attr_reader :passages # passage table attr_reader :priorities # prioroty table attr_reader :terrain_tags # terrain tag table @@ -106,6 +107,8 @@ class Game_Map @particles_type = nil # Unclamp panorama @clamped_panorama = false + # Unwrap map + @wrapping = false # Construct map name path mapinfo = load_data("Data/MapInfos.rxdata") @@ -225,6 +228,7 @@ class Game_Map # y : y-coordinate #-------------------------------------------------------------------------- def valid?(x, y) + return true if @wrapping return (x >= 0 and x < width and y >= 0 and y < height) end #-------------------------------------------------------------------------- @@ -241,6 +245,8 @@ class Game_Map # impassable return false end + x %= self.width + y %= self.height # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0) bit = (1 << (d / 2 - 1)) & 0x0f # Loop in all events diff --git a/scripts/Map.rb b/scripts/Map.rb index f80a8de..e112108 100644 --- a/scripts/Map.rb +++ b/scripts/Map.rb @@ -35,3 +35,7 @@ end def clamp_panorama $game_map.clamped_panorama = true end + +def wrap_map + $game_map.wrapping = true +end diff --git a/scripts/Spriteset_Map.rb b/scripts/Spriteset_Map.rb index 3bb8d39..fdea81c 100644 --- a/scripts/Spriteset_Map.rb +++ b/scripts/Spriteset_Map.rb @@ -124,6 +124,8 @@ class Spriteset_Map # * Frame Update #-------------------------------------------------------------------------- def update + # Update tilemap + @tilemap.wrapping = $game_map.wrapping # If panorama is different from current one if @panorama_name != $game_map.panorama_name or @panorama_hue != $game_map.panorama_hue diff --git a/src/tilemap.cpp b/src/tilemap.cpp index e1b3532..af3078d 100644 --- a/src/tilemap.cpp +++ b/src/tilemap.cpp @@ -236,6 +236,7 @@ struct TilemapPrivate Table *mapData; Table *priorities; bool visible; + bool wrapping; Vec2i origin; Vec2i dispPos; @@ -328,6 +329,7 @@ struct TilemapPrivate mapData(0), priorities(0), visible(true), + wrapping(false), flashAlphaIdx(0), atlasSizeDirty(false), atlasDirty(false), @@ -656,7 +658,7 @@ struct TilemapPrivate { int ox = x + viewpPos.x; int oy = y + viewpPos.y; - if (ox < 0 || oy < 0 || ox >= mapData->xSize() || oy >= mapData->ySize()) + if (!wrapping && (ox < 0 || oy < 0 || ox >= mapData->xSize() || oy >= mapData->ySize())) return; int tileInd = @@ -1149,6 +1151,7 @@ DEF_ATTR_RD_SIMPLE(Tilemap, MapData, Table*, p->mapData) DEF_ATTR_RD_SIMPLE(Tilemap, FlashData, Table*, p->flashMap.getData()) DEF_ATTR_RD_SIMPLE(Tilemap, Priorities, Table*, p->priorities) DEF_ATTR_RD_SIMPLE(Tilemap, Visible, bool, p->visible) +DEF_ATTR_SIMPLE(Tilemap, Wrapping, bool, p->wrapping) DEF_ATTR_RD_SIMPLE(Tilemap, OX, int, p->origin.x) DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->origin.y) diff --git a/src/tilemap.h b/src/tilemap.h index 9afe00f..ff1450c 100644 --- a/src/tilemap.h +++ b/src/tilemap.h @@ -63,6 +63,7 @@ public: DECL_ATTR( FlashData, Table* ) DECL_ATTR( Priorities, Table* ) DECL_ATTR( Visible, bool ) + DECL_ATTR( Wrapping, bool ) DECL_ATTR( OX, int ) DECL_ATTR( OY, int )