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

113 lines
4.0 KiB

#include "Class.h"
#include "olcPixelGameEngine.h"
#include "DEFINES.h"
#include "Player.h"
#include "Effect.h"
#include "Crawler.h"
#include "BulletTypes.h"
INCLUDE_MONSTER_LIST
INCLUDE_BULLET_LIST
INCLUDE_game
std::string Ranger::name="Ranger";
Class Ranger::cl=RANGER;
Ability Ranger::rightClickAbility=Ability("Retreat",7,0,VERY_DARK_BLUE,DARK_BLUE);
Ability Ranger::ability1=Ability("Rapid Fire",12,35);
Ability Ranger::ability2=Ability("Charged Shot",15,40);
Ability Ranger::ability3=Ability("Multishot",25,50);
Ability Ranger::ability4=Ability("???",0,0);
AnimationState Ranger::idle_n=RANGER_IDLE_N;
AnimationState Ranger::idle_e=RANGER_IDLE_E;
AnimationState Ranger::idle_s=RANGER_IDLE_S;
AnimationState Ranger::idle_w=RANGER_IDLE_W;
AnimationState Ranger::walk_n=RANGER_WALK_N;
AnimationState Ranger::walk_e=RANGER_WALK_E;
AnimationState Ranger::walk_s=RANGER_WALK_S;
AnimationState Ranger::walk_w=RANGER_WALK_W;
SETUP_CLASS(Ranger)
void Ranger::OnUpdate(float fElapsedTime){
if(GetState()==SHOOT_ARROW){
if(attack_cooldown_timer<=ARROW_ATTACK_COOLDOWN-0.3){
SetState(NORMAL);
}
}
if(retreatTimer>0){
SetZ(6*sin(PI/RETREAT_TIME*retreatTimer));
retreatTimer-=fElapsedTime;
if(retreatTimer<=0){
SetVelocity({});
SetZ(0);
}
}
if(ghostRemoveTimer>0){
ghostRemoveTimer-=fElapsedTime;
if(ghostRemoveTimer<=0){
if(ghostPositions.size()>0){
ghostPositions.erase(ghostPositions.begin());
if(ghostPositions.size()>0){
ghostRemoveTimer=RETREAT_GHOST_FRAME_DELAY;
}
}
}
}
}
bool Ranger::AutoAttack(){
attack_cooldown_timer=ARROW_ATTACK_COOLDOWN;
geom2d::line pointTowardsCursor(GetPos(),game->GetWorldMousePos());
vf2d extendedLine=pointTowardsCursor.upoint(1.1);
float angleToCursor=atan2(extendedLine.y-GetPos().y,extendedLine.x-GetPos().x);
BULLET_LIST.push_back(std::make_unique<Arrow>(Arrow(GetPos(),extendedLine,vf2d{cos(angleToCursor)*250,float(sin(angleToCursor)*250-PI/8*250)}+movementVelocity,12,GetAttack(),OnUpperLevel(),true)));
SetState(State::SHOOT_ARROW);
if(angleToCursor<=PI/4&&angleToCursor>-PI/4){
UpdateAnimation(AnimationState::RANGER_SHOOT_E);
} else
if(angleToCursor>=3*PI/4||angleToCursor<-3*PI/4){
UpdateAnimation(AnimationState::RANGER_SHOOT_W);
} else
if(angleToCursor<=3*PI/4&&angleToCursor>PI/4){
UpdateAnimation(AnimationState::RANGER_SHOOT_S);
} else
if(angleToCursor>=-3*PI/4&&angleToCursor<-PI/4){
UpdateAnimation(AnimationState::RANGER_SHOOT_N);
}
return false;
}
void Ranger::InitializeClassAbilities(){
#pragma region Ranger Right-click Ability (???)
Ranger::rightClickAbility.action=
[](Player*p,vf2d pos={}){
geom2d::line mouseDir{game->GetWorldMousePos(),p->GetPos()};
float velocity=(0.5*-p->friction*p->RETREAT_TIME*p->RETREAT_TIME-p->RETREAT_DISTANCE)/-p->RETREAT_TIME; //Derived from kinetic motion formula.
p->SetVelocity(mouseDir.vector().norm()*velocity);
p->retreatTimer=p->RETREAT_TIME;
p->iframe_time=p->RETREAT_TIME;
p->ghostPositions.push_back(p->GetPos());
p->ghostFrameTimer=p->RETREAT_GHOST_FRAME_DELAY;
p->ghostRemoveTimer=p->RETREAT_GHOST_FRAMES*p->RETREAT_GHOST_FRAME_DELAY;
return true;
};
#pragma endregion
#pragma region Ranger Ability 1 (???)
Ranger::ability1.action=
[](Player*p,vf2d pos={}){
return false;
};
#pragma endregion
#pragma region Ranger Ability 2 (???)
Ranger::ability2.action=
[](Player*p,vf2d pos={}){
return false;
};
#pragma endregion
#pragma region Ranger Ability 3 (???)
Ranger::ability3.action=
[](Player*p,vf2d pos={}){
return false;
};
#pragma endregion
}