Super big refactor of the animation storage and monster storage system using configuration files.
This commit is contained in:
+44
-16
@@ -1,27 +1,55 @@
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "Monster.h"
|
||||
#include "Animation.h"
|
||||
#include "config.h"
|
||||
#include "DEFINES.h"
|
||||
#include "safemap.h"
|
||||
|
||||
INCLUDE_DATA
|
||||
INCLUDE_STRATEGY_DATA
|
||||
|
||||
std::map<MonsterName,MonsterData>MONSTER_DATA={
|
||||
{SLIME_GREEN,MonsterData(MonsterName::SLIME_GREEN,10,5,
|
||||
{{AnimationState::GREEN_SLIME_IDLE,AnimationState::GREEN_SLIME_JUMP,AnimationState::GREEN_SLIME_ROLL,AnimationState::GREEN_SLIME_DIE,AnimationState::GREEN_SLIME_SPIT}},AnimationState::GREEN_SLIME_JUMP,AnimationState::GREEN_SLIME_SPIT,AnimationState::GREEN_SLIME_DIE
|
||||
,1.1f,0.8f,MonsterStrategy::RUN_TOWARDS,5)},
|
||||
{SLIME_BLUE,MonsterData(MonsterName::SLIME_BLUE,30,10,{{AnimationState::BLUE_SLIME_IDLE,AnimationState::BLUE_SLIME_JUMP,AnimationState::BLUE_SLIME_ROLL,AnimationState::BLUE_SLIME_DIE,AnimationState::BLUE_SLIME_SPIT}},AnimationState::BLUE_SLIME_JUMP,AnimationState::BLUE_SLIME_SPIT,AnimationState::BLUE_SLIME_DIE
|
||||
,0.8f,1.0f,MonsterStrategy::SHOOT_AFAR,0)},
|
||||
{SLIME_RED,MonsterData(MonsterName::SLIME_RED,25,10,{{AnimationState::RED_SLIME_IDLE,AnimationState::RED_SLIME_JUMP,AnimationState::RED_SLIME_ROLL,AnimationState::RED_SLIME_DIE,AnimationState::RED_SLIME_SPIT}},AnimationState::RED_SLIME_JUMP,AnimationState::RED_SLIME_SPIT,AnimationState::RED_SLIME_DIE
|
||||
,0.95f,1.2f,MonsterStrategy::RUN_TOWARDS,10)},
|
||||
{SLIME_YELLOW,MonsterData(MonsterName::SLIME_YELLOW,175,10,{{AnimationState::YELLOW_SLIME_IDLE,AnimationState::YELLOW_SLIME_JUMP,AnimationState::YELLOW_SLIME_ROLL,AnimationState::YELLOW_SLIME_DIE,AnimationState::YELLOW_SLIME_SPIT}},AnimationState::YELLOW_SLIME_JUMP,AnimationState::YELLOW_SLIME_SPIT,AnimationState::YELLOW_SLIME_DIE
|
||||
,0.4f,1.6f,MonsterStrategy::RUN_TOWARDS,15)},
|
||||
};
|
||||
|
||||
std::map<MonsterName,MonsterData>MONSTER_DATA;
|
||||
|
||||
MonsterData::MonsterData(){}
|
||||
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<AnimationState>animations,AnimationState jumpAnimation,AnimationState shootAnimation,AnimationState deathAnimation
|
||||
MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vector<std::string>animations,std::string jumpAnimation,std::string shootAnimation,std::string deathAnimation
|
||||
,float moveSpd,float size,MonsterStrategy strategy,int collisionDmg):
|
||||
type(type),hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy),animations(animations),collisionDmg(collisionDmg)
|
||||
,jumpAnimation(jumpAnimation),shootAnimation(shootAnimation),deathAnimation(deathAnimation){
|
||||
}
|
||||
void MonsterData::InitializeMonsterData(){
|
||||
for(int i=0;i<MonsterName::END;i++){
|
||||
std::string ID=DATA["Monsters"][std::to_string(i)]["DisplayName"].GetString(1);
|
||||
std::vector<std::string>animations{
|
||||
ID+"_JUMP",
|
||||
ID+"_SPIT",
|
||||
ID+"_DIE",
|
||||
ID+"_IDLE",
|
||||
};
|
||||
|
||||
//Add additional custom animations defined in the config.
|
||||
int animationCounter=0;
|
||||
while(DATA["Monsters"][std::to_string(i)].HasProperty("ANIMATION["+std::to_string(animationCounter)+"]")){
|
||||
animations.push_back(DATA["Monsters"][std::to_string(i)]["ANIMATION["+std::to_string(animationCounter)+"]"].GetString());
|
||||
animationCounter++;
|
||||
}
|
||||
|
||||
MonsterData monster(
|
||||
MonsterName(i),
|
||||
DATA["Monsters"][std::to_string(i)]["Health"].GetInt(),
|
||||
DATA["Monsters"][std::to_string(i)]["Attack"].GetInt(),
|
||||
animations,
|
||||
ID+"_JUMP",
|
||||
ID+"_SPIT",
|
||||
ID+"_DIE",
|
||||
DATA["Monsters"][std::to_string(i)]["MoveSpd"].GetReal()/100,
|
||||
DATA["Monsters"][std::to_string(i)]["Size"].GetReal()/100,
|
||||
STRATEGY_DATA[DATA["Monsters"][std::to_string(i)]["Strategy"].GetString()],
|
||||
DATA["Monsters"][std::to_string(i)]["CollisionDmg"].GetInt()
|
||||
);
|
||||
|
||||
MONSTER_DATA[MonsterName(i)]=monster;
|
||||
}
|
||||
}
|
||||
int MonsterData::GetHealth(){
|
||||
return hp;
|
||||
}
|
||||
@@ -44,14 +72,14 @@ MonsterStrategy MonsterData::GetAIStrategy(){
|
||||
return strategy;
|
||||
}
|
||||
|
||||
AnimationState MonsterData::GetJumpAnimation(){
|
||||
std::string MonsterData::GetJumpAnimation(){
|
||||
return jumpAnimation;
|
||||
}
|
||||
AnimationState MonsterData::GetShootAnimation(){
|
||||
std::string MonsterData::GetShootAnimation(){
|
||||
return shootAnimation;
|
||||
}
|
||||
|
||||
AnimationState MonsterData::GetDeathAnimation()
|
||||
std::string MonsterData::GetDeathAnimation()
|
||||
{
|
||||
return deathAnimation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user