@ -76,11 +76,13 @@ All rights reserved.
# include "discord.h"
# include "discord.h"
# endif
# endif
# include "GameSettings.h"
# include "GameSettings.h"
# include "LoadingScreen.h"
INCLUDE_EMITTER_LIST
INCLUDE_EMITTER_LIST
INCLUDE_ITEM_CATEGORIES
INCLUDE_ITEM_CATEGORIES
INCLUDE_BACKDROP_DATA
INCLUDE_BACKDROP_DATA
INCLUDE_MONSTER_DATA
INCLUDE_MONSTER_DATA
INCLUDE_PACK_KEY
bool _DEBUG_MAP_LOAD_INFO = false ;
bool _DEBUG_MAP_LOAD_INFO = false ;
//360x240
//360x240
@ -226,8 +228,7 @@ AiL::AiL()
}
}
bool AiL : : OnUserCreate ( ) {
bool AiL : : OnUserCreate ( ) {
std : : string packKey = " 129jvgndsaf7dsa8932hj " ;
gamepack . LoadPack ( " assets/ " + " gamepack_file " _S , PACK_KEY ) ;
gamepack . LoadPack ( " assets/ " + " gamepack_file " _S , packKey ) ;
GamePad : : init ( ) ;
GamePad : : init ( ) ;
@ -278,7 +279,6 @@ bool AiL::OnUserCreate(){
Inventory : : AddItem ( " Minor Health Potion " s , 3 ) ;
Inventory : : AddItem ( " Minor Health Potion " s , 3 ) ;
Inventory : : AddItem ( " Bandages " s , 10 ) ;
Inventory : : AddItem ( " Bandages " s , 10 ) ;
LoadLevel ( " starting_map " _S ) ;
ChangePlayerClass ( WARRIOR ) ;
ChangePlayerClass ( WARRIOR ) ;
GameState : : Initialize ( ) ;
GameState : : Initialize ( ) ;
@ -320,7 +320,7 @@ bool AiL::OnUserCreate(){
gameInitialized = true ;
gameInitialized = true ;
if ( ! gamepack . Loaded ( ) & & " GENERATE_GAMEPACK " _B ) {
if ( ! gamepack . Loaded ( ) & & " GENERATE_GAMEPACK " _B ) {
gamepack . SavePack ( " assets/ " + " gamepack_file " _S , packKey ) ;
gamepack . SavePack ( " assets/ " + " gamepack_file " _S , PACK_KEY ) ;
std : : cout < < " Game Pack has been generated! " < < std : : endl < < " ======================== " < < std : : endl < < std : : endl ;
std : : cout < < " Game Pack has been generated! " < < std : : endl < < " ======================== " < < std : : endl < < std : : endl ;
}
}
@ -336,6 +336,7 @@ bool AiL::OnUserUpdate(float fElapsedTime){
if ( ! GamePaused ( ) ) {
if ( ! GamePaused ( ) ) {
GameState : : STATE - > OnUserUpdate ( this ) ;
GameState : : STATE - > OnUserUpdate ( this ) ;
}
}
LoadingScreen : : Update ( ) ;
InputListener : : Update ( ) ;
InputListener : : Update ( ) ;
Audio : : Update ( ) ;
Audio : : Update ( ) ;
RenderWorld ( GetElapsedTime ( ) ) ;
RenderWorld ( GetElapsedTime ( ) ) ;
@ -343,6 +344,7 @@ bool AiL::OnUserUpdate(float fElapsedTime){
RenderMenu ( ) ;
RenderMenu ( ) ;
GameState : : STATE - > DrawOverlay ( this ) ;
GameState : : STATE - > DrawOverlay ( this ) ;
RenderFadeout ( ) ;
RenderFadeout ( ) ;
LoadingScreen : : Draw ( ) ;
RenderVersionInfo ( ) ;
RenderVersionInfo ( ) ;
# ifndef __EMSCRIPTEN__
# ifndef __EMSCRIPTEN__
if ( Discord ) {
if ( Discord ) {
@ -898,6 +900,7 @@ void AiL::RenderWorld(float fElapsedTime){
PopulateRenderLists ( ) ;
PopulateRenderLists ( ) ;
auto RenderPlayer = [ & ] ( vf2d pos , vf2d scale ) {
auto RenderPlayer = [ & ] ( vf2d pos , vf2d scale ) {
if ( player - > IsInvisible ( ) ) return ;
vf2d playerScale = vf2d ( player - > GetSizeMult ( ) , player - > GetSizeMult ( ) ) ;
vf2d playerScale = vf2d ( player - > GetSizeMult ( ) , player - > GetSizeMult ( ) ) ;
int count = 0 ;
int count = 0 ;
for ( vf2d & pos : player - > ghostPositions ) {
for ( vf2d & pos : player - > ghostPositions ) {
@ -1153,7 +1156,9 @@ void AiL::RenderWorld(float fElapsedTime){
if ( view . IsRectVisible ( group . GetRange ( ) . pos , group . GetRange ( ) . size ) ) {
if ( view . IsRectVisible ( group . GetRange ( ) . pos , group . GetRange ( ) . size ) ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player - > pos ) ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player - > pos ) ) {
group . playerBehind = true ;
group . playerBehind = true ;
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
if ( GameState : : STATE ! = GameState : : states [ States : : MAIN_MENU ] ) { //Don't fade out tile groups while we are on the main menu.
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
}
} else {
} else {
group . playerBehind = false ;
group . playerBehind = false ;
group . fadeFactor = std : : max ( group . fadeFactor - fElapsedTime , 0.f ) ;
group . fadeFactor = std : : max ( group . fadeFactor - fElapsedTime , 0.f ) ;
@ -1319,7 +1324,9 @@ void AiL::RenderWorld(float fElapsedTime){
if ( view . IsRectVisible ( group . GetRange ( ) . pos , group . GetRange ( ) . size ) ) {
if ( view . IsRectVisible ( group . GetRange ( ) . pos , group . GetRange ( ) . size ) ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player - > pos ) ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player - > pos ) ) {
group . playerBehind = true ;
group . playerBehind = true ;
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
if ( GameState : : STATE ! = GameState : : states [ States : : MAIN_MENU ] ) { //Don't fade out tile groups while we are on the main menu.
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
}
} else {
} else {
group . playerBehind = false ;
group . playerBehind = false ;
group . fadeFactor = std : : max ( group . fadeFactor - fElapsedTime , 0.f ) ;
group . fadeFactor = std : : max ( group . fadeFactor - fElapsedTime , 0.f ) ;
@ -1582,6 +1589,16 @@ void AiL::RenderCooldowns(){
const auto DrawCooldown = [ & ] ( vf2d pos , Ability & a , int loadoutSlot = - 1 /*Set to 0-2 to get an item slot rendered instead*/ ) {
const auto DrawCooldown = [ & ] ( vf2d pos , Ability & a , int loadoutSlot = - 1 /*Set to 0-2 to get an item slot rendered instead*/ ) {
bool circle = loadoutSlot = = - 1 ;
bool circle = loadoutSlot = = - 1 ;
if ( a . name ! = " ??? " ) {
if ( a . name ! = " ??? " ) {
vf2d keyDisplaySize = vf2d { GetTextSize ( a . input - > GetDisplayName ( ) ) } * vf2d { 0.5f , 0.5f } ;
InputType controlType = KEY ;
if ( Input : : UsingGamepad ( ) ) controlType = CONTROLLER ;
vf2d drawOffset = { } ;
if ( loadoutSlot ! = - 1 ) {
drawOffset . y + = 2.f ;
}
a . input - > DrawInput ( game , pos + vf2d { 14 , 0.f } + drawOffset , " " , 255 , controlType , { 0.75f , 0.75f } ) ;
if ( a . cooldown > 0.1 ) {
if ( a . cooldown > 0.1 ) {
vf2d iconScale = { 1 , 1 } ;
vf2d iconScale = { 1 , 1 } ;
if ( loadoutSlot ! = - 1 ) iconScale = { 0.7f , 0.7f } ;
if ( loadoutSlot ! = - 1 ) iconScale = { 0.7f , 0.7f } ;
@ -1647,9 +1664,6 @@ void AiL::RenderCooldowns(){
vf2d manaCostSize = vf2d { GetTextSize ( std : : to_string ( a . manaCost ) ) } * vf2d { 0.5f , 0.75f } ;
vf2d manaCostSize = vf2d { GetTextSize ( std : : to_string ( a . manaCost ) ) } * vf2d { 0.5f , 0.75f } ;
DrawShadowStringDecal ( pos + vf2d { 20 , 4 } - manaCostSize / 2 , std : : to_string ( a . manaCost ) , { 192 , 192 , 255 } , manaCostShadowCol , { 0.5f , 0.75f } ) ;
DrawShadowStringDecal ( pos + vf2d { 20 , 4 } - manaCostSize / 2 , std : : to_string ( a . manaCost ) , { 192 , 192 , 255 } , manaCostShadowCol , { 0.5f , 0.75f } ) ;
}
}
vf2d keyDisplaySize = vf2d { GetTextSize ( a . input - > GetDisplayName ( ) ) } * vf2d { 0.5f , 0.5f } ;
DrawShadowStringDecal ( pos + vf2d { 12 , - 2 } - keyDisplaySize / 2 , a . input - > GetDisplayName ( ) , keyDisplayCol , BLACK , { 0.5f , 0.5f } , std : : numeric_limits < float > : : max ( ) , 1 ) ;
vf2d shortNameSize = vf2d { GetTextSize ( a . shortName ) } * vf2d { 0.5f , 0.75f } ;
vf2d shortNameSize = vf2d { GetTextSize ( a . shortName ) } * vf2d { 0.5f , 0.75f } ;
DrawShadowStringDecal ( pos + vf2d { 13 , 24 } - shortNameSize / 2 , a . shortName , shortNameCol , { 255 , 255 , 255 , 230 } , { 0.5f , 0.75f } ) ;
DrawShadowStringDecal ( pos + vf2d { 13 , 24 } - shortNameSize / 2 , a . shortName , shortNameCol , { 255 , 255 , 255 , 230 } , { 0.5f , 0.75f } ) ;
@ -1820,282 +1834,354 @@ void AiL::InitializeLevel(std::string mapFile,MapName map){
}
}
}
}
void AiL : : LoadLevel ( MapName map ) {
void AiL : : LoadLevel ( MapName map , MusicChange changeMusic ) {
if ( game - > MAP_DATA . count ( map ) = = 0 ) ERR ( std : : format ( " WARNING! Could not load map {}! Does not exist! Refer to levels.txt for valid maps. " , map ) ) ;
LoadingScreen : : loading = true ;
if ( game - > MAP_DATA [ map ] . GetMapType ( ) = = " Hub " & & GameState : : STATE ! = GameState : : states [ States : : GAME_HUB ] ) ERR ( " WARNING! A hub level should only be initiated in the GAME_HUB game state! " ) ;
_PrepareLevel ( map , changeMusic ) ;
}
# pragma region Reset Environmental Audio
for ( EnvironmentalAudio & audio : MAP_DATA [ GetCurrentLevel ( ) ] . environmentalAudioData ) {
audio . Deactivate ( ) ;
}
# pragma endregion
SPAWNER_LIST . clear ( ) ;
void AiL : : _PrepareLevel ( MapName map , MusicChange changeMusic ) {
foregroundTileGroups . clear ( ) ;
LoadingScreen : : Reset ( ) ;
upperForegroundTileGroups . clear ( ) ;
previousLevel = currentLevel ;
MONSTER_LIST . clear ( ) ;
ZONE_LIST . clear ( ) ;
ItemDrop : : drops . clear ( ) ;
GameEvent : : events . clear ( ) ;
worldColor = WHITE ;
worldColorFunc = [ & ] ( vi2d pos ) { return game - > worldColor ; } ;
currentLevel = map ;
currentLevel = map ;
levelTime = 0 ;
# pragma region Reset all data (Loading phase 1)
bossName = " " ;
LoadingScreen : : AddPhase ( [ & ] ( ) {
encounterDuration = 0 ;
if ( game - > MAP_DATA . count ( GetCurrentLevel ( ) ) = = 0 ) ERR ( std : : format ( " WARNING! Could not load map {}! Does not exist! Refer to levels.txt for valid maps. " , map ) ) ;
totalDamageDealt = 0 ;
if ( game - > MAP_DATA [ GetCurrentLevel ( ) ] . GetMapType ( ) = = " Hub " & & GameState : : STATE ! = GameState : : states [ States : : GAME_HUB ] ) ERR ( " WARNING! A hub level should only be initiated in the GAME_HUB game state! " ) ;
encounterStarted = false ;
totalBossEncounterMobs = 0 ;
# pragma region Reset Environmental Audio
Inventory : : Clear ( " Monster Loot " ) ;
for ( EnvironmentalAudio & audio : MAP_DATA [ previousLevel ] . environmentalAudioData ) {
Inventory : : Clear ( " Stage Loot " ) ;
audio . Deactivate ( ) ;
}
GetPlayer ( ) - > hp = GetPlayer ( ) - > GetMaxHealth ( ) ;
# pragma endregion
GetPlayer ( ) - > mana = GetPlayer ( ) - > GetMaxMana ( ) ;
GetPlayer ( ) - > SetState ( State : : NORMAL ) ;
SPAWNER_LIST . clear ( ) ;
GetPlayer ( ) - > GetCastInfo ( ) = { } ;
foregroundTileGroups . clear ( ) ;
GetPlayer ( ) - > ResetAccumulatedXP ( ) ;
upperForegroundTileGroups . clear ( ) ;
MONSTER_LIST . clear ( ) ;
ZONE_LIST = game - > MAP_DATA [ game - > GetCurrentLevel ( ) ] . ZoneData ;
ZONE_LIST . clear ( ) ;
ItemDrop : : drops . clear ( ) ;
GameEvent : : events . clear ( ) ;
worldColor = WHITE ;
worldColorFunc = [ & ] ( vi2d pos ) { return game - > worldColor ; } ;
levelTime = 0 ;
bossName = " " ;
encounterDuration = 0 ;
totalDamageDealt = 0 ;
encounterStarted = false ;
totalBossEncounterMobs = 0 ;
Inventory : : Clear ( " Monster Loot " ) ;
Inventory : : Clear ( " Stage Loot " ) ;
GetPlayer ( ) - > hp = GetPlayer ( ) - > GetMaxHealth ( ) ;
GetPlayer ( ) - > mana = GetPlayer ( ) - > GetMaxMana ( ) ;
GetPlayer ( ) - > SetState ( State : : NORMAL ) ;
GetPlayer ( ) - > GetCastInfo ( ) = { } ;
GetPlayer ( ) - > ResetAccumulatedXP ( ) ;
GetPlayer ( ) - > SetIframes ( 0.f ) ;
GetPlayer ( ) - > SetInvisible ( false ) ;
ZONE_LIST = game - > MAP_DATA [ game - > GetCurrentLevel ( ) ] . ZoneData ;
return true ;
} ) ;
# pragma endregion
# pragma region Monster Spawn Data Setup
# pragma region Monster Spawn Data Setup (Loading phase 2)
for ( auto & [ key , value ] : MAP_DATA [ map ] . SpawnerData ) {
LoadingScreen : : AddPhase ( [ & ] ( ) {
SpawnerTag & spawnData = MAP_DATA [ map ] . SpawnerData [ key ] ;
for ( auto & [ key , value ] : MAP_DATA [ GetCurrentLevel ( ) ] . SpawnerData ) {
std : : vector < std : : pair < std : : string , vf2d > > monster_list ;
SpawnerTag & spawnData = MAP_DATA [ GetCurrentLevel ( ) ] . SpawnerData [ key ] ;
std : : vector < std : : pair < std : : string , vf2d > > monster_list ;
vf2d spawnerRadius = vf2d { spawnData . ObjectData . GetFloat ( " width " ) , spawnData . ObjectData . GetFloat ( " height " ) } / 2 ;
vf2d spawnerRadius = vf2d { spawnData . ObjectData . GetFloat ( " width " ) , spawnData . ObjectData . GetFloat ( " height " ) } / 2 ;
for ( XMLTag & monster : spawnData . monsters ) {
for ( XMLTag & monster : spawnData . monsters ) {
std : : string monsterName = monster . GetString ( " value " ) ;
std : : string monsterName = monster . GetString ( " value " ) ;
monster_list . push_back ( { monsterName , { monster . GetInteger ( " x " ) - spawnData . ObjectData . GetFloat ( " x " ) , monster . GetInteger ( " y " ) - spawnData . ObjectData . GetFloat ( " y " ) } } ) ;
monster_list . push_back ( { monsterName , { monster . GetInteger ( " x " ) - spawnData . ObjectData . GetFloat ( " x " ) , monster . GetInteger ( " y " ) - spawnData . ObjectData . GetFloat ( " y " ) } } ) ;
}
SPAWNER_LIST . push_back ( MonsterSpawner { { spawnData . ObjectData . GetFloat ( " x " ) , spawnData . ObjectData . GetFloat ( " y " ) } , spawnerRadius * 2 , monster_list , spawnData . upperLevel , spawnData . bossNameDisplay } ) ;
}
}
SPAWNER_LIST . push_back ( MonsterSpawner { { spawnData . ObjectData . GetFloat ( " x " ) , spawnData . ObjectData . GetFloat ( " y " ) } , spawnerRadius * 2 , monster_list , spawnData . upperLevel , spawnData . bossNameDisplay } ) ;
retu rn true ;
}
} ) ;
# pragma endregion
# pragma endregion
# pragma region Identify Upper Foreground Tiles
# pragma region Identify Upper Foreground Tiles (Loading phase 3)
auto GetUpperZones = [ & ] ( ) {
LoadingScreen : : AddPhase ( [ & ] ( ) {
for ( auto & zoneSet : MAP_DATA [ map ] . ZoneData ) {
auto GetUpperZones = [ & ] ( ) {
if ( zoneSet . first = = " UpperZone " ) { //We are interested in all upper zones.
for ( auto & zoneSet : MAP_DATA [ GetCurrentLevel ( ) ] . ZoneData ) {
return zoneSet . second ;
if ( zoneSet . first = = " UpperZone " ) { //We are interested in all upper zones.
return zoneSet . second ;
}
}
}
}
return std : : vector < ZoneData > { } ;
return std : : vector < ZoneData > { } ;
} ;
} ;
for ( ZoneData & zone : GetUpperZones ( ) ) {
for ( ZoneData & zone : GetUpperZones ( ) ) {
int zoneX = zone . zone . pos . x / game - > GetCurrentMapData ( ) . tilewidth ; //snap to grid
int zoneX = zone . zone . pos . x / game - > GetCurrentMapData ( ) . tilewidth ; //snap to grid
int zoneY = zone . zone . pos . y / game - > GetCurrentMapData ( ) . tilewidth ;
int zoneY = zone . zone . pos . y / game - > GetCurrentMapData ( ) . tilewidth ;
int zoneW = zone . zone . right ( ) . start . x / game - > GetCurrentMapData ( ) . tilewidth - zoneX ;
int zoneW = zone . zone . right ( ) . start . x / game - > GetCurrentMapData ( ) . tilewidth - zoneX ;
int zoneH = zone . zone . bottom ( ) . start . y / game - > GetCurrentMapData ( ) . tilewidth - zoneY ;
int zoneH = zone . zone . bottom ( ) . start . y / game - > GetCurrentMapData ( ) . tilewidth - zoneY ;
for ( int x = zoneX ; x < zoneX + zoneW ; x + + ) {
for ( int x = zoneX ; x < zoneX + zoneW ; x + + ) {
for ( int y = zoneY ; y < zoneY + zoneH ; y + + ) {
for ( int y = zoneY ; y < zoneY + zoneH ; y + + ) {
for ( LayerTag & layer : MAP_DATA [ GetCurrentLevel ( ) ] . LayerData ) {
for ( LayerTag & layer : MAP_DATA [ map ] . LayerData ) {
int tile = layer . tiles [ y ] [ x ] - 1 ;
int tile = layer . tiles [ y ] [ x ] - 1 ;
TilesheetData tileSheet = GetTileSheet ( currentLevel , tile ) ;
TilesheetData tileSheet = GetTileSheet ( currentLevel , tile ) ;
int tileSheetIndex = tile - ( tileSheet . firstgid - 1 ) ;
int tileSheetIndex = tile - ( tileSheet . firstgid - 1 ) ;
if ( IsForegroundTile ( tileSheet , tileSheetIndex ) ) {
if ( IsForegroundTile ( tileSheet , tileSheetIndex ) ) {
layer . tiles [ y ] [ x ] + = 1000000 ;
layer . tiles [ y ] [ x ] + = 1000000 ;
}
}
}
}
}
}
}
}
}
}
return true ;
} ) ;
# pragma endregion
# pragma endregion
# pragma region Foreground and Upper Foreground Tile Fade Group Setup
# pragma region Foreground and Upper Foreground Tile Fade Group Setup (Loading phase 4)
std : : set < vi2d > foregroundTilesAdded , upperForegroundTilesAdded ;
LoadingScreen : : AddPhase ( [ & ] ( ) {
for ( int x = 0 ; x < GetCurrentMapData ( ) . width ; x + + ) {
std : : set < vi2d > foregroundTilesAdded , upperForegroundTilesAdded ;
for ( int y = 0 ; y < GetCurrentMapData ( ) . height ; y + + ) {
for ( int x = 0 ; x < GetCurrentMapData ( ) . width ; x + + ) {
int layerID = 0 ;
for ( int y = 0 ; y < GetCurrentMapData ( ) . height ; y + + ) {
for ( LayerTag & layer : MAP_DATA [ currentLevel ] . LayerData ) {
int layerID = 0 ;
if ( Unlock : : IsUnlocked ( layer . unlockCondition ) ) {
for ( LayerTag & layer : MAP_DATA [ currentLevel ] . LayerData ) {
int tileID = layer . tiles [ y ] [ x ] - 1 ;
if ( Unlock : : IsUnlocked ( layer . unlockCondition ) ) {
if ( tileID ! = - 1 ) {
int tileID = layer . tiles [ y ] [ x ] - 1 ;
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID ) ;
if ( tileID ! = - 1 ) {
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID ) ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int realTileSheetIndex = ( tileID % 1000000 ) - ( tileSheet . firstgid - 1 ) ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = realTileSheetIndex % tileSheetWidth ;
int realTileSheetIndex = ( tileID % 1000000 ) - ( tileSheet . firstgid - 1 ) ;
int tileSheetY = realTileSheetIndex / tileSheetWidth ;
int tileSheetX = realTileSheetIndex % tileSheetWidth ;
int checkTileIndex = tileID ;
int tileSheetY = realTileSheetIndex / tileSheetWidth ;
int checkTileID = tileSheetIndex ;
int checkTileIndex = tileID ;
# pragma region TileGroupShenanigans
int checkTileID = tileSheetIndex ;
auto SetupTileGroups = [ & ] ( std : : function < bool ( TilesheetData , int ) > IsForeground , TileRenderData tile , std : : set < vi2d > & foregroundTilesIncluded , std : : vector < TileGroup > & groups ) {
# pragma region TileGroupShenanigans
if ( foregroundTilesIncluded . find ( { x , y } ) = = foregroundTilesIncluded . end ( ) & & IsForeground ( tileSheet , tileSheetIndex ) ) {
auto SetupTileGroups = [ & ] ( std : : function < bool ( TilesheetData , int ) > IsForeground , TileRenderData tile , std : : set < vi2d > & foregroundTilesIncluded , std : : vector < TileGroup > & groups ) {
std : : queue < vi2d > tileGroupChecks ;
if ( foregroundTilesIncluded . find ( { x , y } ) = = foregroundTilesIncluded . end ( ) & & IsForeground ( tileSheet , tileSheetIndex ) ) {
TileGroup group ;
std : : queue < vi2d > tileGroupChecks ;
foregroundTilesIncluded . insert ( { x , y } ) ;
TileGroup group ;
group . InsertTile ( tile ) ;
foregroundTilesIncluded . insert ( { x , y } ) ;
if ( x > 0 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { - 1 , 0 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x - 1 , y } ) ;
group . InsertTile ( tile ) ;
if ( x < GetCurrentMapData ( ) . width - 1 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { 1 , 0 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x + 1 , y } ) ;
if ( x > 0 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { - 1 , 0 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x - 1 , y } ) ;
if ( y > 0 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { 0 , - 1 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x , y - 1 } ) ;
if ( x < GetCurrentMapData ( ) . width - 1 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { 1 , 0 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x + 1 , y } ) ;
if ( y < GetCurrentMapData ( ) . height - 1 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { 0 , 1 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x , y + 1 } ) ;
if ( y > 0 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { 0 , - 1 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x , y - 1 } ) ;
auto IterateThroughOtherLayers = [ & ] ( vi2d pos , bool loopAll = false ) {
if ( y < GetCurrentMapData ( ) . height - 1 & & foregroundTilesIncluded . find ( vi2d { x , y } + vi2d { 0 , 1 } ) = = foregroundTilesIncluded . end ( ) ) tileGroupChecks . push ( { x , y + 1 } ) ;
int layer2ID = 0 ;
auto IterateThroughOtherLayers = [ & ] ( vi2d pos , bool loopAll = false ) {
bool hadForeground = false ;
int layer2ID = 0 ;
for ( LayerTag & layer2 : MAP_DATA [ currentLevel ] . LayerData ) {
bool hadForeground = false ;
if ( ! loopAll & & & layer = = & layer2 ) { layer2ID + + ; continue ; } ;
for ( LayerTag & layer2 : MAP_DATA [ currentLevel ] . LayerData ) {
int tileID = layer2 . tiles [ pos . y ] [ pos . x ] - 1 ;
if ( ! loopAll & & & layer = = & layer2 ) { layer2ID + + ; continue ; } ;
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID % 1000000 ) ;
int tileID = layer2 . tiles [ pos . y ] [ pos . x ] - 1 ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID % 1000000 ) ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int tileSheetWidth = tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileSheet . tileset - > tilewidth ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetHeight = tileSheet . tileset - > tileset - > Sprite ( ) - > height / tileSheet . tileset - > tileheight ;
int realTileSheetIndex = ( tileID % 1000000 ) - ( tileSheet . firstgid - 1 ) ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = realTileSheetIndex % tileSheetWidth ;
int realTileSheetIndex = ( tileID % 1000000 ) - ( tileSheet . firstgid - 1 ) ;
int tileSheetY = realTileSheetIndex / tileSheetWidth ;
int tileSheetX = realTileSheetIndex % tileSheetWidth ;
TileRenderData tile = { tileSheet , vi2d { pos . x , pos . y } * game - > GetCurrentMapData ( ) . tilewidth , vi2d { tileSheetX , tileSheetY } * game - > GetCurrentMapData ( ) . tilewidth , realTileSheetIndex , layer2ID } ;
int tileSheetY = realTileSheetIndex / tileSheetWidth ;
if ( IsForeground ( tileSheet , tileSheetIndex ) ) {
TileRenderData tile = { tileSheet , vi2d { pos . x , pos . y } * game - > GetCurrentMapData ( ) . tilewidth , vi2d { tileSheetX , tileSheetY } * game - > GetCurrentMapData ( ) . tilewidth , realTileSheetIndex , layer2ID } ;
foregroundTilesIncluded . insert ( { pos . x , pos . y } ) ;
if ( IsForeground ( tileSheet , tileSheetIndex ) ) {
group . InsertTile ( tile ) ;
foregroundTilesIncluded . insert ( { pos . x , pos . y } ) ;
hadForeground = true ;
group . InsertTile ( tile ) ;
hadForeground = true ;
}
layer2ID + + ;
}
}
layer2ID + + ;
return hadForeground ;
}
} ;
return hadForeground ;
IterateThroughOtherLayers ( { x , y } ) ;
} ;
while ( ! tileGroupChecks . empty ( ) ) {
IterateThroughOtherLayers ( { x , y } ) ;
vi2d & pos = tileGroupChecks . front ( ) ;
while ( ! tileGroupChecks . empty ( ) ) {
if ( IterateThroughOtherLayers ( pos , true ) ) {
vi2d & pos = tileGroupChecks . front ( ) ;
foregroundTilesIncluded . insert ( { pos . x , pos . y } ) ; //Regardless of if we found a foreground tile or not, we need to add this to not get stuck in an infinite loop.
if ( IterateThroughOtherLayers ( pos , true ) ) {
vi2d targetPos = pos + vi2d { - 1 , 0 } ;
foregroundTilesIncluded . insert ( { pos . x , pos . y } ) ; //Regardless of if we found a foreground tile or not, we need to add this to not get stuck in an infinite loop.
if ( pos . x > 0 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetPos ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
vi2d targetPos = pos + vi2d { - 1 , 0 } ;
targetPos = pos + vi2d { 1 , 0 } ;
if ( pos . x > 0 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetPos ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
if ( pos . x < GetCurrentMapData ( ) . width - 1 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetPos ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
targetPos = pos + vi2d { 1 , 0 } ;
targetPos = pos + vi2d { 0 , - 1 } ;
if ( pos . x < GetCurrentMapData ( ) . width - 1 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetPos ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
if ( pos . y > 0 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetPos ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
targetPos = pos + vi2d { 0 , - 1 } ;
targetPos = pos + vi2d { 0 , 1 } ;
if ( pos . y > 0 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetPos ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
if ( pos . y < GetCurrentMapData ( ) . height - 1 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetPos ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
targetPos = pos + vi2d { 0 , 1 } ;
}
if ( pos . y < GetCurrentMapData ( ) . height - 1 & & foregroundTilesIncluded . find ( targetPos ) = = foregroundTilesIncluded . end ( ) ) { tileGroupChecks . push ( targetP os ) ; foregroundTilesIncluded . insert ( targetPos ) ; }
tileGroupChecks . pop ( ) ;
}
}
tileGroupChecks . pop ( ) ;
groups . push_back ( group ) ;
}
}
groups . push_back ( group ) ;
} ;
}
TileRenderData tile = { tileSheet , vi2d { x , y } * game - > GetCurrentMapData ( ) . tilewidth , vi2d { tileSheetX , tileSheetY } * game - > GetCurrentMapData ( ) . tilewidth , realTileSheetIndex , layerID } ;
} ;
SetupTileGroups ( [ & ] ( TilesheetData sheet , int tileID ) { return IsForegroundTile ( sheet , tileID ) ; } , tile , foregroundTilesAdded , foregroundTileGroups ) ;
TileRenderData tile = { tileSheet , vi2d { x , y } * game - > GetCurrentMapData ( ) . tilewidth , vi2d { tileSheetX , tileSheetY } * game - > GetCurrentMapData ( ) . tilewidth , realTileSheetIndex , layerID } ;
SetupTileGroups ( [ & ] ( TilesheetData sheet , int tileID ) { return IsUpperForegroundTile ( tileID ) ; } , tile , upperForegroundTilesAdded , upperForegroundTileGroups ) ;
SetupTileGroups ( [ & ] ( TilesheetData sheet , int tileID ) { return IsForegroundTile ( sheet , tileID ) ; } , tile , foregroundTilesAdded , foregroundTileGroups ) ;
# pragma endregion
SetupTileGroups ( [ & ] ( TilesheetData sheet , int tileID ) { return IsUpperForegroundTile ( tileID ) ; } , tile , upperForegroundTilesAdded , upperForegroundTileGroups ) ;
}
# pragma endregion
}
}
layerID + + ;
}
}
layerID + + ;
}
}
}
}
}
for ( TileGroup & group : foregroundTileGroups ) {
for ( TileGroup & group : foregroundTileGroups ) {
std : : sort ( group . GetTiles ( ) . begin ( ) , group . GetTiles ( ) . end ( ) , [ ] ( TileRenderData & t1 , TileRenderData & t2 ) { return t1 . layerID < t2 . layerID ; } ) ;
std : : sort ( group . GetTiles ( ) . begin ( ) , group . GetTiles ( ) . end ( ) , [ ] ( TileRenderData & t1 , TileRenderData & t2 ) { return t1 . layerID < t2 . layerID ; } ) ;
}
}
for ( TileGroup & group : upperForegroundTileGroups ) {
for ( TileGroup & group : upperForegroundTileGroups ) {
std : : sort ( group . GetTiles ( ) . begin ( ) , group . GetTiles ( ) . end ( ) , [ ] ( TileRenderData & t1 , TileRenderData & t2 ) { return t1 . layerID < t2 . layerID ; } ) ;
std : : sort ( group . GetTiles ( ) . begin ( ) , group . GetTiles ( ) . end ( ) , [ ] ( TileRenderData & t1 , TileRenderData & t2 ) { return t1 . layerID < t2 . layerID ; } ) ;
}
}
return true ;
} ) ;
# pragma endregion
# pragma endregion
# pragma region Foreground and Upper Foreground Tile Fade Group Individual Object Grouping Splitting
# pragma region Foreground and Upper Foreground Tile Fade Group Individual Object Grouping Splitting (Loading phase 5)
auto SplitUp = [ & ] ( std : : vector < TileGroup > & group ) {
LoadingScreen : : AddPhase ( [ & ] ( ) {
std : : multimap < vi2d , TileRenderData > data ;
auto SplitUp = [ & ] ( std : : vector < TileGroup > & group ) {
using TileDataGroup = std : : multimap < vi2d , TileRenderData > ; //See below.
std : : multimap < vi2d , TileRenderData > data ;
std : : vector < TileDataGroup > splitUpData ; //This stores every tile group with tiles as a multi map.
using TileDataGroup = std : : multimap < vi2d , TileRenderData > ; //See below.
std : : set < vi2d > iteratedTiles ;
std : : vector < TileDataGroup > splitUpData ; //This stores every tile group with tiles as a multi map.
for ( TileGroup & group : group ) {
std : : set < vi2d > iteratedTiles ;
for ( TileRenderData & tile : group . GetTiles ( ) ) {
for ( TileGroup & group : group ) {
data . insert ( { tile . pos , tile } ) ;
for ( TileRenderData & tile : group . GetTiles ( ) ) {
data . insert ( { tile . pos , tile } ) ;
}
}
}
}
auto IsAdjacent = [ ] ( int tile1 , int tile2 , int tileSheetWidth ) {
auto IsAdjacent = [ ] ( int tile1 , int tile2 , int tileSheetWidth ) {
return abs ( tile1 - tile2 ) = = 1 | | abs ( tile1 - tile2 ) > = tileSheetWidth - 1 & & abs ( tile1 - tile2 ) < = tileSheetWidth + 1 ;
return abs ( tile1 - tile2 ) = = 1 | | abs ( tile1 - tile2 ) > = tileSheetWidth - 1 & & abs ( tile1 - tile2 ) < = tileSheetWidth + 1 ;
} ;
} ;
for ( auto & [ key , tile ] : data ) {
for ( auto & [ key , tile ] : data ) {
if ( iteratedTiles . count ( key ) ) continue ;
if ( iteratedTiles . count ( key ) ) continue ;
vi2d loc = key ;
vi2d loc = key ;
auto loc_tiles = data . equal_range ( loc ) ;
auto loc_tiles = data . equal_range ( loc ) ;
for ( auto & it = loc_tiles . first ; it ! = loc_tiles . second ; + + it ) { //For each tile that exists at this position...
for ( auto & it = loc_tiles . first ; it ! = loc_tiles . second ; + + it ) { //For each tile that exists at this position...
TileRenderData & tile = ( * it ) . second ;
TileRenderData & tile = ( * it ) . second ;
bool groupFound = false ;
bool groupFound = false ;
for ( TileDataGroup & group : splitUpData ) { //See if this position can fit into any existing tile groups
for ( TileDataGroup & group : splitUpData ) { //See if this position can fit into any existing tile groups
for ( int y = - game - > GetCurrentMapData ( ) . tileheight ; y < = game - > GetCurrentMapData ( ) . tileheight ; y + = game - > GetCurrentMapData ( ) . tileheight ) {
for ( int y = - game - > GetCurrentMapData ( ) . tileheight ; y < = game - > GetCurrentMapData ( ) . tileheight ; y + = game - > GetCurrentMapData ( ) . tileheight ) {
for ( int x = - game - > GetCurrentMapData ( ) . tilewidth ; x < = game - > GetCurrentMapData ( ) . tilewidth ; x + = game - > GetCurrentMapData ( ) . tilewidth ) {
for ( int x = - game - > GetCurrentMapData ( ) . tilewidth ; x < = game - > GetCurrentMapData ( ) . tilewidth ; x + = game - > GetCurrentMapData ( ) . tilewidth ) {
if ( x ! = 0 | | y ! = 0 ) { //Check every adjacent location for a possible adjacent tile.
if ( x ! = 0 | | y ! = 0 ) { //Check every adjacent location for a possible adjacent tile.
vi2d checkOffset = loc + vi2d { x , y } ;
vi2d checkOffset = loc + vi2d { x , y } ;
auto find_tiles = group . equal_range ( checkOffset ) ; //Each tile group consists of tiles that may be adjacent to us. Find all tiles that are adjacent to us in this tile group.
auto find_tiles = group . equal_range ( checkOffset ) ; //Each tile group consists of tiles that may be adjacent to us. Find all tiles that are adjacent to us in this tile group.
for ( auto & it = find_tiles . first ; it ! = find_tiles . second ; + + it ) {
for ( auto & it = find_tiles . first ; it ! = find_tiles . second ; + + it ) {
//These are all tiles that were found adjacent to the location we are checking for. See if they match a potential group.
//These are all tiles that were found adjacent to the location we are checking for. See if they match a potential group.
TileRenderData & foundTile = ( * it ) . second ;
TileRenderData & foundTile = ( * it ) . second ;
if ( tile . tileSheet . tileset = = foundTile . tileSheet . tileset ) { //Let's first see if they are even in the same tileset.
if ( tile . tileSheet . tileset = = foundTile . tileSheet . tileset ) { //Let's first see if they are even in the same tileset.
//Let's get how many tiles wide this tile sheet is.
//Let's get how many tiles wide this tile sheet is.
int tileWidth = tile . tileSheet . tileset - > tilewidth ;
int tileWidth = tile . tileSheet . tileset - > tilewidth ;
int tileSheetWidth = tile . tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileWidth ;
int tileSheetWidth = tile . tileSheet . tileset - > tileset - > Sprite ( ) - > width / tileWidth ;
if ( IsAdjacent ( tile . tileID , foundTile . tileID , tileSheetWidth ) ) {
if ( IsAdjacent ( tile . tileID , foundTile . tileID , tileSheetWidth ) ) {
group . insert ( { loc , tile } ) ; //We add this tile to the group! It is adjacent!
group . insert ( { loc , tile } ) ; //We add this tile to the group! It is adjacent!
groupFound = true ;
groupFound = true ;
goto groupIterationDone ;
goto groupIterationDone ;
}
}
}
}
}
}
}
}
}
}
}
}
}
groupIterationDone :
if ( ! groupFound ) {
splitUpData . push_back ( { } ) ;
splitUpData . back ( ) . insert ( { loc , tile } ) ; //Since we could not find a group to fit in, we had to start a brand new group.
}
}
}
groupIterationDone :
iteratedTiles . insert ( loc ) ;
if ( ! groupFound ) {
splitUpData . push_back ( { } ) ;
splitUpData . back ( ) . insert ( { loc , tile } ) ; //Since we could not find a group to fit in, we had to start a brand new group.
}
}
}
iteratedTiles . insert ( loc ) ;
group . clear ( ) ;
}
for ( auto & split : splitUpData ) {
group . clear ( ) ;
TileGroup newGroup ;
for ( auto & split : splitUpData ) {
for ( auto & [ key , value ] : split ) {
TileGroup newGroup ;
newGroup . InsertTile ( value ) ;
for ( auto & [ key , value ] : split ) {
}
newGroup . InsertTile ( value ) ;
group . push_back ( newGroup ) ;
}
}
group . push_back ( newGroup ) ;
} ;
}
SplitUp ( foregroundTileGroups ) ;
} ;
SplitUp ( upperForegroundTileGroups ) ;
SplitUp ( foregroundTileGroups ) ;
return true ;
SplitUp ( upperForegroundTileGroups ) ;
} ) ;
# pragma endregion
# pragma endregion
# pragma region Bridge Layer Setup
# pragma region Bridge Layer Setup (Loading Phase 6)
bridgeLayerIndex = - 1 ;
LoadingScreen : : AddPhase ( [ & ] ( ) {
for ( int counter = 0 ; LayerTag & layer : MAP_DATA [ map ] . LayerData ) {
bridgeLayerIndex = - 1 ;
if ( IsBridgeLayer ( layer ) ) {
for ( int counter = 0 ; LayerTag & layer : MAP_DATA [ GetCurrentLevel ( ) ] . LayerData ) {
bridgeLayerIndex = counter ;
if ( IsBridgeLayer ( layer ) ) {
bridgeLayerIndex = counter ;
}
counter + + ;
}
}
counter + + ;
return true ;
}
} ) ;
# pragma endregion
# pragma endregion
for ( NPCData data : game - > MAP_DATA [ game - > GetCurrentLevel ( ) ] . npcs ) {
# pragma region Setup NPCs (Loading Phase 7)
if ( Unlock : : IsUnlocked ( data . unlockCondition ) ) {
LoadingScreen : : AddPhase ( [ & ] ( ) {
MONSTER_LIST . push_back ( Monster { data . spawnPos , MONSTER_DATA [ data . name ] } ) ;
for ( NPCData data : game - > MAP_DATA [ game - > GetCurrentLevel ( ) ] . npcs ) {
MONSTER_LIST . back ( ) . iframe_timer = INFINITE ;
if ( Unlock : : IsUnlocked ( data . unlockCondition ) ) {
MONSTER_LIST . back ( ) . npcData = data ;
MONSTER_LIST . push_back ( Monster { data . spawnPos , MONSTER_DATA [ data . name ] } ) ;
}
MONSTER_LIST . back ( ) . iframe_timer = INFINITE ;
}
MONSTER_LIST . back ( ) . npcData = data ;
}
}
return true ;
} ) ;
# pragma endregion
player - > GetAbility1 ( ) . cooldown = 0.f ;
# pragma region Setup Player and Camera (Loading Phase 8)
player - > GetAbility2 ( ) . cooldown = 0.f ;
LoadingScreen : : AddPhase ( [ & ] ( ) {
player - > GetAbility3 ( ) . cooldown = 0.f ;
player - > GetAbility1 ( ) . cooldown = 0.f ;
player - > GetAbility4 ( ) . cooldown = 0.f ;
player - > GetAbility2 ( ) . cooldown = 0.f ;
player - > GetRightClickAbility ( ) . cooldown = 0.f ;
player - > GetAbility3 ( ) . cooldown = 0.f ;
player - > useItem1 . cooldown = 0.f ;
player - > GetAbility4 ( ) . cooldown = 0.f ;
player - > useItem2 . cooldown = 0.f ;
player - > GetRightClickAbility ( ) . cooldown = 0.f ;
player - > useItem3 . cooldown = 0.f ;
player - > useItem1 . cooldown = 0.f ;
player - > useItem2 . cooldown = 0.f ;
player - > useItem3 . cooldown = 0.f ;
player - > upperLevel = false ; //Assume player starts on lower level.
player - > upperLevel = false ; //Assume player starts on lower level.
player - > ForceSetPos ( MAP_DATA [ map ] . MapData . playerSpawnLocation ) ; //Normal set pos does one axis and then the other, so this will make sure that we actually end up at the right spot and ignore collision rules.
player - > ForceSetPos ( MAP_DATA [ GetCurrentLevel ( ) ] . MapData . playerSpawnLocation ) ; //Normal set pos does one axis and then the other, so this will make sure that we actually end up at the right spot and ignore collision rules.
vf2d cameraStartPos = player - > GetPos ( ) + vf2d ( - 24 * 6 , 0 ) ;
vf2d cameraStartPos = player - > GetPos ( ) + vf2d ( - 24 * 6 , 0 ) ;
camera . MoveCamera ( cameraStartPos ) ;
camera . MoveCamera ( cameraStartPos ) ;
return true ;
} ) ;
# pragma endregion
pathfinder . Initialize ( ) ;
# pragma region Setup Pathfinding (Loading Phase 9)
Audio : : SetAudioEvent ( " Default Volume " ) ;
LoadingScreen : : AddPhase ( [ & ] ( ) {
game - > audioEngine . fullyLoaded = true ; //We assume there's no audio to load, so we just set the audio as fully loaded by default.
pathfinder . Initialize ( ) ;
if ( MAP_DATA [ map ] . bgmSongName . length ( ) > 0 ) {
return true ;
Audio : : PlayBGM ( MAP_DATA [ map ] . bgmSongName ) ;
} ) ;
DisableFadeIn ( true ) ;
# pragma endregion
if ( changeMusic = = PLAY_LEVEL_MUSIC ) {
# pragma region Audio Preparation (Loading Phase 10)
LoadingScreen : : AddPhase ( [ & ] ( ) {
Audio : : SetAudioEvent ( " Default Volume " ) ;
game - > audioEngine . fullyLoaded = true ; //We assume there's no audio to load, so we just set the audio as fully loaded by default.
if ( MAP_DATA [ GetCurrentLevel ( ) ] . bgmSongName . length ( ) > 0 ) {
Audio : : PrepareBGM ( MAP_DATA [ GetCurrentLevel ( ) ] . bgmSongName ) ;
DisableFadeIn ( true ) ;
}
return true ;
} ) ;
# pragma endregion
//Until the audio has stopped (by waiting for a set amount of time), we will respect the audio engine's wishes and not proceed.
LoadingScreen : : DeferLoad ( [ & ] ( ) { return audioEngine . playBGMWaitTime = = 0.f ; } ) ; //This is the wait time for the audio engine to finish.
# pragma region Audio Channel Loading (Count based on Audio::GetPrepareBGMLoopIterations)
for ( int i = 0 ; i < Audio : : GetPrepareBGMLoopIterations ( MAP_DATA [ GetCurrentLevel ( ) ] . bgmSongName ) ; i + + ) {
LoadingScreen : : AddPhase ( [ & ] ( ) {
Audio : : UpdateLoop ( ) ;
return true ;
} ) ;
}
# pragma endregion
LoadingScreen : : AddPhase ( [ & ] ( ) {
Audio : : BGM & track = audioEngine . bgm [ audioEngine . GetTrackName ( ) ] ;
for ( int trackID : track . GetChannelIDs ( ) ) {
audioEngine . Engine ( ) . Play ( trackID , true ) ;
}
return true ;
} ) ;
}
}
}
}
@ -2204,10 +2290,6 @@ const MapName&AiL::GetCurrentLevel()const{
return currentLevel ;
return currentLevel ;
}
}
std : : map < std : : string , std : : vector < ZoneData > > & AiL : : GetZoneData ( MapName map ) {
return MAP_DATA [ map ] . ZoneData ;
}
void AiL : : ChangePlayerClass ( Class cl ) {
void AiL : : ChangePlayerClass ( Class cl ) {
Ability itemAbility1 = player - > useItem1 ;
Ability itemAbility1 = player - > useItem1 ;
Ability itemAbility2 = player - > useItem2 ;
Ability itemAbility2 = player - > useItem2 ;
@ -3100,7 +3182,7 @@ void AiL::RenderFadeout(){
}
}
bool AiL : : GamePaused ( ) {
bool AiL : : GamePaused ( ) {
return fadeOutDuration > 0 | | disableFadeIn | | paused ;
return fadeOutDuration > 0 | | disableFadeIn | | paused | | LoadingScreen : : loading ;
}
}
void AiL : : PauseGame ( ) {
void AiL : : PauseGame ( ) {
@ -3338,12 +3420,22 @@ const bool AiL::GameInitialized()const {
rcode AiL : : LoadResource ( Renderable & renderable , std : : string_view imgPath , bool filter , bool clamp ) {
rcode AiL : : LoadResource ( Renderable & renderable , std : : string_view imgPath , bool filter , bool clamp ) {
rcode returnCode ;
rcode returnCode ;
if ( gamepack . Loaded ( ) ) {
if ( gamepack . Loaded ( ) ) {
returnCode = renderable . Load ( std : : string ( imgPath ) , & gamepack ) ;
returnCode = renderable . Load ( std : : string ( imgPath ) , & gamepack , filter , clamp ) ;
} else {
} else {
returnCode = renderable . Load ( std : : string ( imgPath ) ) ;
returnCode = renderable . Load ( std : : string ( imgPath ) , nullptr , filter , clamp ) ;
if ( " GENERATE_GAMEPACK " _B ) {
if ( " GENERATE_GAMEPACK " _B ) {
gamepack . AddFile ( std : : string ( imgPath ) ) ;
gamepack . AddFile ( std : : string ( imgPath ) ) ;
}
}
}
}
return returnCode ;
return returnCode ;
}
void AiL : : UpdateMonsters ( ) {
for ( Monster & m : MONSTER_LIST ) {
m . Update ( game - > GetElapsedTime ( ) ) ;
}
for ( Monster & m : game - > monstersToBeSpawned ) {
MONSTER_LIST . push_back ( m ) ;
}
game - > monstersToBeSpawned . clear ( ) ;
}
}