Monster spawning now adds to a queue to prevent memory adjustment corruption while inside of monster update functions.

Monster spawning on phase transition now occurs.
pull/28/head
sigonasr2 1 year ago
parent c816a0eac7
commit 74a31dda2e
  1. 8
      Crawler/Crawler.cpp
  2. 2
      Crawler/Crawler.h
  3. 1
      Crawler/DEFINES.h
  4. 2
      Crawler/Monster.cpp
  5. 2
      Crawler/MonsterData.cpp
  6. 50
      Crawler/SlimeKing.cpp
  7. 2
      Crawler/Version.h

@ -121,6 +121,10 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
for(Monster&m:MONSTER_LIST){
m.Update(fElapsedTime);
}
for(Monster&m:monstersToBeSpawned){
MONSTER_LIST.push_back(m);
}
monstersToBeSpawned.clear();
UpdateBullets(fElapsedTime);
UpdateCamera(fElapsedTime);
RenderWorld(fElapsedTime);
@ -1375,3 +1379,7 @@ void Crawler::InitializeLevels(){
LEVEL_NAMES.SetInitialized();
}
void Crawler::SpawnMonster(vf2d pos,MonsterData*data,bool upperLevel){
monstersToBeSpawned.push_back(Monster(pos,*data,upperLevel));
}

@ -47,6 +47,7 @@ private:
float reflectionUpdateTimer=0;
float reflectionStepTime=0;
std::set<vi2d>visibleTiles;
std::vector<Monster>monstersToBeSpawned;
public:
Crawler();
bool OnUserCreate() override;
@ -108,6 +109,7 @@ public:
void RenderTile(vi2d pos,TilesheetData tileSheet,int tileSheetIndex,vi2d tileSheetPos);
void RenderTile(TileRenderData&tileSheet,Pixel col);
bool IsReflectiveTile(TilesheetData tileSheet,int tileID);
void SpawnMonster(vf2d pos,MonsterData*data,bool upperLevel=false); //Queues a monster for spawning on the next frame.
struct TileGroupData{
vi2d tilePos;

@ -5,6 +5,7 @@
#define INCLUDE_DAMAGENUMBER_LIST extern std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
#define INCLUDE_game extern Crawler*game;
#define INCLUDE_MONSTER_DATA extern std::map<int,MonsterData>MONSTER_DATA;
#define INCLUDE_MONSTER_NAME_DATA extern safemap<std::string,MonsterData*>MONSTER_NAME_DATA;
#define INCLUDE_BULLET_LIST extern std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
#define INCLUDE_EMITTER_LIST extern std::vector<std::unique_ptr<Emitter>>EMITTER_LIST;
#define INCLUDE_DATA extern utils::datafile DATA;

@ -286,7 +286,7 @@ void MonsterSpawner::SetTriggered(bool trigger,bool spawnMonsters){
triggered=trigger;
if(spawnMonsters){
for(std::pair<int,vf2d>&monsterInfo:monsters){
MONSTER_LIST.push_back(Monster(pos+monsterInfo.second,MONSTER_DATA[monsterInfo.first],DoesUpperLevelSpawning()));
game->SpawnMonster(pos+monsterInfo.second,&MONSTER_DATA[monsterInfo.first],DoesUpperLevelSpawning());
}
}
}

@ -10,6 +10,7 @@ INCLUDE_STRATEGY_DATA
INCLUDE_ANIMATION_DATA
std::map<int,MonsterData>MONSTER_DATA;
safemap<std::string,MonsterData*>MONSTER_NAME_DATA;
MonsterData::MonsterData()
:atk(0),collisionDmg(0),hp(0),id(0),moveSpd(0),size(0),strategy(0){}
@ -98,6 +99,7 @@ void MonsterData::InitializeMonsterData(){
);
MONSTER_DATA[id]=monster;
MONSTER_NAME_DATA[MonsterName]=&MONSTER_DATA[id];
id++;
}

@ -10,6 +10,7 @@
INCLUDE_game
INCLUDE_BULLET_LIST
INCLUDE_ANIMATION_DATA
INCLUDE_MONSTER_NAME_DATA
typedef Attribute A;
@ -22,7 +23,7 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
m.F(A::SHOOT_RING_DELAY)=std::max(0.f,m.F(A::SHOOT_RING_DELAY)-fElapsedTime);
m.F(A::JUMP_LANDING_TIMER)=std::max(0.f,m.F(A::JUMP_LANDING_TIMER)-fElapsedTime);
auto ShootBulletRing=[&](float angleOffset){
const auto ShootBulletRing=[&](float angleOffset){
int bulletCount=ConfigInt("Phase1.RingBulletCount");
for(int i=0;i<bulletCount;i++){
float angle=((2*PI)/bulletCount)*i+angleOffset;
@ -30,13 +31,48 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
}
};
auto Landed=[&ShootBulletRing,&m](int currentPhase){
const auto Landed=[&ShootBulletRing,&m](int currentPhase){
if(currentPhase==1){
ShootBulletRing(m.F(A::SHOOT_RING_OFFSET));
}
};
auto StartJump=[&](float jumpDuration,vf2d targetPos,float recoveryTime){
const auto TransitionPhase=[&](int newPhase){
switch(newPhase){
case 2:{
std::string spawnMonster=ConfigStringArr("Phase2.MonsterSpawnOnChange",0);
int spawnCount=ConfigIntArr("Phase2.MonsterSpawnOnChange",1);
for(int i=0;i<spawnCount;i++){
float randomAngle=util::random(2*PI);
game->SpawnMonster(m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12,MONSTER_NAME_DATA[spawnMonster]);
}
}break;
case 3:{
std::string spawnMonster=ConfigStringArr("Phase3.MonsterSpawnOnChange",0);
int spawnCount=ConfigIntArr("Phase3.MonsterSpawnOnChange",1);
for(int i=0;i<spawnCount;i++){
float randomAngle=util::random(2*PI);
game->SpawnMonster(m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12,MONSTER_NAME_DATA[spawnMonster]);
}
}break;
case 4:{
std::string spawnMonster=ConfigStringArr("Phase4.MonsterSpawnOnChange",0);
int spawnCount=ConfigIntArr("Phase4.MonsterSpawnOnChange",1);
for(int i=0;i<spawnCount;i++){
float randomAngle=util::random(2*PI);
game->SpawnMonster(m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12,MONSTER_NAME_DATA[spawnMonster]);
}
}break;
case 5:{
}break;
}
};
const auto StartJump=[&](float jumpDuration,vf2d targetPos,float recoveryTime){
m.V(A::JUMP_ORIGINAL_POS)=m.GetPos();
m.F(A::JUMP_ORIGINAL_LANDING_TIMER)=m.F(A::JUMP_LANDING_TIMER)=jumpDuration;
m.V(A::JUMP_TARGET_POS)=targetPos;
@ -112,6 +148,8 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
if(m.hp<=m.maxhp*ConfigFloat("Phase2.Change")/100){
m.phase=2;
m.SetSize(ConfigFloat("Phase2.Size")/100,false);
TransitionPhase(m.phase);
return;
}
if(m.F(A::SHOOT_RING_TIMER)==0){
if(m.I(A::PATTERN_REPEAT_COUNT)>=ConfigInt("Phase1.JumpAfter")){
@ -143,18 +181,24 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
if(m.hp<=m.maxhp*ConfigFloat("Phase3.Change")/100){
m.phase=3;
m.SetSize(ConfigFloat("Phase3.Size")/100,false);
TransitionPhase(m.phase);
return;
}
}break;
case 3:{
if(m.hp<=m.maxhp*ConfigFloat("Phase4.Change")/100){
m.phase=4;
m.SetSize(ConfigFloat("Phase4.Size")/100,false);
TransitionPhase(m.phase);
return;
}
}break;
case 4:{
if(m.hp<=0){
m.phase=5;
m.F(A::IFRAME_TIME_UPON_HIT)=1;
TransitionPhase(m.phase);
return;
}
}break;
}

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 1334
#define VERSION_BUILD 1342
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save