@ -91,7 +91,7 @@ bool Crawler::OnUserCreate(){
camera = Camera2D { WINDOW_SIZE } ;
camera . SetMode ( olc : : utils : : Camera2D : : Mode : : LazyFollow ) ;
camera . SetTarget ( player - > GetPos ( ) ) ;
camera . SetWorldBoundary ( { 0 , 0 } , GetCurrentMap ( ) . MapSize * 24 ) ;
camera . SetWorldBoundary ( { 0 , 0 } , GetCurrentMap ( ) . MapSize * GetCurrentMap ( ) . TileSize ) ;
camera . EnableWorldBoundary ( false ) ;
InitializeGraphics ( ) ;
@ -199,8 +199,8 @@ void Crawler::HandleUserInput(float fElapsedTime){
if ( player - > GetVelocity ( ) = = vf2d { 0 , 0 } & & player - > CanMove ( ) ) {
auto GetPlayerStaircaseDirection = [ & ] ( ) {
for ( LayerTag & layer : MAP_DATA [ GetCurrentLevel ( ) ] . LayerData ) {
int truncatedPlayerX = int ( player - > GetX ( ) ) / 24 ;
int truncatedPlayerY = int ( player - > GetY ( ) ) / 24 ;
int truncatedPlayerX = int ( player - > GetX ( ) ) / game - > GetCurrentMap ( ) . tilewidth ;
int truncatedPlayerY = int ( player - > GetY ( ) ) / game - > GetCurrentMap ( ) . tilewidth ;
int tileID = layer . tiles [ truncatedPlayerY ] [ truncatedPlayerX ] ;
TilesheetData dat = GetTileSheet ( GetCurrentLevel ( ) , tileID ) ;
if ( dat . tileset - > staircaseTiles . find ( tileID ) ! = dat . tileset - > staircaseTiles . end ( ) ) {
@ -547,12 +547,12 @@ void Crawler::RenderTile(vi2d pos,TilesheetData tileSheet,int tileSheetIndex,vi2
if ( tileSheet . tileset - > animationData . count ( tileSheetIndex ) ) {
int animationDuration_ms = tileSheet . tileset - > animationData [ tileSheetIndex ] . size ( ) * " animation_tile_precision " _I ;
int animatedIndex = tileSheet . tileset - > animationData [ tileSheetIndex ] [ int ( fmod ( levelTime * 1000 , animationDuration_ms ) / " animation_tile_precision " _I ) ] ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / 24 ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetX = animatedIndex % tileSheetWidth ;
int tileSheetY = animatedIndex / tileSheetWidth ;
view . DrawPartialDecal ( pos * 24 , { 24 , 24 } , tileSheet . tileset - > tileset - > Decal ( ) , vi2d { tileSheetX , tileSheetY } * 24 , { 24 , 24 } ) ;
view . DrawPartialDecal ( pos * game - > GetCurrentMap ( ) . tilewidth , { float ( tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileset - > tileheight ) } , tileSheet . tileset - > tileset - > Decal ( ) , vi2d { tileSheetX , tileSheetY } * tileSheet . tileset - > tilewidth , { float ( tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileset - > tileheight ) } ) ;
} else {
view . DrawPartialDecal ( pos * 24 , { 24 , 24 } , tileSheet . tileset - > tileset - > Decal ( ) , tileSheetPos * 24 , { 24 , 24 } ) ;
view . DrawPartialDecal ( pos * game - > GetCurrentMap ( ) . tilewidth , { float ( tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileset - > tileheight ) } , tileSheet . tileset - > tileset - > Decal ( ) , tileSheetPos * tileSheet . tileset - > tilewidth , { float ( tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileset - > tileheight ) } ) ;
}
}
@ -560,12 +560,12 @@ void Crawler::RenderTile(TileRenderData&tileSheet,Pixel col){
if ( tileSheet . tileSheet . tileset - > animationData . count ( tileSheet . tileID % 1000000 ) ) {
int animationDuration_ms = tileSheet . tileSheet . tileset - > animationData [ tileSheet . tileID % 1000000 ] . size ( ) * " animation_tile_precision " _I ;
int animatedIndex = tileSheet . tileSheet . tileset - > animationData [ tileSheet . tileID % 1000000 ] [ int ( fmod ( levelTime * 1000 , animationDuration_ms ) / " animation_tile_precision " _I ) ] ;
int tileSheetWidth = tileSheet . tileSheet . tileset - > tileset - > Sprite ( ) - > width / 24 ;
int tileSheetWidth = tileSheet . tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileSheet . tileset - > tilewidth ;
int tileSheetX = animatedIndex % tileSheetWidth ;
int tileSheetY = animatedIndex / tileSheetWidth ;
view . DrawPartialDecal ( tileSheet . pos , { 24 , 24 } , tileSheet . tileSheet . tileset - > tileset - > Decal ( ) , vi2d { tileSheetX , tileSheetY } , { 24 , 24 } , col ) ;
view . DrawPartialDecal ( tileSheet . pos , { float ( tileSheet . tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileSheet . tileset - > tileheight ) } , tileSheet . tileSheet . tileset - > tileset - > Decal ( ) , vi2d { tileSheetX , tileSheetY } , { float ( tileSheet . tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileSheet . tileset - > tileheight ) } , col ) ;
} else {
view . DrawPartialDecal ( tileSheet . pos , { 24 , 24 } , tileSheet . tileSheet . tileset - > tileset - > Decal ( ) , tileSheet . tileSheetPos , { 24 , 24 } , col ) ;
view . DrawPartialDecal ( tileSheet . pos , { float ( tileSheet . tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileSheet . tileset - > tileheight ) } , tileSheet . tileSheet . tileset - > tileset - > Decal ( ) , tileSheet . tileSheetPos , { float ( tileSheet . tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileSheet . tileset - > tileheight ) } , col ) ;
}
}
@ -612,7 +612,7 @@ void Crawler::RenderWorld(float fElapsedTime){
SetDecalMode ( DecalMode : : ADDITIVE ) ;
float reflectionHeight = ( float ( player - > GetFrame ( ) . GetSourceRect ( ) . size . y ) - 8 ) * player - > GetSizeMult ( ) ;
float reflectionBottom = player - > GetPos ( ) . y + reflectionHeight ;
float cutOff = reflectionBottom - GetCurrentMap ( ) . height * 24 ;
float cutOff = reflectionBottom - GetCurrentMap ( ) . height * GetCurrentMap ( ) . tileheight ;
float multiplierX = 0.9 ;
multiplierX * = ( 1 - abs ( sin ( reflectionStepTime ) ) * " water_reflection_scale_factor " _F ) ;
multiplierX * = ( 1 - abs ( cos ( 1.5 * reflectionStepTime ) ) * " water_reflection_scale_factor " _F ) ;
@ -623,8 +623,8 @@ void Crawler::RenderWorld(float fElapsedTime){
}
SetDecalMode ( DecalMode : : NORMAL ) ;
}
for ( int x = view . GetTopLeftTile ( ) . x / 24 - 1 ; x < = view . GetBottomRightTile ( ) . x / 24 ; x + + ) {
for ( int y = view . GetTopLeftTile ( ) . y / 24 - 1 ; y < = view . GetBottomRightTile ( ) . y / 24 ; y + + ) {
for ( int x = view . GetTopLeftTile ( ) . x / GetCurrentMap ( ) . tilewidth - 1 ; x < = view . GetBottomRightTile ( ) . x / GetCurrentMap ( ) . tilewidth ; x + + ) {
for ( int y = view . GetTopLeftTile ( ) . y / GetCurrentMap ( ) . tilewidth - 1 ; y < = view . GetBottomRightTile ( ) . y / GetCurrentMap ( ) . tilewidth ; y + + ) {
if ( x > = 0 & & x < GetCurrentMap ( ) . width & & y > = 0 & & y < GetCurrentMap ( ) . height ) {
switch ( mode ) {
case RenderMode : : NORMAL_TILES : {
@ -634,8 +634,8 @@ void Crawler::RenderWorld(float fElapsedTime){
if ( ! bridgeLayerFade & & ! player - > upperLevel ) {
int tileID = layer . tiles [ y ] [ x ] - 1 ;
if ( tileID ! = - 1 ) {
int playerXTruncated = int ( player - > GetPos ( ) . x ) / 24 ;
int playerYTruncated = int ( player - > GetPos ( ) . y ) / 24 ;
int playerXTruncated = int ( player - > GetPos ( ) . x ) / GetCurrentMap ( ) . tilewidth ;
int playerYTruncated = int ( player - > GetPos ( ) . y ) / GetCurrentMap ( ) . tilewidth ;
if ( playerXTruncated = = x & & playerYTruncated = = y ) {
bridgeLayerFade = true ;
}
@ -646,8 +646,8 @@ void Crawler::RenderWorld(float fElapsedTime){
int tileID = layer . tiles [ y ] [ x ] - 1 ;
if ( tileID ! = - 1 ) {
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID ) ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / 24 ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / 24 ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = tileSheetIndex % tileSheetWidth ;
int tileSheetY = tileSheetIndex / tileSheetWidth ;
@ -657,8 +657,8 @@ void Crawler::RenderWorld(float fElapsedTime){
if ( " debug_collision_boxes " _I ) {
if ( tileSheet . tileset - > collision . find ( tileSheetIndex ) ! = tileSheet . tileset - > collision . end ( ) ) {
geom2d : : rect < int > collision = tileSheet . tileset - > collision [ tileSheetIndex ] . collision ;
view . FillRectDecal ( vi2d { x , y } * 24 + collision . pos , collision . size , { 0 , 0 , 0 , 128 } ) ;
view . DrawRectDecal ( vi2d { x , y } * 24 + collision . pos , collision . size , GREY ) ;
view . FillRectDecal ( vi2d { x , y } * GetCurrentMap ( ) . tilewidth + collision . pos , collision . size , { 0 , 0 , 0 , 128 } ) ;
view . DrawRectDecal ( vi2d { x , y } * GetCurrentMap ( ) . tilewidth + collision . pos , collision . size , GREY ) ;
}
}
}
@ -671,8 +671,8 @@ void Crawler::RenderWorld(float fElapsedTime){
int tileID = layer . tiles [ y ] [ x ] - 1 ;
if ( tileID ! = - 1 ) {
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID ) ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / 24 ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / 24 ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = tileSheetIndex % tileSheetWidth ;
int tileSheetY = tileSheetIndex / tileSheetWidth ;
@ -683,8 +683,8 @@ void Crawler::RenderWorld(float fElapsedTime){
if ( " debug_collision_boxes " _I ) {
if ( tileSheet . tileset - > collision . find ( tileSheetIndex ) ! = tileSheet . tileset - > collision . end ( ) ) {
geom2d : : rect < int > collision = tileSheet . tileset - > collision [ tileSheetIndex ] . collision ;
view . FillRectDecal ( vi2d { x , y } * 24 + collision . pos , collision . size , { 0 , 0 , 0 , 128 } ) ;
view . DrawRectDecal ( vi2d { x , y } * 24 + collision . pos , collision . size , GREY ) ;
view . FillRectDecal ( vi2d { x , y } * GetCurrentMap ( ) . tilewidth + collision . pos , collision . size , { 0 , 0 , 0 , 128 } ) ;
view . DrawRectDecal ( vi2d { x , y } * GetCurrentMap ( ) . tilewidth + collision . pos , collision . size , GREY ) ;
}
}
}
@ -692,12 +692,12 @@ void Crawler::RenderWorld(float fElapsedTime){
} break ;
case RenderMode : : EMPTY_TILES : {
if ( visibleTiles . count ( { x , y } ) ) {
view . FillRectDecal ( vi2d { x , y } * 24 , { 24 , 24 } , { 100 , 180 , 100 } ) ;
view . FillRectDecal ( vi2d { x , y } * GetCurrentMap ( ) . tilewidth , { float ( GetCurrentMap ( ) . tilewidth ) , float ( GetCurrentMap ( ) . tilewidth ) } , { 100 , 180 , 100 } ) ;
}
} break ;
}
} else {
view . FillRectDecal ( vi2d { x , y } * 24 , { 24 , 24 } , { 100 , 180 , 100 } ) ;
view . FillRectDecal ( vi2d { x , y } * GetCurrentMap ( ) . tilewidth , { float ( GetCurrentMap ( ) . tilewidth ) , float ( GetCurrentMap ( ) . tilewidth ) } , { 100 , 180 , 100 } ) ;
}
}
}
@ -841,23 +841,23 @@ void Crawler::RenderWorld(float fElapsedTime){
# pragma region Bridge Layer Rendering
if ( bridgeLayer ! = nullptr ) {
for ( int x = view . GetTopLeftTile ( ) . x / 24 - 1 ; x < = view . GetBottomRightTile ( ) . x / 24 ; x + + ) {
for ( int y = view . GetTopLeftTile ( ) . y / 24 - 1 ; y < = view . GetBottomRightTile ( ) . y / 24 ; y + + ) {
for ( int x = view . GetTopLeftTile ( ) . x / game - > GetCurrentMap ( ) . tilewidth - 1 ; x < = view . GetBottomRightTile ( ) . x / game - > GetCurrentMap ( ) . tilewidth ; x + + ) {
for ( int y = view . GetTopLeftTile ( ) . y / game - > GetCurrentMap ( ) . tilewidth - 1 ; y < = view . GetBottomRightTile ( ) . y / game - > GetCurrentMap ( ) . tilewidth ; y + + ) {
if ( x > = 0 & & x < GetCurrentMap ( ) . width & & y > = 0 & & y < GetCurrentMap ( ) . height ) {
int tileID = bridgeLayer - > tiles [ y ] [ x ] - 1 ;
if ( tileID ! = - 1 ) {
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID ) ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / 24 ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / 24 ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = tileSheetIndex % tileSheetWidth ;
int tileSheetY = tileSheetIndex / tileSheetWidth ;
view . DrawPartialDecal ( vi2d { x , y } * 24 , { 24 , 24 } , tileSheet . tileset - > tileset - > Decal ( ) , vi2d { tileSheetX , tileSheetY } * 24 , { 24 , 24 } , { 255 , 255 , 255 , uint8_t ( 255 - bridgeFadeFactor / TileGroup : : FADE_TIME * TileGroup : : FADE_AMT ) } ) ;
view . DrawPartialDecal ( vi2d { x , y } * game - > GetCurrentMap ( ) . tilewidth , { float ( tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileset - > tileheight ) } , tileSheet . tileset - > tileset - > Decal ( ) , vi2d { tileSheetX , tileSheetY } * game - > GetCurrentMap ( ) . tilewidth , { float ( tileSheet . tileset - > tilewidth ) , float ( tileSheet . tileset - > tileheight ) } , { 255 , 255 , 255 , uint8_t ( 255 - bridgeFadeFactor / TileGroup : : FADE_TIME * TileGroup : : FADE_AMT ) } ) ;
# ifdef DEBUG_COLLISIONS
if ( tileSheet . tileset . collision . find ( tileSheetIndex ) ! = tileSheet . tileset . collision . end ( ) ) {
geom2d : : rect < int > collision = tileSheet . tileset . collision [ tileSheetIndex ] . collision ;
view . FillRectDecal ( vi2d { x , y } * 24 + collision . pos , collision . size , { 0 , 0 , 0 , 128 } ) ;
view . DrawRectDecal ( vi2d { x , y } * 24 + collision . pos , collision . size , GREY ) ;
view . FillRectDecal ( vi2d { x , y } * game - > GetCurrentMap ( ) . tilewidth + collision . pos , collision . size , { 0 , 0 , 0 , 128 } ) ;
view . DrawRectDecal ( vi2d { x , y } * game - > GetCurrentMap ( ) . tilewidth + collision . pos , collision . size , GREY ) ;
}
# endif
}
@ -990,7 +990,7 @@ void Crawler::RenderWorld(float fElapsedTime){
if ( DEBUG_PATHFINDING ) {
std : : vector < vf2d > pathing = game - > pathfinder . Solve_AStar ( player . get ( ) - > GetPos ( ) , GetWorldMousePos ( ) , 8 , player . get ( ) - > OnUpperLevel ( ) ) ;
for ( vf2d & square : pathing ) {
view . FillRectDecal ( square * 24 , { 24 , 24 } , DARK_GREEN ) ;
view . FillRectDecal ( square * game - > GetCurrentMap ( ) . tilewidth , { float ( game - > GetCurrentMap ( ) . tilewidth ) , float ( game - > GetCurrentMap ( ) . tilewidth ) } , DARK_GREEN ) ;
}
}
}
@ -1134,6 +1134,8 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){
if ( MAP_TILESETS . find ( " assets/maps/ " + baseSourceDir ) = = MAP_TILESETS . end ( ) ) {
TSXParser tileset ( baseDir + tag . data [ " source " ] ) ;
Renderable * r = new Renderable ( ) ;
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . tilewidth = tileset . GetData ( ) . tilewidth ;
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . tileheight = tileset . GetData ( ) . tileheight ;
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . tileset = r ;
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . foregroundTiles = tileset . GetData ( ) . ForegroundTileData ;
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . upperForegroundTiles = tileset . GetData ( ) . UpperForegroundTileData ;
@ -1183,10 +1185,10 @@ void Crawler::LoadLevel(MapName map){
} ;
for ( geom2d : : rect < int > & zone : GetUpperZones ( ) ) {
int zoneX = zone . pos . x / 24 ; //snap to grid
int zoneY = zone . pos . y / 24 ;
int zoneW = zone . right ( ) . start . x / 24 - zoneX ;
int zoneH = zone . bottom ( ) . start . y / 24 - zoneY ;
int zoneX = zone . pos . x / game - > GetCurrentMap ( ) . tilewidth ; //snap to grid
int zoneY = zone . pos . y / game - > GetCurrentMap ( ) . tilewidth ;
int zoneW = zone . right ( ) . start . x / game - > GetCurrentMap ( ) . tilewidth - zoneX ;
int zoneH = zone . bottom ( ) . start . y / game - > GetCurrentMap ( ) . tilewidth - zoneY ;
for ( int x = zoneX ; x < zoneX + zoneW ; x + + ) {
for ( int y = zoneY ; y < zoneY + zoneH ; y + + ) {
for ( LayerTag & layer : MAP_DATA [ map ] . LayerData ) {
@ -1211,8 +1213,8 @@ void Crawler::LoadLevel(MapName map){
int tileID = layer . tiles [ y ] [ x ] - 1 ;
if ( tileID ! = - 1 ) {
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID ) ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / 24 ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / 24 ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int realTileSheetIndex = ( tileID % 1000000 ) - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = realTileSheetIndex % tileSheetWidth ;
@ -1235,13 +1237,13 @@ void Crawler::LoadLevel(MapName map){
if ( ! loopAll & & & layer = = & layer2 ) { layer2ID + + ; continue ; } ;
int tileID = layer2 . tiles [ pos . y ] [ pos . x ] - 1 ;
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID % 1000000 ) ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / 24 ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / 24 ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int realTileSheetIndex = ( tileID % 1000000 ) - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = realTileSheetIndex % tileSheetWidth ;
int tileSheetY = realTileSheetIndex / tileSheetWidth ;
TileRenderData tile = { tileSheet , vi2d { pos . x , pos . y } * 24 , vi2d { tileSheetX , tileSheetY } * 24 , realTileSheetIndex , layer2ID } ;
TileRenderData tile = { tileSheet , vi2d { pos . x , pos . y } * game - > GetCurrentMap ( ) . tilewidth , vi2d { tileSheetX , tileSheetY } * game - > GetCurrentMap ( ) . tilewidth , realTileSheetIndex , layer2ID } ;
if ( IsForeground ( tileSheet , tileSheetIndex ) ) {
foregroundTilesIncluded . insert ( { pos . x , pos . y } ) ;
group . InsertTile ( tile ) ;
@ -1270,7 +1272,7 @@ void Crawler::LoadLevel(MapName map){
groups . push_back ( group ) ;
}
} ;
TileRenderData tile = { tileSheet , vi2d { x , y } * 24 , vi2d { tileSheetX , tileSheetY } * 24 , tileID , layerID } ;
TileRenderData tile = { tileSheet , vi2d { x , y } * game - > GetCurrentMap ( ) . tilewidth , vi2d { tileSheetX , tileSheetY } * game - > GetCurrentMap ( ) . tilewidth , tileID , layerID } ;
SetupTileGroups ( [ & ] ( TilesheetData sheet , int tileID ) { return IsForegroundTile ( sheet , tileID ) ; } , tile , foregroundTilesAdded , foregroundTileGroups ) ;
SetupTileGroups ( [ & ] ( TilesheetData sheet , int tileID ) { return IsUpperForegroundTile ( tileID ) ; } , tile , upperForegroundTilesAdded , upperForegroundTileGroups ) ;
# pragma endregion
@ -1342,7 +1344,7 @@ TilesheetData Crawler::GetTileSheet(MapName map,int tileID){
bool Crawler : : HasTileCollision ( MapName map , vf2d pos , bool upperLevel ) {
geom2d : : rect < int > collisionRect = GetTileCollision ( map , pos , upperLevel ) ;
vi2d collisionRectSnapPos = vi2d { pos / 24 } * 24 ;
vi2d collisionRectSnapPos = vi2d { pos / game - > GetCurrentMap ( ) . tilewidth } * game - > GetCurrentMap ( ) . tilewidth ;
collisionRect . pos + = collisionRectSnapPos ;
return geom2d : : overlaps ( collisionRect , pos ) ;
}
@ -1352,19 +1354,19 @@ bool Crawler::IsBridgeLayer(LayerTag&layer){
}
geom2d : : rect < int > Crawler : : GetTileCollision ( MapName map , vf2d pos , bool upperLevel ) {
if ( pos . x < 0 | | pos . y < 0 | | pos . x > = GetCurrentMap ( ) . width * 24 | | pos . y > = GetCurrentMap ( ) . height * 24 ) return NO_COLLISION ;
if ( pos . x < 0 | | pos . y < 0 | | pos . x > = GetCurrentMap ( ) . width * game - > GetCurrentMap ( ) . tilewidth | | pos . y > = GetCurrentMap ( ) . height * game - > GetCurrentMap ( ) . tilewidth ) return NO_COLLISION ;
# pragma region Lower Bridge Collision Check
if ( ! upperLevel ) { //We are looking for lower bridge collisions.
for ( geom2d : : rect < int > & zone : MAP_DATA [ map ] . ZoneData [ " LowerBridgeCollision " ] ) {
if ( geom2d : : contains ( zone , pos ) ) {
return { { 0 , 0 } , { 24 , 24 } } ;
return { { 0 , 0 } , { game - > GetCurrentMap ( ) . tilewidth , game - > GetCurrentMap ( ) . tilewidth } } ;
}
}
}
# pragma endregion
//The logic here is, if there's a tile on the bridge, we respect that tile instead if we're on the upper level. So we don't check other layers when we are on the upper level and there is a tile below us.
if ( upperLevel & & bridgeLayerIndex ! = - 1 ) {
int tileID = MAP_DATA [ map ] . LayerData [ bridgeLayerIndex ] . tiles [ int ( pos . y ) / 24 ] [ int ( pos . x ) / 24 ] - 1 ;
int tileID = MAP_DATA [ map ] . LayerData [ bridgeLayerIndex ] . tiles [ int ( pos . y ) / game - > GetCurrentMap ( ) . tilewidth ] [ int ( pos . x ) / game - > GetCurrentMap ( ) . tilewidth ] - 1 ;
if ( tileID ! = - 1 ) {
if ( GetTileSheet ( map , tileID % 1000000 ) . tileset - > collision . find ( tileID % 1000000 - GetTileSheet ( map , tileID % 1000000 ) . firstgid + 1 ) ! = GetTileSheet ( map , tileID % 1000000 ) . tileset - > collision . end ( ) ) {
return GetTileSheet ( map , tileID % 1000000 ) . tileset - > collision [ tileID % 1000000 - GetTileSheet ( map , tileID % 1000000 ) . firstgid + 1 ] . collision ;
@ -1377,7 +1379,7 @@ geom2d::rect<int>Crawler::GetTileCollision(MapName map,vf2d pos,bool upperLevel)
for ( LayerTag & layer : MAP_DATA [ map ] . LayerData ) {
//auto HasNoClass=[&](){return layer.tag.data.find("class")==layer.tag.data.end();};
if ( counter ! = bridgeLayerIndex ) {
int tileID = layer . tiles [ int ( pos . y ) / 24 ] [ int ( pos . x ) / 24 ] - 1 ;
int tileID = layer . tiles [ int ( pos . y ) / game - > GetCurrentMap ( ) . tilewidth ] [ int ( pos . x ) / game - > GetCurrentMap ( ) . tilewidth ] - 1 ;
if ( tileID ! = - 1 & & GetTileSheet ( map , tileID % 1000000 ) . tileset - > collision . find ( tileID % 1000000 - GetTileSheet ( map , tileID % 1000000 ) . firstgid + 1 ) ! = GetTileSheet ( map , tileID % 1000000 ) . tileset - > collision . end ( ) ) {
geom2d : : rect < int > collisionRect = GetTileSheet ( map , tileID % 1000000 ) . tileset - > collision [ tileID % 1000000 - GetTileSheet ( map , tileID % 1000000 ) . firstgid + 1 ] . collision ;
if ( foundRect . pos = = NO_COLLISION . pos & & foundRect . size = = NO_COLLISION . size ) {