The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'! https://forums.lestoria.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
AdventuresInLestoria/Crawler/Player.cpp

126 lines
2.5 KiB

#include "Monster.h"
#include "Player.h"
#include "Crawler.h"
#include "DamageNumber.h"
extern std::map<MonsterName,MonsterData>MONSTER_DATA;
extern std::vector<Monster>MONSTER_LIST;
extern std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
extern std::vector<MonsterSpawner>SPAWNER_LIST;
extern std::vector<DamageNumber>DAMAGENUMBER_LIST;
extern Crawler*game;
Player::Player(){
}
Player::Player(vf2d pos):
pos(pos){
}
void Player::SetX(float x){
pos.x=x;
};
void Player::SetY(float y){
pos.y=y;
}
void Player::SetZ(float z){
this->z=z;
}
void Player::SetPos(vf2d pos){
this->pos=pos;
}
vf2d&Player::GetPos(){
return pos;
}
float Player::GetX(){
return pos.x;
}
float Player::GetY(){
return pos.y;
}
float Player::GetZ(){
return z;
}
int Player::GetHealth(){
return hp;
}
int Player::GetMaxHealth(){
return maxhp;
}
int Player::GetAttack(){
return atk;
}
float Player::GetMoveSpdMult(){
return moveSpd;
}
float Player::GetSizeMult(){
return size;
}
float Player::GetAttackRangeMult(){
return attack_range;
}
void Player::Update(float fElapsedTime){
attack_cooldown_timer=std::max(0.f,attack_cooldown_timer-fElapsedTime);
animation.UpdateState(internal_animState,fElapsedTime);
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
bool attack=false;
for(Monster&m:MONSTER_LIST){
if(m.IsAlive()&&geom2d::overlaps(geom2d::circle<float>(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle<float>(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12))){
m.Hurt(atk);
attack=true;
break;
}
}
if(attack){
attack_cooldown_timer=ATTACK_COOLDOWN;
}
}
}
void Player::Hurt(int damage){
hp=std::max(0,hp-damage);
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
}
void Player::AddAnimation(AnimationState state){
animation.AddState(state,ANIMATION_DATA[state]);
}
void Player::UpdateAnimation(AnimationState animState){
animation.ChangeState(internal_animState,animState);
}
Animate2D::Frame Player::GetFrame(){
return animation.GetFrame(internal_animState);
}
void Player::SetLastReleasedMovementKey(Key k){
lastReleasedMovementKey=k;
}
Key Player::GetLastReleasedMovementKey(){
return lastReleasedMovementKey;
}
void Player::Moved(){
for(MonsterSpawner&spawner:SPAWNER_LIST){
if(!spawner.SpawnTriggered()&&geom2d::overlaps(geom2d::circle<float>(pos-vf2d{size*12,size*12},size*12),geom2d::circle<float>(spawner.GetPos(),spawner.GetRange()))){
spawner.SetTriggered(true);
}
}
}