Implemented monster update method and monster spawner methods.

pull/28/head
sigonasr2 1 year ago
parent 776bf9165d
commit 0f449a902a
  1. 43
      Crawler/Monster.cpp
  2. 21
      Crawler/Monster.h
  3. 8
      Crawler/MonsterData.cpp
  4. 5
      Crawler/main.cpp

@ -3,8 +3,8 @@
extern std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
MonsterData::MonsterData(){}
MonsterData::MonsterData(int hp,int atk,float moveSpd,float size,MonsterStrategy strategy):
hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy){
MonsterData::MonsterData(int hp,int atk,std::vector<AnimationState>animations,float moveSpd,float size,MonsterStrategy strategy):
hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy),animations(animations){
}
int MonsterData::GetHealth(){
return hp;
@ -25,6 +25,14 @@ MonsterStrategy MonsterData::GetAIStrategy(){
Monster::Monster(){}
Monster::Monster(vf2d pos,MonsterData data):
pos(pos),hp(data.GetHealth()),maxhp(data.GetHealth()),atk(data.GetAttack()),moveSpd(data.GetMoveSpdMult()),size(data.GetSizeMult()),strategy(data.GetAIStrategy()){
bool firstAnimation=true;
for(AnimationState&anim:data.GetAnimations()){
animation.AddState(anim,ANIMATION_DATA[anim]);
if(firstAnimation){
animation.ChangeState(internal_animState,anim);
firstAnimation=false;
}
}
}
vf2d&Monster::GetPos(){
return pos;
@ -40,4 +48,35 @@ float Monster::GetMoveSpdMult(){
}
float Monster::GetSizeMult(){
return size;
}
void Monster::UpdateAnimation(AnimationState state){
animation.ChangeState(internal_animState,state);
}
void Monster::Update(float fElapsedTime){
switch(strategy){
RUN_TOWARDS:{
}break;
SHOOT_AFAR:{
}break;
}
animation.UpdateState(internal_animState,fElapsedTime);
}
MonsterSpawner::MonsterSpawner(){}
MonsterSpawner::MonsterSpawner(vf2d pos,int range,std::vector<std::pair<MonsterData,vf2d>>monsters):
pos(pos),range(range),monsters(monsters){
}
bool MonsterSpawner::SpawnTriggered(){
return triggered;
}
int MonsterSpawner::GetRange(){
return range;
}
vf2d MonsterSpawner::GetPos(){
return pos;
}
void MonsterSpawner::SetTriggered(bool trigger){
triggered=trigger;
}

@ -13,16 +13,20 @@ struct MonsterData{
int atk;
float moveSpd;//1.0=100%
float size;
std::vector<AnimationState> animations;
MonsterStrategy strategy;
Animate2D::Animation<AnimationState>animation;
public:
MonsterData();
MonsterData(int hp,int atk,float moveSpd=1.0f,float size=1.0f,MonsterStrategy strategy=RUN_TOWARDS);
//When specifying animations, the first one will become the default animation.
MonsterData(int hp,int atk,std::vector<AnimationState>animations,float moveSpd=1.0f,float size=1.0f,MonsterStrategy strategy=RUN_TOWARDS);
int GetHealth();
int GetAttack();
float GetMoveSpdMult();
float GetSizeMult();
MonsterStrategy GetAIStrategy();
std::vector<AnimationState>GetAnimations(){
return animations;
}
};
enum MonsterName{
@ -40,6 +44,8 @@ struct Monster{
float moveSpd;
float size;
MonsterStrategy strategy;
Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState;
public:
Monster();
Monster(vf2d pos,MonsterData data);
@ -48,10 +54,21 @@ struct Monster{
int GetAttack();
float GetMoveSpdMult();
float GetSizeMult();
void UpdateAnimation(AnimationState state);
void Update(float fElapsedTime);
};
struct MonsterSpawner{
private:
vf2d pos;
int range;
std::vector<std::pair<MonsterData,vf2d>>monsters;
bool triggered;
public:
MonsterSpawner();
MonsterSpawner(vf2d pos,int range,std::vector<std::pair<MonsterData,vf2d>>monsters);
bool SpawnTriggered();
int GetRange();
vf2d GetPos();
void SetTriggered(bool trigger);
};

@ -1,10 +1,10 @@
#include "olcPixelGameEngine.h"
#include "Monster.h"
#include "Animation.h"
std::map<MonsterName,MonsterData>MONSTER_DATA={
{SLIME_GREEN,MonsterData(10,5,1.1f,0.8f,MonsterStrategy::RUN_TOWARDS)},
{SLIME_BLUE,MonsterData(30,10,0.8f,1.0f,MonsterStrategy::SHOOT_AFAR)},
{SLIME_RED,MonsterData(25,10,0.95f,1.2f,MonsterStrategy::RUN_TOWARDS)},
{SLIME_GREEN,MonsterData(10,5,{{AnimationState::GREEN_SLIME_IDLE,AnimationState::GREEN_SLIME_JUMP,AnimationState::GREEN_SLIME_ROLL,AnimationState::GREEN_SLIME_DIE,AnimationState::GREEN_SLIME_SPIT}},1.1f,0.8f,MonsterStrategy::RUN_TOWARDS)},
{SLIME_BLUE,MonsterData(30,10,{{AnimationState::BLUE_SLIME_IDLE,AnimationState::BLUE_SLIME_JUMP,AnimationState::BLUE_SLIME_ROLL,AnimationState::BLUE_SLIME_DIE,AnimationState::BLUE_SLIME_SPIT}},0.8f,1.0f,MonsterStrategy::SHOOT_AFAR)},
{SLIME_RED,MonsterData(25,10,{{AnimationState::RED_SLIME_IDLE,AnimationState::RED_SLIME_JUMP,AnimationState::RED_SLIME_ROLL,AnimationState::RED_SLIME_DIE,AnimationState::RED_SLIME_SPIT}},0.95f,1.2f,MonsterStrategy::RUN_TOWARDS)},
//{SLIME_YELLOW,{}},
};

@ -20,7 +20,6 @@ struct Player{
float moveSpd=1.0f;
float size=1.0f;
float attack_range=1.5f;
AnimationState animState=AnimationState::IDLE_S;
Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState;
Key lastReleasedMovementKey;
@ -95,6 +94,8 @@ class Crawler : public olc::PixelGameEngine
TileTransformedView view;
Player player=Player{{}};
Renderable GFX_Pl_Sheet,GFX_Slime_Sheet;
std::vector<MonsterSpawner>spawners;
std::vector<Monster>monsters;
public:
Crawler()
@ -132,7 +133,7 @@ public:
player.SetPos({4*24,4*24});
player.UpdateAnimation(AnimationState::IDLE_S);
std::cout<<MONSTER_DATA[SLIME_BLUE].GetHealth()<<std::endl;
return true;
}

Loading…
Cancel
Save