# pragma once
# include "olcPixelGameEngine.h"
# include "Animation.h"
# include "State.h"
# include "Buff.h"
# include "olcUTIL_Animate2D.h"
# include "DamageNumber.h"
# include <variant>
# include "MonsterAttribute.h"
# define GET_FLOAT(attribute) _Get<float>(attribute);
# define GET_INT(attribute) _Get<int>(attribute);
# define GET_STRING(attribute) _Get<std::string>(attribute);
# define GET_BOOL(attribute) _Get<bool>(attribute);
struct Player ;
enum MonsterAnimation {
IDLE ,
JUMP ,
SHOOT ,
DEATH
} ;
struct MonsterData {
private :
int id ;
std : : string name ;
int hp ;
int atk ;
float moveSpd ; //1.0=100%
float size ;
std : : vector < std : : string > animations ;
int strategy ;
int collisionDmg ;
std : : string jumpAnimation = " WARRIOR_IDLE_S " ;
std : : string shootAnimation = " WARRIOR_IDLE_S " ;
std : : string deathAnimation = " WARRIOR_IDLE_S " ;
public :
MonsterData ( ) ;
MonsterData ( int id , std : : string name , int hp , int atk , std : : vector < std : : string > animations , float moveSpd = 1.0f , float size = 1.0f , int strategy = 0 , int collisionDmg = 0 ) ;
int GetHealth ( ) ;
int GetAttack ( ) ;
float GetMoveSpdMult ( ) ;
float GetSizeMult ( ) ;
int GetAIStrategy ( ) ;
int GetCollisionDmg ( ) ;
int GetID ( ) ;
std : : string GetIdleAnimation ( ) ;
std : : string GetJumpAnimation ( ) ;
std : : string GetShootAnimation ( ) ;
std : : string GetDeathAnimation ( ) ;
std : : vector < std : : string > GetAnimations ( ) {
return animations ;
}
static void InitializeMonsterData ( ) ;
static std : : map < int , Renderable * > imgs ;
} ;
struct Monster {
friend struct STRATEGY ;
private :
int id = 0 ;
vf2d pos ;
vf2d vel = { 0 , 0 } ;
float friction = 400 ;
vf2d target = { 0 , 0 } ;
float targetAcquireTimer = 0 ;
int hp , maxhp ;
int atk ;
float moveSpd ;
float size ;
float attackCooldownTimer = 0 ;
float queueShotTimer = 0 ;
float z = 0 ;
float iframe_timer = 0 ;
Key facingDirection ;
int strategy ;
State state = State : : NORMAL ;
Animate2D : : Animation < std : : string > animation ;
Animate2D : : AnimationState internal_animState ;
float randomFrameOffset = 0.f ;
float deathTimer = 0.f ;
std : : vector < Buff > buffList ;
std : : string GetDeathAnimationName ( ) ;
bool hasHitPlayer = false ;
bool canMove = true ; //Set to false when stuck due to collisions.
bool upperLevel = false ;
vf2d pathTarget = { } ;
std : : vector < vf2d > path ;
int pathIndex = 0 ;
float lastHitTimer = 0 ;
std : : shared_ptr < DamageNumber > damageNumberPtr ;
int phase = 0 ;
bool diesNormally = true ; //If set to false, the monster death is handled in a special way. Set it to true when it's time to die.
float targetSize = 0 ;
std : : map < _ATTRIBUTE , std : : variant < VARIANTS > > attributes ;
protected :
public :
Monster ( ) = delete ;
Monster ( vf2d pos , MonsterData data , bool upperLevel = false ) ;
vf2d & GetPos ( ) ;
int GetHealth ( ) ;
int GetAttack ( ) ;
float GetMoveSpdMult ( ) ;
float GetSizeMult ( ) ;
Animate2D : : Frame GetFrame ( ) ;
void UpdateAnimation ( std : : string state ) ;
bool Update ( float fElapsedTime ) ;
//Returns true when damage is actually dealt. Provide whether or not the attack is on the upper level or not. Monsters must be on the same level to get hit by it. (there is a death check and level check here.)
//If you need to hurt multiple enemies try Crawler::HurtEnemies()
bool Hurt ( int damage , bool onUpperLevel ) ;
bool IsAlive ( ) ;
vf2d & GetTargetPos ( ) ;
Key GetFacingDirection ( ) ;
void Draw ( ) ;
void Collision ( Player * p ) ;
void Collision ( Monster & p ) ;
void Collision ( ) ;
void SetVelocity ( vf2d vel ) ;
//Returns false if the monster could not be moved to the requested location due to collision.
bool SetPosition ( vf2d pos ) ;
//Returns false if the monster could not be moved to the requested location due to collision.
bool SetX ( float x ) ;
//Returns false if the monster could not be moved to the requested location due to collision.
bool SetY ( float y ) ;
void PerformJumpAnimation ( ) ;
void PerformShootAnimation ( ) ;
void PerformIdleAnimation ( ) ;
bool OnUpperLevel ( ) ;
void Moved ( ) ;
void StartPathfinding ( float pathingTime ) ;
void PathAroundBehavior ( float fElapsedTime ) ;
void AddBuff ( BuffType type , float duration , float intensity ) ;
std : : vector < Buff > GetBuffs ( BuffType buff ) ;
State GetState ( ) ;
void SetState ( State newState ) ;
static void InitializeStrategies ( ) ;
bool HasIframes ( ) ;
float GetZ ( ) ;
std : : string GetStrategy ( ) ;
void SetSize ( float newSize , bool immediate = true ) ;
void Set ( _ATTRIBUTE a , std : : variant < VARIANTS > val ) ;
template < typename T >
T _Get ( _ATTRIBUTE a ) {
if ( attributes . count ( a ) > 0 ) {
return std : : get < T > ( attributes [ a ] ) ;
} else {
switch ( a . type ) {
case Attribute : : TYPE : : FLOAT : {
return 0 ;
} break ;
case Attribute : : TYPE : : INT : {
return 0 ;
} break ;
case Attribute : : TYPE : : STRING : {
return " " ;
} break ;
case Attribute : : TYPE : : BOOL : {
return false ;
} break ;
}
}
}
private :
struct STRATEGY {
static int _GetInt ( Monster & m , std : : string param , int strategyNumber , int index = 0 ) ;
static float _GetFloat ( Monster & m , std : : string param , int strategyNumber , int index = 0 ) ;
static std : : string _GetString ( Monster & m , std : : string param , int strategyNumber , int index = 0 ) ;
static void RUN_STRATEGY ( Monster & m , float fElapsedTime ) ;
static void RUN_TOWARDS ( Monster & m , float fElapsedTime , int strategyNumber ) ;
static void SHOOT_AFAR ( Monster & m , float fElapsedTime , int strategyNumber ) ;
static void TURRET ( Monster & m , float fElapsedTime , int strategyNumber ) ;
static void SLIMEKING ( Monster & m , float fElapsedTime , int strategyNumber ) ;
} ;
} ;
struct MonsterSpawner {
private :
vf2d pos ;
vf2d range ;
std : : vector < std : : pair < int , vf2d > > monsters ;
bool triggered = false ;
bool upperLevel = false ;
public :
MonsterSpawner ( ) ;
//For the monster list, the second pair item is the position relative to the spawner to spawn the monster.
MonsterSpawner ( vf2d pos , vf2d range , std : : vector < std : : pair < int , vf2d > > MONSTER_LIST , bool upperLevel = false ) ;
bool SpawnTriggered ( ) ;
vf2d GetRange ( ) ;
vf2d GetPos ( ) ;
bool DoesUpperLevelSpawning ( ) ;
void SetTriggered ( bool trigger , bool spawnMonsters = true ) ;
friend std : : ostream & operator < < ( std : : ostream & os , MonsterSpawner & rhs ) ;
} ;