From 244ac80d2ac3a122d555797ffbcb9398b2804544 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 9 Sep 2023 04:43:52 -0500 Subject: [PATCH] Fix std::less comparison for Monster attributes. Cleaned up list deletion for bullets, emitters, and effects. Bullet ring implementation for slime king. --- Crawler/Bullet.h | 1 + Crawler/Crawler.cpp | 53 ++++++-------------- Crawler/Effect.cpp | 1 + Crawler/Effect.h | 4 ++ Crawler/Emitter.cpp | 1 + Crawler/Emitter.h | 4 ++ Crawler/Monster.cpp | 3 ++ Crawler/MonsterAttribute.cpp | 8 ++- Crawler/MonsterAttribute.h | 9 +++- Crawler/SlimeKing.cpp | 10 ++++ Crawler/Version.h | 2 +- Crawler/assets/config/MonsterStrategies.txt | 8 ++- Crawler/olcUTIL_DataFile.h | 1 + x64/Release/Crawler.exe | Bin 598016 -> 598016 bytes 14 files changed, 62 insertions(+), 43 deletions(-) diff --git a/Crawler/Bullet.h b/Crawler/Bullet.h index fe58dc5d..a1066c84 100644 --- a/Crawler/Bullet.h +++ b/Crawler/Bullet.h @@ -25,6 +25,7 @@ protected: private: void UpdateFadeTime(float fElapsedTime); vf2d scale={1,1}; + bool dead=false; //When marked as dead it wil be removed by the next frame. public: Animate2D::Animationanimation; Animate2D::AnimationState internal_animState; diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index fd721129..f4000d93 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -384,32 +384,21 @@ void Crawler::UpdateCamera(float fElapsedTime){ void Crawler::UpdateEffects(float fElapsedTime){ for(auto it=EMITTER_LIST.begin();it!=EMITTER_LIST.end();++it){ auto ptr=(*it).get(); - if(!ptr->Update(fElapsedTime)){ - it=EMITTER_LIST.erase(it); - if(it==EMITTER_LIST.end()){ - break; - } - } + ptr->Update(fElapsedTime); } for(std::vector>::iterator it=backgroundEffects.begin();it!=backgroundEffects.end();++it){ Effect*e=(*it).get(); - if(!e->Update(fElapsedTime)){ - it=backgroundEffects.erase(it); - if(it==backgroundEffects.end()){//In case we added effects to the vector and the vector has shifted in memory, we prematurely end. - break; - } - } + e->Update(fElapsedTime); } for(std::vector>::iterator it=foregroundEffects.begin();it!=foregroundEffects.end();++it){ Effect*e=(*it).get(); - if(!e->Update(fElapsedTime)){ - it=foregroundEffects.erase(it); - if(it==foregroundEffects.end()){//In case we added effects to the vector and the vector has shifted in memory, we prematurely end. - break; - } - } + e->Update(fElapsedTime); } + std::erase_if(EMITTER_LIST,[](std::unique_ptr&e){return e->dead;}); + std::erase_if(backgroundEffects,[](std::unique_ptr&e){return e->dead;}); + std::erase_if(foregroundEffects,[](std::unique_ptr&e){return e->dead;}); + for(auto it=foregroundEffectsToBeInserted.begin();it!=foregroundEffectsToBeInserted.end();++it){ foregroundEffects.push_back(std::move(*it)); } @@ -440,11 +429,8 @@ void Crawler::UpdateBullets(float fElapsedTime){ if(b->hitList.find(&m)==b->hitList.end()&&m.Hurt(b->damage,b->OnUpperLevel())){ if(!b->hitsMultiple){ if(b->MonsterHit(m)){ - it=BULLET_LIST.erase(it); - if(it==BULLET_LIST.end()){ - goto outsideBulletLoop; - } - goto continueBulletLoop; + b->dead=true; + continue; } } b->hitList[&m]=true; @@ -455,11 +441,8 @@ void Crawler::UpdateBullets(float fElapsedTime){ if(geom2d::overlaps(geom2d::circle(player->GetPos(),12*player->GetSizeMult()/2),geom2d::circle(b->pos,b->radius))){ if(player->Hurt(b->damage,b->OnUpperLevel())){ if(b->PlayerHit(player.get())){ - it=BULLET_LIST.erase(it); - if(it==BULLET_LIST.end()){ - goto outsideBulletLoop; - } - goto continueBulletLoop; + b->dead=true; + continue; } } } @@ -469,25 +452,17 @@ void Crawler::UpdateBullets(float fElapsedTime){ b->pos+=b->vel*fElapsedTime; } if(b->pos.x+b->radiuspos.x-b->radius>view.GetWorldBR().x||b->pos.y+b->radiuspos.y-b->radius>view.GetWorldBR().y){ - it=BULLET_LIST.erase(it); - if(it==BULLET_LIST.end()){ - break; - } + b->dead=true; continue; } b->lifetime-=fElapsedTime; if(b->lifetime<=0){ - it=BULLET_LIST.erase(it); - if(it==BULLET_LIST.end()){ - break; - } + b->dead=true; continue; } - continueBulletLoop: - continue; } outsideBulletLoop: - int a; + std::erase_if(BULLET_LIST,[](std::unique_ptr&b){return b->dead;}); } void Crawler::HurtEnemies(vf2d pos,float radius,int damage,bool upperLevel){ for(Monster&m:MONSTER_LIST){ diff --git a/Crawler/Effect.cpp b/Crawler/Effect.cpp index 7785344d..185c5087 100644 --- a/Crawler/Effect.cpp +++ b/Crawler/Effect.cpp @@ -21,6 +21,7 @@ bool Effect::Update(float fElapsedTime){ if(lifetime<=0){ fadeout-=fElapsedTime; if(fadeout<=0){ + dead=true; return false; } } diff --git a/Crawler/Effect.h b/Crawler/Effect.h index 650bb140..b7b0ba87 100644 --- a/Crawler/Effect.h +++ b/Crawler/Effect.h @@ -4,6 +4,7 @@ #include "olcUTIL_Animate2D.h" struct Effect{ + friend class Crawler; vf2d pos={0,0}; float lifetime=0; float fadeout=0; @@ -13,6 +14,9 @@ struct Effect{ float rotation=0; float rotationSpd=0; bool additiveBlending=false; +private: + bool dead=false; +public: Effect(vf2d pos,float lifetime,std::string animation,bool upperLevel,float size=1.0f,float fadeout=0.0f,vf2d spd={},Pixel col=WHITE,float rotation=0,float rotationSpd=0,bool additiveBlending=false); Effect(vf2d pos,float lifetime,std::string animation,bool upperLevel,vf2d size={1,1},float fadeout=0.0f,vf2d spd={},Pixel col=WHITE,float rotation=0,float rotationSpd=0,bool additiveBlending=false); virtual bool Update(float fElapsedTime); diff --git a/Crawler/Emitter.cpp b/Crawler/Emitter.cpp index b852a5ed..de8d90da 100644 --- a/Crawler/Emitter.cpp +++ b/Crawler/Emitter.cpp @@ -13,6 +13,7 @@ bool Emitter::Update(float fElapsedTime){ } timer-=fElapsedTime; if(timer<0){ + dead=true; return false; } return true; diff --git a/Crawler/Emitter.h b/Crawler/Emitter.h index df7e6f33..6f85c75d 100644 --- a/Crawler/Emitter.h +++ b/Crawler/Emitter.h @@ -2,9 +2,13 @@ #include "olcPixelGameEngine.h" struct Emitter{ + friend class Crawler; float frequency; float timer; float lastEmit=0; +private: + bool dead=false; +public: virtual ~Emitter()=default; Emitter(float frequency,float timer); bool Update(float fElapsedTime); diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index 2cd29d38..fc17b83c 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -110,6 +110,9 @@ bool Monster::SetY(float y){ bool Monster::Update(float fElapsedTime){ lastHitTimer=std::max(0.f,lastHitTimer-fElapsedTime); iframe_timer=std::max(0.f,iframe_timer-fElapsedTime); + Set(Attribute::SHOOT_RING_TIMER,std::max(0.f,GetFloat(Attribute::SHOOT_RING_TIMER)-fElapsedTime)); + Set(Attribute::SHOOT_RING_DELAY,std::max(0.f,GetFloat(Attribute::SHOOT_RING_DELAY)-fElapsedTime)); + Set(Attribute::SHOOT_RING_COUNTER,std::max(0.f,GetFloat(Attribute::SHOOT_RING_COUNTER)-fElapsedTime)); if(size!=targetSize){ if(size>targetSize){ size=std::max(targetSize,size-Crawler::SIZE_CHANGE_SPEED*fElapsedTime); diff --git a/Crawler/MonsterAttribute.cpp b/Crawler/MonsterAttribute.cpp index 6836b500..cd3097e7 100644 --- a/Crawler/MonsterAttribute.cpp +++ b/Crawler/MonsterAttribute.cpp @@ -2,4 +2,10 @@ #define SETUP(attribute,type) _ATTRIBUTE attribute{ATTRIBUTE_TYPE::type}; SETUP(Attribute::IFRAME_TIME_UPON_HIT,FLOAT); -SETUP(Attribute::SHOOT_RING_TIMER,FLOAT); \ No newline at end of file +SETUP(Attribute::SHOOT_RING_TIMER,FLOAT); +SETUP(Attribute::SHOOT_RING_DELAY,FLOAT); +SETUP(Attribute::SHOOT_RING_COUNTER,FLOAT); + +int _ATTRIBUTE::internal_id=0; +_ATTRIBUTE::_ATTRIBUTE(ATTRIBUTE_TYPE type) + :type(type),id(internal_id++){} \ No newline at end of file diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h index 7190f815..6e73775f 100644 --- a/Crawler/MonsterAttribute.h +++ b/Crawler/MonsterAttribute.h @@ -10,8 +10,13 @@ enum class ATTRIBUTE_TYPE{ struct _ATTRIBUTE{ ATTRIBUTE_TYPE type; + _ATTRIBUTE(ATTRIBUTE_TYPE type); +private: + static int internal_id; + int id; +public: bool operator<(const _ATTRIBUTE&rhs)const{ - return int(type)(m.GetPos(),vf2d{cos(angle),sin(angle)}*bulletSpd,6,ConfigInt("ProjectileDamage"),m.OnUpperLevel(),false,YELLOW,vf2d{6,6})); + } + m.Set(Attribute::SHOOT_RING_TIMER,ConfigFloat("Phase1.ShootRepeatTime")); + } }break; case 2:{ if(m.hp<=m.maxhp*ConfigFloat("Phase3.Change")/100){ diff --git a/Crawler/Version.h b/Crawler/Version.h index 34ef497a..18319868 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1101 +#define VERSION_BUILD 1114 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/MonsterStrategies.txt b/Crawler/assets/config/MonsterStrategies.txt index 8d78befe..4284ea4b 100644 --- a/Crawler/assets/config/MonsterStrategies.txt +++ b/Crawler/assets/config/MonsterStrategies.txt @@ -78,12 +78,18 @@ MonsterStrategy JumpHeight = 1500 ProjectileDamage = 10 JumpAttackDamage = 20 + + BulletSpd = 150 + Phase1 { Size = 800 ShootRepeatTime = 4.0 ShootRingCount = 3 - #In degrees. + # Amount of time between each set of rings. + ShootRingDelay = 0.2 + RingBulletCount = 16 + # In degrees. RingOffset = 10 JumpAfter = 4 shots AirborneTime = 3.0 diff --git a/Crawler/olcUTIL_DataFile.h b/Crawler/olcUTIL_DataFile.h index dbfadf1b..d0632827 100644 --- a/Crawler/olcUTIL_DataFile.h +++ b/Crawler/olcUTIL_DataFile.h @@ -149,6 +149,7 @@ namespace olc::utils return operator[](sProperty).GetProperty(name.substr(x + 1, name.size())); else { std::cout<<"WARNING! Could not read Property "<&wxKfwww$D BFo*yE