From 973813f0b512354966020b91aacc8acf54278d4b Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii <89110903+Nic0Nic0Nii@users.noreply.github.com> Date: Mon, 29 Jan 2024 18:27:08 +0000 Subject: [PATCH 1/3] Player no longer bounces off of NPCs. Bonus boss no longer continues charging if it makes contact with the player. Fix undefined pointer in TMXParser. Co-authored-by: sigonasr2 --- .vscode/settings.json | 3 ++- Adventures in Lestoria/DamageNumber.cpp | 2 +- Adventures in Lestoria/Monster.cpp | 11 +++++++++++ Adventures in Lestoria/Monster.h | 7 +++++-- Adventures in Lestoria/MonsterAttribute.h | 1 + Adventures in Lestoria/MonsterData.cpp | 3 ++- Adventures in Lestoria/Player.cpp | 2 +- Adventures in Lestoria/TMXParser.h | 12 ++++++------ Adventures in Lestoria/Ursule.cpp | 3 ++- .../assets/config/configuration.txt | 2 +- 10 files changed, 32 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 24ce3fcf..81969e1e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -91,7 +91,8 @@ "*.inc": "cpp", "future": "cpp", "any": "cpp", - "source_location": "cpp" + "source_location": "cpp", + "forward_list": "cpp" }, "editor.suggest.insertMode": "replace" } \ No newline at end of file diff --git a/Adventures in Lestoria/DamageNumber.cpp b/Adventures in Lestoria/DamageNumber.cpp index b294b11f..9d96dd04 100644 --- a/Adventures in Lestoria/DamageNumber.cpp +++ b/Adventures in Lestoria/DamageNumber.cpp @@ -54,7 +54,7 @@ DamageNumber::DamageNumber(vf2d pos,int damage,bool friendly,DamageNumberType ty } void DamageNumber::RecalculateSize(){ - float damageMultRatio=damage/game->GetPlayer()->GetBaseStat("Attack")/2.f; + float damageMultRatio=damage/game->GetPlayer()->GetStat("Attack")/2.f; riseSpd=originalRiseSpd; if(!friendly){ float newSize=std::clamp(roundf(damageMultRatio),1.0f,4.0f); diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index a4cafcff..dcd8b18c 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -400,6 +400,9 @@ void Monster::Collision(Player*p){ p->Knockback(knockbackVecNorm*knockbackStrength); #pragma endregion + + B(Attribute::COLLIDED_WITH_PLAYER)=true; + Collision(); } void Monster::Collision(Monster&m){ @@ -783,4 +786,12 @@ const float Monster::GetCollisionDamage()const{ void Monster::SetStrategyDeathFunction(std::functionfunc){ hasStrategyDeathFunction=true; strategyDeathFunc=func; +} + +const bool Monster::IsNPC()const{ + return MONSTER_DATA[name].IsNPC(); +} + +const bool MonsterData::IsNPC()const{ + return isNPC; } \ No newline at end of file diff --git a/Adventures in Lestoria/Monster.h b/Adventures in Lestoria/Monster.h index 57df3d5d..3066ac6a 100644 --- a/Adventures in Lestoria/Monster.h +++ b/Adventures in Lestoria/Monster.h @@ -71,7 +71,7 @@ struct MonsterDropData{ }; struct MonsterData{ - private: +private: std::string name; int hp; int atk; @@ -88,7 +88,8 @@ struct MonsterData{ EventName deathSound=""; EventName walkSound=""; std::vector dropData; - public: + bool isNPC=false; +public: MonsterData(); MonsterData(std::string name,int hp,int atk,const uint32_t xp,std::vectoranimations,std::vectordrops,float moveSpd=1.0f,float size=1.0f,std::string strategy="Run Towards",int collisionDmg=0); int GetHealth(); @@ -105,6 +106,7 @@ struct MonsterData{ const EventName&GetHurtSound(); const EventName&GetDeathSound(); const EventName&GetWalkSound(); + const bool IsNPC()const; std::vectorGetAnimations(){ return animations; } @@ -193,6 +195,7 @@ public: void RotateTowardsPos(const vf2d&targetPos); const float GetDamageReductionFromBuffs()const; const float GetCollisionDamage()const; + const bool IsNPC()const; private: std::string name; vf2d pos; diff --git a/Adventures in Lestoria/MonsterAttribute.h b/Adventures in Lestoria/MonsterAttribute.h index 211a8457..a761146a 100644 --- a/Adventures in Lestoria/MonsterAttribute.h +++ b/Adventures in Lestoria/MonsterAttribute.h @@ -92,4 +92,5 @@ enum class Attribute{ BULLETS_REMOVED, BEAR_STOMP_COUNT, PREVIOUS_PHASE, + COLLIDED_WITH_PLAYER, //A boolean flag that is set to true when an enemy makes contact with the player. }; \ No newline at end of file diff --git a/Adventures in Lestoria/MonsterData.cpp b/Adventures in Lestoria/MonsterData.cpp index 9944d31e..67b89041 100644 --- a/Adventures in Lestoria/MonsterData.cpp +++ b/Adventures in Lestoria/MonsterData.cpp @@ -207,7 +207,7 @@ void MonsterData::InitializeMonsterData(){ } } void MonsterData::InitializeNPCData(){ - for(auto&[key,size]:DATA["NPCs"].GetKeys()){ + for(auto&[key,dataSize]:DATA["NPCs"].GetKeys()){ std::string NPCName=key; if(MONSTER_DATA.count(key)){ ERR("WARNING! A monster with the name "<accumulatedMonsterTags; std::mapstagePlates; bool infiniteMap=false; @@ -400,7 +400,7 @@ class TMXParser{ }; XMLTag newTag=ReadNextTag(); - + if (newTag.tag=="object"&&newTag.data["type"]!="StagePlate"){ currentStagePlate=nullptr; } @@ -514,13 +514,13 @@ class TMXParser{ } } }else{ - #if _DEBUG + #ifdef _DEBUG if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n"; #endif } - #if _DEBUG - if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n"; - #endif + #ifdef _DEBUG + if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n"; + #endif } TMXParser::TMXParser(std::string file){ fileName=file; diff --git a/Adventures in Lestoria/Ursule.cpp b/Adventures in Lestoria/Ursule.cpp index abf52f38..32d014b9 100644 --- a/Adventures in Lestoria/Ursule.cpp +++ b/Adventures in Lestoria/Ursule.cpp @@ -306,6 +306,7 @@ void Monster::STRATEGY::URSULE(Monster&m,float fElapsedTime,std::string strategy m.F(A::CASTING_TIMER)=ConfigFloat("Phase 3.Charge Cast Time"); m.UpdateFacingDirection(geom2d::line(m.GetPos(),game->GetPlayer()->GetPos()).vector()); m.PerformOtherAnimation(4); + m.B(A::COLLIDED_WITH_PLAYER)=false; } } if(m.F(A::CASTING_TIMER)>0.f){ @@ -350,7 +351,7 @@ void Monster::STRATEGY::URSULE(Monster&m,float fElapsedTime,std::string strategy float distToTarget=geom2d::line(m.target,m.GetPos()).length(); - if(distToTarget<=4.f||m.F(A::TARGET_TIMER)==0.f){ + if(distToTarget<=4.f||m.F(A::TARGET_TIMER)==0.f||m.B(A::COLLIDED_WITH_PLAYER)){ m.phase=3; m.RemoveBuff(SPEEDBOOST); m.RemoveBuff(FIXED_COLLISION_DMG); diff --git a/Adventures in Lestoria/assets/config/configuration.txt b/Adventures in Lestoria/assets/config/configuration.txt index 05802dd1..6b10f41e 100644 --- a/Adventures in Lestoria/assets/config/configuration.txt +++ b/Adventures in Lestoria/assets/config/configuration.txt @@ -120,7 +120,7 @@ debug_access_options = 0 debug_menu_navigation_info = 0 # Shows map loading output -debug_map_load_info = 0 +debug_map_load_info = 1 # Shows state transition information debug_transition_info = 0 From 2e3e8dd910e2f9dc81097b8b32b45747d5322a4d Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii <89110903+Nic0Nic0Nii@users.noreply.github.com> Date: Mon, 29 Jan 2024 19:01:51 +0000 Subject: [PATCH 2/3] Add debug flag when building emscripten in debug mode. Co-authored-by: sigonasr2 --- .../AdventuresInLestoria.cpp | 50 ++++++++++--------- Adventures in Lestoria/Error.h | 14 ++++-- .../assets/config/configuration.txt | 2 +- CMakeLists.txt | 6 +++ debug.sh | 2 +- emscripten_debug_build.ps1 | 2 +- 6 files changed, 47 insertions(+), 29 deletions(-) diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 494238bb..855d0346 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -2233,31 +2233,35 @@ int main() } #ifdef _DEBUG - HANDLE hLogFile; - hLogFile = CreateFile(L"assets/memoryleak.txt", GENERIC_WRITE, - FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, NULL); - _CrtSetReportMode(_CRT_WARN,_CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_WARN,hLogFile); - _CrtDumpMemoryLeaks(); - CloseHandle(hLogFile); - - std::ifstream file("assets/memoryleak.txt"); - bool leaked=false; - while(file.good()){ - std::string line; - std::getline(file,line); - if(line.find("AiL\\")!=std::string::npos){ - if(!leaked){ - leaked=true; - std::cout< #ifdef _DEBUG - #define NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) - // Replace _NORMAL_BLOCK with _CLIENT_BLOCK if you want the - // allocations to be of _CLIENT_BLOCK type +#ifndef __EMSCRIPTEN__ +#ifndef __linux__ + #define NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) + // Replace _NORMAL_BLOCK with _CLIENT_BLOCK if you want the + // allocations to be of _CLIENT_BLOCK type +#else + #define NEW new +#endif +#else + #define NEW new +#endif #else #define NEW new #endif diff --git a/Adventures in Lestoria/assets/config/configuration.txt b/Adventures in Lestoria/assets/config/configuration.txt index 6b10f41e..05802dd1 100644 --- a/Adventures in Lestoria/assets/config/configuration.txt +++ b/Adventures in Lestoria/assets/config/configuration.txt @@ -120,7 +120,7 @@ debug_access_options = 0 debug_menu_navigation_info = 0 # Shows map loading output -debug_map_load_info = 1 +debug_map_load_info = 0 # Shows state transition information debug_transition_info = 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d83ac7c..86e1cc08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -311,6 +311,12 @@ if (EMSCRIPTEN) # Build Cache: SDL2_mixer, libpng, zlib execute_process(COMMAND "${EMSCRIPTEN_ROOT_PATH}/embuilder${EMCC_SUFFIX}" build sdl2_mixer freetype libpng zlib) + + target_compile_definitions( + ${OutputExecutable} + PUBLIC + $<$:_DEBUG> + ) if(EXISTS "${SOURCE_DATA_DIR}" AND IS_DIRECTORY "${SOURCE_DATA_DIR}") target_link_options( diff --git a/debug.sh b/debug.sh index 8f1856e5..ee4fcf21 100755 --- a/debug.sh +++ b/debug.sh @@ -1 +1 @@ -cmake -DCMAKE_BUILD_TYPE=Debug .;make -j 8 +cmake -DCMAKE_BUILD_TYPE=Debug -D_DEBUG=1 .;make -j 8 diff --git a/emscripten_debug_build.ps1 b/emscripten_debug_build.ps1 index dd23ac42..1892785d 100644 --- a/emscripten_debug_build.ps1 +++ b/emscripten_debug_build.ps1 @@ -1,3 +1,3 @@ clear -emcmake cmake -DCMAKE_BUILD_TYPE=Debug . +emcmake cmake -DCMAKE_BUILD_TYPE=Debug -D_DEBUG=1 . cmake --build . -j 8 \ No newline at end of file From bc2b98094708a8c1ebb27dc31acb649e32e46e2a Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii <89110903+Nic0Nic0Nii@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:22:12 +0000 Subject: [PATCH 3/3] Damage numbers now clamp to view edges. --- .../AdventuresInLestoria.cpp | 52 +++++++++++-------- Adventures in Lestoria/Monster.cpp | 4 +- emscripten_debug_build.sh | 4 ++ 3 files changed, 37 insertions(+), 23 deletions(-) create mode 100755 emscripten_debug_build.sh diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 855d0346..47dcedd9 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -1365,42 +1365,52 @@ void AiL::RenderWorld(float fElapsedTime){ } } } + + #define NumberScalesWithDamage true + #define NormalNumber false + + auto DrawDamageNumber=[&](const bool ScaleWithNumber,std::string_view text,std::paircolorsEnemy,std::paircolorsFriendly,vf2d scaling={1.f,1.f}){ + vf2d textSize=GetTextSizeProp(text)*scaling; + if(!dn->friendly){ + vf2d additionalScaling={1.f,1.f}; + if(ScaleWithNumber)additionalScaling=dn->size; + + textSize*=additionalScaling; + vf2d drawPos=dn->pos-textSize/2.f; + + drawPos.x=std::clamp(drawPos.x,view.GetWorldTL().x,view.GetWorldBR().x-textSize.x); + drawPos.y=std::clamp(drawPos.y,view.GetWorldTL().y,view.GetWorldBR().y-textSize.y); + + view.DrawShadowStringPropDecal(drawPos,text,colorsEnemy.first,colorsEnemy.second,scaling*additionalScaling); + }else{ + vf2d drawPos=dn->pos-textSize/2.f; + drawPos.x=std::clamp(drawPos.x,view.GetWorldTL().x,view.GetWorldBR().x-textSize.x); + drawPos.y=std::clamp(drawPos.y,view.GetWorldTL().y,view.GetWorldBR().y-textSize.y); + + view.DrawShadowStringPropDecal(drawPos,text,colorsFriendly.first,colorsFriendly.second,scaling); + } + }; + switch(dn->type){ case HEALTH_LOSS:{ std::string text=std::to_string(dn->damage); - if(!dn->friendly){ - view.DrawStringPropDecal(dn->pos-GetTextSizeProp(text)/2.f*dn->size,text,DARK_RED,dn->size); - }else{ - view.DrawShadowStringPropDecal(dn->pos-GetTextSizeProp(text)/2,text,RED,VERY_DARK_GREY); - } + DrawDamageNumber(NumberScalesWithDamage,text,{DARK_RED,{0,0,0,0}},{RED,VERY_DARK_GREY}); }break; case HEALTH_GAIN:{ std::string text="+"+std::to_string(dn->damage); - if(!dn->friendly){ - view.DrawStringPropDecal(dn->pos-GetTextSizeProp(text)/2,text,DARK_GREEN); - }else{ - view.DrawShadowStringPropDecal(dn->pos-GetTextSizeProp(text)/2,text,GREEN,VERY_DARK_GREY); - } + DrawDamageNumber(NormalNumber,text,{DARK_GREEN,{0,0,0,0}},{GREEN,VERY_DARK_GREY}); }break; case MANA_GAIN:{ std::string text="+"+std::to_string(dn->damage); - if(dn->friendly){ - view.DrawShadowStringPropDecal(dn->pos-GetTextSizeProp(text)/2,text,BLUE,VERY_DARK_GREY); - } + DrawDamageNumber(NormalNumber,text,{BLUE,VERY_DARK_GREY},{BLUE,VERY_DARK_GREY}); }break; case INTERRUPT:{ std::string text="Interrupted!"; - if(dn->friendly){ - view.DrawShadowStringPropDecal(dn->pos-GetTextSizeProp(text)/2,text,BLACK,VERY_DARK_GREY,{0.5,1}); - } + DrawDamageNumber(NormalNumber,text,{BLACK,VERY_DARK_GREY},{BLACK,VERY_DARK_GREY},{0.5f,1}); }break; case CRIT:{ std::string text=std::to_string(dn->damage); - if(!dn->friendly){ - view.DrawShadowStringPropDecal(dn->pos-GetTextSizeProp(text)/2.f*dn->size,text,YELLOW,DARK_YELLOW,dn->size); - }else{ - view.DrawStringPropDecal(dn->pos-GetTextSizeProp(text)/2,text,BLACK); - } + DrawDamageNumber(NumberScalesWithDamage,text,{YELLOW,DARK_YELLOW},{BLACK,{0,0,0,0}}); }break; } } diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index dcd8b18c..2923e48f 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -690,8 +690,8 @@ void Monster::OnDeath(){ const geom2d::rectarenaBounds=game->GetZones().at("BossArena")[0].zone; geom2d::rectclampedArena{vi2d(arenaBounds.pos+"boss_spawn_ring_radius"_I),vi2d(arenaBounds.size-"boss_spawn_ring_radius"_I*2)}; - exitRing.zone.pos.x=std::clamp(exitRing.zone.pos.x,clampedArena.pos.x,clampedArena.pos.x+clampedArena.size.x); - exitRing.zone.pos.y=std::clamp(exitRing.zone.pos.y,clampedArena.pos.y,clampedArena.pos.y+clampedArena.size.y); + exitRing.zone.pos.x=std::clamp(exitRing.zone.pos.x,clampedArena.pos.x-"boss_spawn_ring_radius"_I,clampedArena.pos.x-"boss_spawn_ring_radius"_I+clampedArena.size.x); + exitRing.zone.pos.y=std::clamp(exitRing.zone.pos.y,clampedArena.pos.y-"boss_spawn_ring_radius"_I,clampedArena.pos.y-"boss_spawn_ring_radius"_I+clampedArena.size.y); game->AddZone("EndZone",exitRing); //Create a 144x144 ring around the dead boss. } diff --git a/emscripten_debug_build.sh b/emscripten_debug_build.sh new file mode 100755 index 00000000..4a0a7900 --- /dev/null +++ b/emscripten_debug_build.sh @@ -0,0 +1,4 @@ +clear +source ./emsdk/emsdk_env.sh +emcmake cmake -DCMAKE_BUILD_TYPE=Debug -D_DEBUG=1 . +cmake --build . -j 8 \ No newline at end of file