Fix std::less comparison for Monster attributes. Cleaned up list deletion for bullets, emitters, and effects. Bullet ring implementation for slime king.
This commit is contained in:
+14
-39
@@ -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<std::unique_ptr<Effect>>::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<std::unique_ptr<Effect>>::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<Emitter>&e){return e->dead;});
|
||||
std::erase_if(backgroundEffects,[](std::unique_ptr<Effect>&e){return e->dead;});
|
||||
std::erase_if(foregroundEffects,[](std::unique_ptr<Effect>&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->radius<view.GetWorldTL().x||b->pos.x-b->radius>view.GetWorldBR().x||b->pos.y+b->radius<view.GetWorldTL().y||b->pos.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<Bullet>&b){return b->dead;});
|
||||
}
|
||||
void Crawler::HurtEnemies(vf2d pos,float radius,int damage,bool upperLevel){
|
||||
for(Monster&m:MONSTER_LIST){
|
||||
|
||||
Reference in New Issue
Block a user