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.
103 lines
4.7 KiB
103 lines
4.7 KiB
#include "Class.h"
|
|
#include "olcPixelGameEngine.h"
|
|
#include "DEFINES.h"
|
|
#include "Player.h"
|
|
#include "Effect.h"
|
|
#include "Crawler.h"
|
|
#include "BulletTypes.h"
|
|
#include "utils.h"
|
|
|
|
INCLUDE_MONSTER_LIST
|
|
INCLUDE_BULLET_LIST
|
|
INCLUDE_game
|
|
|
|
void Ranger::Initialize(){
|
|
Ranger::name="Ranger";
|
|
Ranger::cl=RANGER;
|
|
Ranger::rightClickAbility=Ability("Retreat",7,0,VERY_DARK_BLUE,DARK_BLUE);
|
|
Ranger::ability1=Ability("Rapid Fire",12,35);
|
|
Ranger::ability2=Ability("Charged Shot",15,40,VERY_DARK_RED,DARK_RED,PrecastData(0.3));
|
|
Ranger::ability3=Ability("Multishot",25,50);
|
|
Ranger::ability4=Ability("???",0,0);
|
|
Ranger::idle_n=RANGER_IDLE_N;
|
|
Ranger::idle_e=RANGER_IDLE_E;
|
|
Ranger::idle_s=RANGER_IDLE_S;
|
|
Ranger::idle_w=RANGER_IDLE_W;
|
|
Ranger::walk_n=RANGER_WALK_N;
|
|
Ranger::walk_e=RANGER_WALK_E;
|
|
Ranger::walk_s=RANGER_WALK_S;
|
|
Ranger::walk_w=RANGER_WALK_W;
|
|
}
|
|
|
|
SETUP_CLASS(Ranger)
|
|
|
|
void Ranger::OnUpdate(float fElapsedTime){
|
|
}
|
|
|
|
bool Ranger::AutoAttack(){
|
|
geom2d::line pointTowardsCursor(GetPos(),game->GetWorldMousePos());
|
|
vf2d extendedLine=pointTowardsCursor.upoint(1.1);
|
|
float angleToCursor=atan2(extendedLine.y-GetPos().y,extendedLine.x-GetPos().x);
|
|
attack_cooldown_timer=ARROW_ATTACK_COOLDOWN;
|
|
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);
|
|
SetAnimationBasedOnTargetingDirection(angleToCursor);
|
|
return true;
|
|
}
|
|
|
|
void Ranger::InitializeClassAbilities(){
|
|
#pragma region Ranger Right-click Ability (Retreat)
|
|
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()+vf2d{0,-p->GetZ()});
|
|
p->ghostFrameTimer=p->RETREAT_GHOST_FRAME_DELAY;
|
|
p->ghostRemoveTimer=p->RETREAT_GHOST_FRAMES*p->RETREAT_GHOST_FRAME_DELAY;
|
|
float angleToCursor=atan2(game->GetWorldMousePos().y-p->GetPos().y,game->GetWorldMousePos().x-p->GetPos().x);
|
|
p->SetAnimationBasedOnTargetingDirection(angleToCursor);
|
|
p->SetState(State::RETREAT);
|
|
return true;
|
|
};
|
|
#pragma endregion
|
|
#pragma region Ranger Ability 1 (Rapid Fire)
|
|
Ranger::ability1.action=
|
|
[](Player*p,vf2d pos={}){
|
|
p->remainingRapidFireShots=p->RAPID_FIRE_SHOOT_AMOUNT;
|
|
p->rapidFireTimer=p->RAPID_FIRE_SHOOT_DELAY;
|
|
p->SetState(State::ANIMATION_LOCK);
|
|
return true;
|
|
};
|
|
#pragma endregion
|
|
#pragma region Ranger Ability 2 (Charged Shot)
|
|
Ranger::ability2.action=
|
|
[](Player*p,vf2d pos={}){
|
|
vf2d arrowVelocity=util::pointTo(p->GetPos(),game->GetWorldMousePos());
|
|
BULLET_LIST.push_back(std::make_unique<ChargedArrow>(p->GetPos(),arrowVelocity*600,20,p->GetAttack()*2.5,p->OnUpperLevel(),true));
|
|
p->SetAnimationBasedOnTargetingDirection(atan2(arrowVelocity.y,arrowVelocity.x));
|
|
game->SetupWorldShake(0.3);
|
|
return true;
|
|
};
|
|
#pragma endregion
|
|
#pragma region Ranger Ability 3 (Multi Shot)
|
|
Ranger::ability3.action=
|
|
[](Player*p,vf2d pos={}){
|
|
geom2d::line pointTowardsCursor=geom2d::line(p->GetPos(),game->GetWorldMousePos());
|
|
float shootingDist=pointTowardsCursor.length();
|
|
vf2d shootingDirMiddle=pointTowardsCursor.vector();
|
|
float shootingAngle=atan2(shootingDirMiddle.y,shootingDirMiddle.x);
|
|
for(int i=0;i<7;i++){
|
|
if(i==3)continue;
|
|
float newAngle=shootingAngle-3.f/16*PI+i*1.f/16*PI;
|
|
geom2d::line pointTowardsCursor=geom2d::line(p->GetPos(),p->GetPos()+vf2d{cos(newAngle),sin(newAngle)}*shootingDist);
|
|
vf2d extendedLine=pointTowardsCursor.upoint(1.1);
|
|
BULLET_LIST.push_back(std::make_unique<Arrow>(Arrow(p->GetPos(),extendedLine,vf2d{cos(newAngle)*250,float(sin(newAngle)*250-PI/8*250)}+p->movementVelocity,12,p->GetAttack(),p->OnUpperLevel(),true)));
|
|
}
|
|
p->SetAnimationBasedOnTargetingDirection(shootingAngle);
|
|
return true;
|
|
};
|
|
#pragma endregion
|
|
} |