Rudimentary map wrapping added

This commit is contained in:
Mathew Velasquez 2015-11-20 21:08:00 -05:00
parent 652ef21a50
commit a28082cae3
7 changed files with 26 additions and 1 deletions

View File

@ -136,6 +136,7 @@ DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data")
DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities") DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities")
DEF_PROP_B(Tilemap, Visible) DEF_PROP_B(Tilemap, Visible)
DEF_PROP_B(Tilemap, Wrapping)
DEF_PROP_I(Tilemap, OX) DEF_PROP_I(Tilemap, OX)
DEF_PROP_I(Tilemap, OY) DEF_PROP_I(Tilemap, OY)
@ -165,6 +166,7 @@ tilemapBindingInit()
INIT_PROP_BIND( Tilemap, FlashData, "flash_data" ); INIT_PROP_BIND( Tilemap, FlashData, "flash_data" );
INIT_PROP_BIND( Tilemap, Priorities, "priorities" ); INIT_PROP_BIND( Tilemap, Priorities, "priorities" );
INIT_PROP_BIND( Tilemap, Visible, "visible" ); INIT_PROP_BIND( Tilemap, Visible, "visible" );
INIT_PROP_BIND( Tilemap, Wrapping, "wrapping" );
INIT_PROP_BIND( Tilemap, OX, "ox" ); INIT_PROP_BIND( Tilemap, OX, "ox" );
INIT_PROP_BIND( Tilemap, OY, "oy" ); INIT_PROP_BIND( Tilemap, OY, "oy" );
} }

View File

@ -108,6 +108,13 @@ class Game_Character
# Increase animation count by 1 # Increase animation count by 1
@anime_count += 1 @anime_count += 1
end 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 end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Frame Update (stop) # * Frame Update (stop)

View File

@ -27,6 +27,7 @@ class Game_Map
attr_accessor :bg_name # bg file name attr_accessor :bg_name # bg file name
attr_accessor :particles_type # particles name attr_accessor :particles_type # particles name
attr_accessor :clamped_panorama # panorama is clamped? attr_accessor :clamped_panorama # panorama is clamped?
attr_accessor :wrapping # map is wrapping?
attr_reader :passages # passage table attr_reader :passages # passage table
attr_reader :priorities # prioroty table attr_reader :priorities # prioroty table
attr_reader :terrain_tags # terrain tag table attr_reader :terrain_tags # terrain tag table
@ -106,6 +107,8 @@ class Game_Map
@particles_type = nil @particles_type = nil
# Unclamp panorama # Unclamp panorama
@clamped_panorama = false @clamped_panorama = false
# Unwrap map
@wrapping = false
# Construct map name path # Construct map name path
mapinfo = load_data("Data/MapInfos.rxdata") mapinfo = load_data("Data/MapInfos.rxdata")
@ -225,6 +228,7 @@ class Game_Map
# y : y-coordinate # y : y-coordinate
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def valid?(x, y) def valid?(x, y)
return true if @wrapping
return (x >= 0 and x < width and y >= 0 and y < height) return (x >= 0 and x < width and y >= 0 and y < height)
end end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
@ -241,6 +245,8 @@ class Game_Map
# impassable # impassable
return false return false
end end
x %= self.width
y %= self.height
# Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0) # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
bit = (1 << (d / 2 - 1)) & 0x0f bit = (1 << (d / 2 - 1)) & 0x0f
# Loop in all events # Loop in all events

View File

@ -35,3 +35,7 @@ end
def clamp_panorama def clamp_panorama
$game_map.clamped_panorama = true $game_map.clamped_panorama = true
end end
def wrap_map
$game_map.wrapping = true
end

View File

@ -124,6 +124,8 @@ class Spriteset_Map
# * Frame Update # * Frame Update
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def update def update
# Update tilemap
@tilemap.wrapping = $game_map.wrapping
# If panorama is different from current one # If panorama is different from current one
if @panorama_name != $game_map.panorama_name or if @panorama_name != $game_map.panorama_name or
@panorama_hue != $game_map.panorama_hue @panorama_hue != $game_map.panorama_hue

View File

@ -236,6 +236,7 @@ struct TilemapPrivate
Table *mapData; Table *mapData;
Table *priorities; Table *priorities;
bool visible; bool visible;
bool wrapping;
Vec2i origin; Vec2i origin;
Vec2i dispPos; Vec2i dispPos;
@ -328,6 +329,7 @@ struct TilemapPrivate
mapData(0), mapData(0),
priorities(0), priorities(0),
visible(true), visible(true),
wrapping(false),
flashAlphaIdx(0), flashAlphaIdx(0),
atlasSizeDirty(false), atlasSizeDirty(false),
atlasDirty(false), atlasDirty(false),
@ -656,7 +658,7 @@ struct TilemapPrivate
{ {
int ox = x + viewpPos.x; int ox = x + viewpPos.x;
int oy = y + viewpPos.y; 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; return;
int tileInd = 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, FlashData, Table*, p->flashMap.getData())
DEF_ATTR_RD_SIMPLE(Tilemap, Priorities, Table*, p->priorities) DEF_ATTR_RD_SIMPLE(Tilemap, Priorities, Table*, p->priorities)
DEF_ATTR_RD_SIMPLE(Tilemap, Visible, bool, p->visible) 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, OX, int, p->origin.x)
DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->origin.y) DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->origin.y)

View File

@ -63,6 +63,7 @@ public:
DECL_ATTR( FlashData, Table* ) DECL_ATTR( FlashData, Table* )
DECL_ATTR( Priorities, Table* ) DECL_ATTR( Priorities, Table* )
DECL_ATTR( Visible, bool ) DECL_ATTR( Visible, bool )
DECL_ATTR( Wrapping, bool )
DECL_ATTR( OX, int ) DECL_ATTR( OX, int )
DECL_ATTR( OY, int ) DECL_ATTR( OY, int )