Fix std::less comparison for Monster attributes. Cleaned up list deletion for bullets, emitters, and effects. Bullet ring implementation for slime king.

pull/28/head
sigonasr2 1 year ago
parent 3ee066bb88
commit 244ac80d2a
  1. 1
      Crawler/Bullet.h
  2. 53
      Crawler/Crawler.cpp
  3. 1
      Crawler/Effect.cpp
  4. 4
      Crawler/Effect.h
  5. 1
      Crawler/Emitter.cpp
  6. 4
      Crawler/Emitter.h
  7. 3
      Crawler/Monster.cpp
  8. 8
      Crawler/MonsterAttribute.cpp
  9. 9
      Crawler/MonsterAttribute.h
  10. 10
      Crawler/SlimeKing.cpp
  11. 2
      Crawler/Version.h
  12. 8
      Crawler/assets/config/MonsterStrategies.txt
  13. 1
      Crawler/olcUTIL_DataFile.h
  14. BIN
      x64/Release/Crawler.exe

@ -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::Animation<std::string>animation;
Animate2D::AnimationState internal_animState;

@ -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){

@ -21,6 +21,7 @@ bool Effect::Update(float fElapsedTime){
if(lifetime<=0){
fadeout-=fElapsedTime;
if(fadeout<=0){
dead=true;
return false;
}
}

@ -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);

@ -13,6 +13,7 @@ bool Emitter::Update(float fElapsedTime){
}
timer-=fElapsedTime;
if(timer<0){
dead=true;
return false;
}
return true;

@ -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);

@ -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);

@ -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);
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++){}

@ -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)<int(rhs.type);
return int(id)<int(rhs.id);
}
};
@ -19,4 +24,6 @@ struct Attribute{
#define SETUP(attribute) static _ATTRIBUTE attribute;
SETUP(IFRAME_TIME_UPON_HIT);
SETUP(SHOOT_RING_TIMER);
SETUP(SHOOT_RING_DELAY);
SETUP(SHOOT_RING_COUNTER);
};

@ -8,6 +8,8 @@ INCLUDE_game
INCLUDE_BULLET_LIST
void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumber){
float bulletSpd=ConfigFloat("BulletSpd")/100*24;
switch(m.phase){
case 0:{
m.size=ConfigInt("Phase1.Size")/100;
@ -21,6 +23,14 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
m.phase=2;
m.SetSize(ConfigFloat("Phase2.Size")/100,false);
}
if(m.GetFloat(Attribute::SHOOT_RING_TIMER)==0){
int bulletCount=ConfigInt("Phase1.RingBulletCount");
for(int i=0;i<bulletCount;i++){
float angle=((2*PI)/bulletCount)*i;
BULLET_LIST.emplace_back(std::make_unique<Bullet>(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){

@ -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

@ -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

@ -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 "<<sProperty<<"! Potential bugs may occur."<<std::endl;
throw;
return operator[](sProperty);
}
}

Binary file not shown.
Loading…
Cancel
Save