From d4183180e164d7bf94881528b1569ba259b3837d Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii Date: Tue, 25 Jul 2023 20:32:29 +0000 Subject: [PATCH 1/3] Rapid Fire ranger ability implemented. Co-authored-by: sigonasr2 --- Crawler/Crawler.h | 5 ++--- Crawler/Player.cpp | 4 ++-- Crawler/Player.h | 4 ++++ Crawler/Ranger.cpp | 28 ++++++++++++++++++++++++---- Crawler/State.h | 1 + 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index bd15d938..45397d91 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -52,13 +52,12 @@ private: void InitializeClassAbilities(); public: Crawler(); - + bool OnUserCreate() override; + bool OnUserUpdate(float fElapsedTime) override; public: geom2d::rectNO_COLLISION={}; vi2d WORLD_SIZE={120,8}; TileTransformedView view; - bool OnUserCreate() override; - bool OnUserUpdate(float fElapsedTime) override; void InitializeLevel(std::string mapFile,MapName map); void LoadLevel(MapName map); void HandleUserInput(float fElapsedTime); diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index e7f5be5f..a01e14d8 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -319,7 +319,7 @@ void Player::Update(float fElapsedTime){ } - auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired;}; + auto AllowedToCast=[&](Ability&ability){return !ability.precastInfo.precastTargetingRequired&&GetState()!=State::ANIMATION_LOCK;}; //If pressed is set to false, uses held instead. auto CheckAndPerformAbility=[&](Ability&ability,HWButton key){ if(ability.name!="???"){ @@ -402,7 +402,7 @@ vf2d Player::GetVelocity(){ } bool Player::CanMove(){ - return state!=State::CASTING; + return state!=State::CASTING&&state!=State::ANIMATION_LOCK; } bool Player::HasIframes(){ diff --git a/Crawler/Player.h b/Crawler/Player.h index 3681714c..d8b6ba7d 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -90,6 +90,10 @@ protected: float ghostRemoveTimer=0; float retreatTimer=0; std::vectorghostPositions; + float rapidFireTimer=0; + int remainingRapidFireShots=0; + const float RAPID_FIRE_SHOOT_DELAY=0.1; + const int RAPID_FIRE_SHOOT_AMOUNT=4; public: Player(); //So this is rather fascinating and only exists because we have the ability to change classes which means we need to initialize a class diff --git a/Crawler/Ranger.cpp b/Crawler/Ranger.cpp index 423883b8..b836f822 100644 --- a/Crawler/Ranger.cpp +++ b/Crawler/Ranger.cpp @@ -61,6 +61,23 @@ void Ranger::OnUpdate(float fElapsedTime){ ghostFrameTimer=RETREAT_GHOST_FRAME_DELAY; } } + if(rapidFireTimer>0){ + rapidFireTimer-=fElapsedTime; + if(rapidFireTimer<=0){ + if(remainingRapidFireShots>0){ + remainingRapidFireShots--; + rapidFireTimer=RAPID_FIRE_SHOOT_DELAY; + 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(GetPos(),extendedLine,vf2d{cos(angleToCursor)*250,float(sin(angleToCursor)*250-PI/8*250)}+movementVelocity,12,GetAttack(),OnUpperLevel(),true))); + SetAnimationBasedOnTargetingDirection(angleToCursor); + }else{ + SetState(State::NORMAL); + } + } + } } bool Ranger::AutoAttack(){ @@ -71,11 +88,11 @@ bool Ranger::AutoAttack(){ BULLET_LIST.push_back(std::make_unique(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 false; + return true; } void Ranger::InitializeClassAbilities(){ - #pragma region Ranger Right-click Ability (???) + #pragma region Ranger Right-click Ability (Retreat) Ranger::rightClickAbility.action= [](Player*p,vf2d pos={}){ geom2d::line mouseDir{game->GetWorldMousePos(),p->GetPos()}; @@ -92,10 +109,13 @@ void Ranger::InitializeClassAbilities(){ return true; }; #pragma endregion - #pragma region Ranger Ability 1 (???) + #pragma region Ranger Ability 1 (Rapid Fire) Ranger::ability1.action= [](Player*p,vf2d pos={}){ - return false; + 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 (???) diff --git a/Crawler/State.h b/Crawler/State.h index 5cdcec7e..3191179a 100644 --- a/Crawler/State.h +++ b/Crawler/State.h @@ -14,4 +14,5 @@ enum State{ PREP_CAST, SHOOT_ARROW, RETREAT, + ANIMATION_LOCK, }; \ No newline at end of file From 2d04720bb4db5e9c467a000cde55019406f976a7 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 25 Jul 2023 16:33:19 -0500 Subject: [PATCH 2/3] Ranger only should receive the ranger shooting animation state Co-authored-by: sigonasr2 --- Crawler/loc.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 Crawler/loc.sh diff --git a/Crawler/loc.sh b/Crawler/loc.sh old mode 100644 new mode 100755 From bcbc10cb7c7628252da58b1d969858b33f1befb2 Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii Date: Tue, 25 Jul 2023 21:34:38 +0000 Subject: [PATCH 3/3] Ranger should be the only one updating the ranger-specific shooting animation --- Crawler/Player.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index a01e14d8..18b3ab7c 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -544,16 +544,18 @@ void Player::SetVelocity(vf2d vel){ } void Player::SetAnimationBasedOnTargetingDirection(float targetDirection){ - if(targetDirection<=PI/4&&targetDirection>-PI/4){ - UpdateAnimation(AnimationState::RANGER_SHOOT_E); - } else - if(targetDirection>=3*PI/4||targetDirection<-3*PI/4){ - UpdateAnimation(AnimationState::RANGER_SHOOT_W); - } else - if(targetDirection<=3*PI/4&&targetDirection>PI/4){ - UpdateAnimation(AnimationState::RANGER_SHOOT_S); - } else - if(targetDirection>=-3*PI/4&&targetDirection<-PI/4){ - UpdateAnimation(AnimationState::RANGER_SHOOT_N); + if(GetClass()==Class::RANGER){ + if(targetDirection<=PI/4&&targetDirection>-PI/4){ + UpdateAnimation(AnimationState::RANGER_SHOOT_E); + } else + if(targetDirection>=3*PI/4||targetDirection<-3*PI/4){ + UpdateAnimation(AnimationState::RANGER_SHOOT_W); + } else + if(targetDirection<=3*PI/4&&targetDirection>PI/4){ + UpdateAnimation(AnimationState::RANGER_SHOOT_S); + } else + if(targetDirection>=-3*PI/4&&targetDirection<-PI/4){ + UpdateAnimation(AnimationState::RANGER_SHOOT_N); + } } } \ No newline at end of file