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:
parent
3ee066bb88
commit
244ac80d2a
@ -25,6 +25,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void UpdateFadeTime(float fElapsedTime);
|
void UpdateFadeTime(float fElapsedTime);
|
||||||
vf2d scale={1,1};
|
vf2d scale={1,1};
|
||||||
|
bool dead=false; //When marked as dead it wil be removed by the next frame.
|
||||||
public:
|
public:
|
||||||
Animate2D::Animation<std::string>animation;
|
Animate2D::Animation<std::string>animation;
|
||||||
Animate2D::AnimationState internal_animState;
|
Animate2D::AnimationState internal_animState;
|
||||||
|
@ -384,32 +384,21 @@ void Crawler::UpdateCamera(float fElapsedTime){
|
|||||||
void Crawler::UpdateEffects(float fElapsedTime){
|
void Crawler::UpdateEffects(float fElapsedTime){
|
||||||
for(auto it=EMITTER_LIST.begin();it!=EMITTER_LIST.end();++it){
|
for(auto it=EMITTER_LIST.begin();it!=EMITTER_LIST.end();++it){
|
||||||
auto ptr=(*it).get();
|
auto ptr=(*it).get();
|
||||||
if(!ptr->Update(fElapsedTime)){
|
ptr->Update(fElapsedTime);
|
||||||
it=EMITTER_LIST.erase(it);
|
|
||||||
if(it==EMITTER_LIST.end()){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for(std::vector<std::unique_ptr<Effect>>::iterator it=backgroundEffects.begin();it!=backgroundEffects.end();++it){
|
for(std::vector<std::unique_ptr<Effect>>::iterator it=backgroundEffects.begin();it!=backgroundEffects.end();++it){
|
||||||
Effect*e=(*it).get();
|
Effect*e=(*it).get();
|
||||||
if(!e->Update(fElapsedTime)){
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for(std::vector<std::unique_ptr<Effect>>::iterator it=foregroundEffects.begin();it!=foregroundEffects.end();++it){
|
for(std::vector<std::unique_ptr<Effect>>::iterator it=foregroundEffects.begin();it!=foregroundEffects.end();++it){
|
||||||
Effect*e=(*it).get();
|
Effect*e=(*it).get();
|
||||||
if(!e->Update(fElapsedTime)){
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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){
|
for(auto it=foregroundEffectsToBeInserted.begin();it!=foregroundEffectsToBeInserted.end();++it){
|
||||||
foregroundEffects.push_back(std::move(*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->hitList.find(&m)==b->hitList.end()&&m.Hurt(b->damage,b->OnUpperLevel())){
|
||||||
if(!b->hitsMultiple){
|
if(!b->hitsMultiple){
|
||||||
if(b->MonsterHit(m)){
|
if(b->MonsterHit(m)){
|
||||||
it=BULLET_LIST.erase(it);
|
b->dead=true;
|
||||||
if(it==BULLET_LIST.end()){
|
continue;
|
||||||
goto outsideBulletLoop;
|
|
||||||
}
|
|
||||||
goto continueBulletLoop;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b->hitList[&m]=true;
|
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(geom2d::overlaps(geom2d::circle(player->GetPos(),12*player->GetSizeMult()/2),geom2d::circle(b->pos,b->radius))){
|
||||||
if(player->Hurt(b->damage,b->OnUpperLevel())){
|
if(player->Hurt(b->damage,b->OnUpperLevel())){
|
||||||
if(b->PlayerHit(player.get())){
|
if(b->PlayerHit(player.get())){
|
||||||
it=BULLET_LIST.erase(it);
|
b->dead=true;
|
||||||
if(it==BULLET_LIST.end()){
|
continue;
|
||||||
goto outsideBulletLoop;
|
|
||||||
}
|
|
||||||
goto continueBulletLoop;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,25 +452,17 @@ void Crawler::UpdateBullets(float fElapsedTime){
|
|||||||
b->pos+=b->vel*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){
|
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);
|
b->dead=true;
|
||||||
if(it==BULLET_LIST.end()){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
b->lifetime-=fElapsedTime;
|
b->lifetime-=fElapsedTime;
|
||||||
if(b->lifetime<=0){
|
if(b->lifetime<=0){
|
||||||
it=BULLET_LIST.erase(it);
|
b->dead=true;
|
||||||
if(it==BULLET_LIST.end()){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
continueBulletLoop:
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
outsideBulletLoop:
|
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){
|
void Crawler::HurtEnemies(vf2d pos,float radius,int damage,bool upperLevel){
|
||||||
for(Monster&m:MONSTER_LIST){
|
for(Monster&m:MONSTER_LIST){
|
||||||
|
@ -21,6 +21,7 @@ bool Effect::Update(float fElapsedTime){
|
|||||||
if(lifetime<=0){
|
if(lifetime<=0){
|
||||||
fadeout-=fElapsedTime;
|
fadeout-=fElapsedTime;
|
||||||
if(fadeout<=0){
|
if(fadeout<=0){
|
||||||
|
dead=true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "olcUTIL_Animate2D.h"
|
#include "olcUTIL_Animate2D.h"
|
||||||
|
|
||||||
struct Effect{
|
struct Effect{
|
||||||
|
friend class Crawler;
|
||||||
vf2d pos={0,0};
|
vf2d pos={0,0};
|
||||||
float lifetime=0;
|
float lifetime=0;
|
||||||
float fadeout=0;
|
float fadeout=0;
|
||||||
@ -13,6 +14,9 @@ struct Effect{
|
|||||||
float rotation=0;
|
float rotation=0;
|
||||||
float rotationSpd=0;
|
float rotationSpd=0;
|
||||||
bool additiveBlending=false;
|
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,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);
|
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);
|
virtual bool Update(float fElapsedTime);
|
||||||
|
@ -13,6 +13,7 @@ bool Emitter::Update(float fElapsedTime){
|
|||||||
}
|
}
|
||||||
timer-=fElapsedTime;
|
timer-=fElapsedTime;
|
||||||
if(timer<0){
|
if(timer<0){
|
||||||
|
dead=true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
#include "olcPixelGameEngine.h"
|
#include "olcPixelGameEngine.h"
|
||||||
|
|
||||||
struct Emitter{
|
struct Emitter{
|
||||||
|
friend class Crawler;
|
||||||
float frequency;
|
float frequency;
|
||||||
float timer;
|
float timer;
|
||||||
float lastEmit=0;
|
float lastEmit=0;
|
||||||
|
private:
|
||||||
|
bool dead=false;
|
||||||
|
public:
|
||||||
virtual ~Emitter()=default;
|
virtual ~Emitter()=default;
|
||||||
Emitter(float frequency,float timer);
|
Emitter(float frequency,float timer);
|
||||||
bool Update(float fElapsedTime);
|
bool Update(float fElapsedTime);
|
||||||
|
@ -110,6 +110,9 @@ bool Monster::SetY(float y){
|
|||||||
bool Monster::Update(float fElapsedTime){
|
bool Monster::Update(float fElapsedTime){
|
||||||
lastHitTimer=std::max(0.f,lastHitTimer-fElapsedTime);
|
lastHitTimer=std::max(0.f,lastHitTimer-fElapsedTime);
|
||||||
iframe_timer=std::max(0.f,iframe_timer-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){
|
||||||
if(size>targetSize){
|
if(size>targetSize){
|
||||||
size=std::max(targetSize,size-Crawler::SIZE_CHANGE_SPEED*fElapsedTime);
|
size=std::max(targetSize,size-Crawler::SIZE_CHANGE_SPEED*fElapsedTime);
|
||||||
|
@ -2,4 +2,10 @@
|
|||||||
#define SETUP(attribute,type) _ATTRIBUTE attribute{ATTRIBUTE_TYPE::type};
|
#define SETUP(attribute,type) _ATTRIBUTE attribute{ATTRIBUTE_TYPE::type};
|
||||||
|
|
||||||
SETUP(Attribute::IFRAME_TIME_UPON_HIT,FLOAT);
|
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{
|
struct _ATTRIBUTE{
|
||||||
ATTRIBUTE_TYPE type;
|
ATTRIBUTE_TYPE type;
|
||||||
|
_ATTRIBUTE(ATTRIBUTE_TYPE type);
|
||||||
|
private:
|
||||||
|
static int internal_id;
|
||||||
|
int id;
|
||||||
|
public:
|
||||||
bool operator<(const _ATTRIBUTE&rhs)const{
|
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;
|
#define SETUP(attribute) static _ATTRIBUTE attribute;
|
||||||
SETUP(IFRAME_TIME_UPON_HIT);
|
SETUP(IFRAME_TIME_UPON_HIT);
|
||||||
SETUP(SHOOT_RING_TIMER);
|
SETUP(SHOOT_RING_TIMER);
|
||||||
|
SETUP(SHOOT_RING_DELAY);
|
||||||
|
SETUP(SHOOT_RING_COUNTER);
|
||||||
};
|
};
|
@ -8,6 +8,8 @@ INCLUDE_game
|
|||||||
INCLUDE_BULLET_LIST
|
INCLUDE_BULLET_LIST
|
||||||
|
|
||||||
void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumber){
|
void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumber){
|
||||||
|
float bulletSpd=ConfigFloat("BulletSpd")/100*24;
|
||||||
|
|
||||||
switch(m.phase){
|
switch(m.phase){
|
||||||
case 0:{
|
case 0:{
|
||||||
m.size=ConfigInt("Phase1.Size")/100;
|
m.size=ConfigInt("Phase1.Size")/100;
|
||||||
@ -21,6 +23,14 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
|
|||||||
m.phase=2;
|
m.phase=2;
|
||||||
m.SetSize(ConfigFloat("Phase2.Size")/100,false);
|
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;
|
}break;
|
||||||
case 2:{
|
case 2:{
|
||||||
if(m.hp<=m.maxhp*ConfigFloat("Phase3.Change")/100){
|
if(m.hp<=m.maxhp*ConfigFloat("Phase3.Change")/100){
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 0
|
#define VERSION_PATCH 0
|
||||||
#define VERSION_BUILD 1101
|
#define VERSION_BUILD 1114
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
@ -78,12 +78,18 @@ MonsterStrategy
|
|||||||
JumpHeight = 1500
|
JumpHeight = 1500
|
||||||
ProjectileDamage = 10
|
ProjectileDamage = 10
|
||||||
JumpAttackDamage = 20
|
JumpAttackDamage = 20
|
||||||
|
|
||||||
|
BulletSpd = 150
|
||||||
|
|
||||||
Phase1
|
Phase1
|
||||||
{
|
{
|
||||||
Size = 800
|
Size = 800
|
||||||
ShootRepeatTime = 4.0
|
ShootRepeatTime = 4.0
|
||||||
ShootRingCount = 3
|
ShootRingCount = 3
|
||||||
#In degrees.
|
# Amount of time between each set of rings.
|
||||||
|
ShootRingDelay = 0.2
|
||||||
|
RingBulletCount = 16
|
||||||
|
# In degrees.
|
||||||
RingOffset = 10
|
RingOffset = 10
|
||||||
JumpAfter = 4 shots
|
JumpAfter = 4 shots
|
||||||
AirborneTime = 3.0
|
AirborneTime = 3.0
|
||||||
|
@ -149,6 +149,7 @@ namespace olc::utils
|
|||||||
return operator[](sProperty).GetProperty(name.substr(x + 1, name.size()));
|
return operator[](sProperty).GetProperty(name.substr(x + 1, name.size()));
|
||||||
else {
|
else {
|
||||||
std::cout<<"WARNING! Could not read Property "<<sProperty<<"! Potential bugs may occur."<<std::endl;
|
std::cout<<"WARNING! Could not read Property "<<sProperty<<"! Potential bugs may occur."<<std::endl;
|
||||||
|
throw;
|
||||||
return operator[](sProperty);
|
return operator[](sProperty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user