#include "Class.h" #include "olcPixelGameEngine.h" #include "DEFINES.h" #include "Player.h" #include "Effect.h" #include "Crawler.h" #include "config.h" INCLUDE_MONSTER_LIST INCLUDE_BULLET_LIST INCLUDE_game void Warrior::Initialize(){ READFROMCONFIG(Warrior,WARRIOR); Warrior::idle_n=WARRIOR_IDLE_N; Warrior::idle_e=WARRIOR_IDLE_E; Warrior::idle_s=WARRIOR_IDLE_S; Warrior::idle_w=WARRIOR_IDLE_W; Warrior::walk_n=WARRIOR_WALK_N; Warrior::walk_e=WARRIOR_WALK_E; Warrior::walk_s=WARRIOR_WALK_S; 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(GetPos()-vf2d{GetSizeMult()*12,GetSizeMult()*12},attack_range*GetSizeMult()*12),geom2d::circle(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12)) &&geom2d::line(game->GetWorldMousePos(),m.GetPos()).length()(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(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(p->GetPos(),12*3.5),geom2d::circle(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(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 }