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.
This commit is contained in:
@@ -121,6 +121,10 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
|
|||||||
for(Monster&m:MONSTER_LIST){
|
for(Monster&m:MONSTER_LIST){
|
||||||
m.Update(fElapsedTime);
|
m.Update(fElapsedTime);
|
||||||
}
|
}
|
||||||
|
for(Monster&m:monstersToBeSpawned){
|
||||||
|
MONSTER_LIST.push_back(m);
|
||||||
|
}
|
||||||
|
monstersToBeSpawned.clear();
|
||||||
UpdateBullets(fElapsedTime);
|
UpdateBullets(fElapsedTime);
|
||||||
UpdateCamera(fElapsedTime);
|
UpdateCamera(fElapsedTime);
|
||||||
RenderWorld(fElapsedTime);
|
RenderWorld(fElapsedTime);
|
||||||
@@ -1374,4 +1378,8 @@ void Crawler::InitializeLevels(){
|
|||||||
INITLEVEL(CAMPAIGN_1_2);
|
INITLEVEL(CAMPAIGN_1_2);
|
||||||
|
|
||||||
LEVEL_NAMES.SetInitialized();
|
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 reflectionUpdateTimer=0;
|
||||||
float reflectionStepTime=0;
|
float reflectionStepTime=0;
|
||||||
std::set<vi2d>visibleTiles;
|
std::set<vi2d>visibleTiles;
|
||||||
|
std::vector<Monster>monstersToBeSpawned;
|
||||||
public:
|
public:
|
||||||
Crawler();
|
Crawler();
|
||||||
bool OnUserCreate() override;
|
bool OnUserCreate() override;
|
||||||
@@ -108,6 +109,7 @@ public:
|
|||||||
void RenderTile(vi2d pos,TilesheetData tileSheet,int tileSheetIndex,vi2d tileSheetPos);
|
void RenderTile(vi2d pos,TilesheetData tileSheet,int tileSheetIndex,vi2d tileSheetPos);
|
||||||
void RenderTile(TileRenderData&tileSheet,Pixel col);
|
void RenderTile(TileRenderData&tileSheet,Pixel col);
|
||||||
bool IsReflectiveTile(TilesheetData tileSheet,int tileID);
|
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{
|
struct TileGroupData{
|
||||||
vi2d tilePos;
|
vi2d tilePos;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#define INCLUDE_DAMAGENUMBER_LIST extern std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
|
#define INCLUDE_DAMAGENUMBER_LIST extern std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
|
||||||
#define INCLUDE_game extern Crawler*game;
|
#define INCLUDE_game extern Crawler*game;
|
||||||
#define INCLUDE_MONSTER_DATA extern std::map<int,MonsterData>MONSTER_DATA;
|
#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_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_EMITTER_LIST extern std::vector<std::unique_ptr<Emitter>>EMITTER_LIST;
|
||||||
#define INCLUDE_DATA extern utils::datafile DATA;
|
#define INCLUDE_DATA extern utils::datafile DATA;
|
||||||
|
|||||||
+1
-1
@@ -286,7 +286,7 @@ void MonsterSpawner::SetTriggered(bool trigger,bool spawnMonsters){
|
|||||||
triggered=trigger;
|
triggered=trigger;
|
||||||
if(spawnMonsters){
|
if(spawnMonsters){
|
||||||
for(std::pair<int,vf2d>&monsterInfo:monsters){
|
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
|
INCLUDE_ANIMATION_DATA
|
||||||
|
|
||||||
std::map<int,MonsterData>MONSTER_DATA;
|
std::map<int,MonsterData>MONSTER_DATA;
|
||||||
|
safemap<std::string,MonsterData*>MONSTER_NAME_DATA;
|
||||||
|
|
||||||
MonsterData::MonsterData()
|
MonsterData::MonsterData()
|
||||||
:atk(0),collisionDmg(0),hp(0),id(0),moveSpd(0),size(0),strategy(0){}
|
: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_DATA[id]=monster;
|
||||||
|
MONSTER_NAME_DATA[MonsterName]=&MONSTER_DATA[id];
|
||||||
|
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-3
@@ -10,6 +10,7 @@
|
|||||||
INCLUDE_game
|
INCLUDE_game
|
||||||
INCLUDE_BULLET_LIST
|
INCLUDE_BULLET_LIST
|
||||||
INCLUDE_ANIMATION_DATA
|
INCLUDE_ANIMATION_DATA
|
||||||
|
INCLUDE_MONSTER_NAME_DATA
|
||||||
|
|
||||||
typedef Attribute A;
|
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::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);
|
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");
|
int bulletCount=ConfigInt("Phase1.RingBulletCount");
|
||||||
for(int i=0;i<bulletCount;i++){
|
for(int i=0;i<bulletCount;i++){
|
||||||
float angle=((2*PI)/bulletCount)*i+angleOffset;
|
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){
|
if(currentPhase==1){
|
||||||
ShootBulletRing(m.F(A::SHOOT_RING_OFFSET));
|
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.V(A::JUMP_ORIGINAL_POS)=m.GetPos();
|
||||||
m.F(A::JUMP_ORIGINAL_LANDING_TIMER)=m.F(A::JUMP_LANDING_TIMER)=jumpDuration;
|
m.F(A::JUMP_ORIGINAL_LANDING_TIMER)=m.F(A::JUMP_LANDING_TIMER)=jumpDuration;
|
||||||
m.V(A::JUMP_TARGET_POS)=targetPos;
|
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){
|
if(m.hp<=m.maxhp*ConfigFloat("Phase2.Change")/100){
|
||||||
m.phase=2;
|
m.phase=2;
|
||||||
m.SetSize(ConfigFloat("Phase2.Size")/100,false);
|
m.SetSize(ConfigFloat("Phase2.Size")/100,false);
|
||||||
|
TransitionPhase(m.phase);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if(m.F(A::SHOOT_RING_TIMER)==0){
|
if(m.F(A::SHOOT_RING_TIMER)==0){
|
||||||
if(m.I(A::PATTERN_REPEAT_COUNT)>=ConfigInt("Phase1.JumpAfter")){
|
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){
|
if(m.hp<=m.maxhp*ConfigFloat("Phase3.Change")/100){
|
||||||
m.phase=3;
|
m.phase=3;
|
||||||
m.SetSize(ConfigFloat("Phase3.Size")/100,false);
|
m.SetSize(ConfigFloat("Phase3.Size")/100,false);
|
||||||
|
TransitionPhase(m.phase);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
case 3:{
|
case 3:{
|
||||||
if(m.hp<=m.maxhp*ConfigFloat("Phase4.Change")/100){
|
if(m.hp<=m.maxhp*ConfigFloat("Phase4.Change")/100){
|
||||||
m.phase=4;
|
m.phase=4;
|
||||||
m.SetSize(ConfigFloat("Phase4.Size")/100,false);
|
m.SetSize(ConfigFloat("Phase4.Size")/100,false);
|
||||||
|
TransitionPhase(m.phase);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
case 4:{
|
case 4:{
|
||||||
if(m.hp<=0){
|
if(m.hp<=0){
|
||||||
m.phase=5;
|
m.phase=5;
|
||||||
m.F(A::IFRAME_TIME_UPON_HIT)=1;
|
m.F(A::IFRAME_TIME_UPON_HIT)=1;
|
||||||
|
TransitionPhase(m.phase);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -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 1334
|
#define VERSION_BUILD 1342
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
|||||||
Reference in New Issue
Block a user