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/Warrior.cpp

138 lines
5.6 KiB

#include "Class.h"
#include "olcPixelGameEngine.h"
#include "DEFINES.h"
#include "Player.h"
#include "Effect.h"
#include "Crawler.h"
INCLUDE_MONSTER_LIST
INCLUDE_BULLET_LIST
INCLUDE_game
std::string Warrior::name="Warrior";
Class Warrior::cl=WARRIOR;
Ability Warrior::rightClickAbility={"Block",15,0,VERY_DARK_BLUE,DARK_BLUE};
Ability Warrior::ability1={"Battlecry",12,40};
Ability Warrior::ability2={"Ground Slam",15,50};
Ability Warrior::ability3={"Sonic Slash",40,60};
Ability Warrior::ability4={"???",0,0};
AnimationState Warrior::idle_n=WARRIOR_IDLE_N;
AnimationState Warrior::idle_e=WARRIOR_IDLE_E;
AnimationState Warrior::idle_s=WARRIOR_IDLE_S;
AnimationState Warrior::idle_w=WARRIOR_IDLE_W;
AnimationState Warrior::walk_n=WARRIOR_WALK_N;
AnimationState Warrior::walk_e=WARRIOR_WALK_E;
AnimationState Warrior::walk_s=WARRIOR_WALK_S;
AnimationState Warrior::walk_w=WARRIOR_WALK_W;
SETUP_CLASS(Warrior)
void Warrior::OnUpdate(float fElapsedTime){
}
bool Warrior::AutoAttack(){
if(GetState()!=State::SPIN){
bool attack=false;
Monster*closest=nullptr;
float closest_dist=999999;
for(Monster&m:MONSTER_LIST){
if(m.IsAlive()
&&m.OnUpperLevel()==OnUpperLevel()
&&geom2d::overlaps(geom2d::circle<float>(GetPos()-vf2d{GetSizeMult()*12,GetSizeMult()*12},attack_range*GetSizeMult()*12),geom2d::circle<float>(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12))
&&geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length()<closest_dist){
closest_dist=geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length();
closest=&m;
}
}
if(closest!=nullptr&&closest->Hurt(GetAttack(),OnUpperLevel())){
attack_cooldown_timer=ATTACK_COOLDOWN;
swordSwingTimer=0.2;
SetState(State::SWING_SWORD);
switch(facingDirection){
case DOWN:{
UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_S,WARRIOR|THIEF);
}break;
case RIGHT:{
UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_E,WARRIOR|THIEF);
}break;
case LEFT:{
UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_W,WARRIOR|THIEF);
}break;
case UP:{
UpdateAnimation(AnimationState::WARRIOR_SWINGSWORD_N,WARRIOR|THIEF);
}break;
}
}
}
return true;
}
void Warrior::InitializeClassAbilities(){
#pragma region Warrior Right-click Ability (Block)
Warrior::rightClickAbility.action=
[](Player*p,vf2d pos={}){
if(p->GetState()==State::NORMAL){
rightClickAbility.cooldown=rightClickAbility.COOLDOWN_TIME;
p->SetState(State::BLOCK);
p->AddBuff(BuffType::SLOWDOWN,3,0.3);
return true;
}
return false;
};
#pragma endregion
#pragma region Warrior Ability 1 (Battlecry)
Warrior::ability1.action=
[](Player*p,vf2d pos={}){
game->AddEffect(std::make_unique<Effect>(p->GetPos(),0.1,AnimationState::BATTLECRY_EFFECT,p->upperLevel,1,0.3));
p->AddBuff(BuffType::ATTACK_UP,10,0.1);
p->AddBuff(BuffType::DAMAGE_REDUCTION,10,0.1);
for(Monster&m:MONSTER_LIST){
if(m.GetSizeMult()<=1&&geom2d::overlaps(geom2d::circle<float>(p->GetPos(),12*3.5),geom2d::circle<float>(m.GetPos(),m.GetSizeMult()*12))){
m.AddBuff(BuffType::SLOWDOWN,5,0.3);
}
}
return true;
};
#pragma endregion
#pragma region Warrior Ability 2 (Ground Slam)
Warrior::ability2.action=
[](Player*p,vf2d pos={}){
p->Spin(GROUND_SLAM_SPIN_TIME,14*PI);
p->iframe_time=GROUND_SLAM_SPIN_TIME+0.1;
return true;
};
#pragma endregion
#pragma region Warrior Ability 3 (Sonic Slash)
Warrior::ability3.action=
[](Player*p,vf2d pos={}){
p->SetState(State::SWING_SONIC_SWORD);
p->AddBuff(BuffType::SLOWDOWN,0.5,1);
vf2d bulletVel={};
switch(p->GetFacingDirection()){
case UP:{
p->vel.y=70;
bulletVel.y=-400;
p->UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_N,WARRIOR);
}break;
case LEFT:{
p->vel.x=70;
bulletVel.x=-400;
p->UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_W,WARRIOR);
}break;
case RIGHT:{
p->vel.x=-70;
bulletVel.x=400;
p->UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_E,WARRIOR);
}break;
case DOWN:{
p->vel.y=-70;
bulletVel.y=400;
p->UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_S,WARRIOR);
}break;
}
BULLET_LIST.push_back(std::make_unique<Bullet>(p->GetPos(),bulletVel,30,p->GetAttack()*8,AnimationState::SONICSLASH,p->upperLevel,true,2.25,true,true,WHITE));
game->SetupWorldShake(0.5);
return true;
};
#pragma endregion
}