From 0bf9105fcd753319ffbb590077108bb92ad32ddb Mon Sep 17 00:00:00 2001 From: Sara Montecino Date: Fri, 11 Nov 2022 17:33:00 -0800 Subject: [PATCH] Add boost --- Config/DefaultEngine.ini | 1 + Config/DefaultInput.ini | 2 + Content/PlayerPawn_BP.uasset | Bin 100606 -> 100816 bytes Content/TestMap.umap | Bin 650934 -> 650934 bytes Content/TestMap_BuiltData.uasset | Bin 1249722 -> 1249722 bytes Source/PresidentsBrigade/PlayerPawn.cpp | 74 ++++++++++++++++++++++++ Source/PresidentsBrigade/PlayerPawn.h | 44 ++++++++++++++ todo.txt | 6 +- 8 files changed, 125 insertions(+), 2 deletions(-) diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 3f9fee3..6427574 100755 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -9,6 +9,7 @@ AppliedDefaultGraphicsPerformance=Maximum [/Script/EngineSettings.GameMapsSettings] GlobalDefaultGameMode=/Game/GameModeBase_BP.GameModeBase_BP_C +EditorStartupMap=/Game/TestMap.TestMap [/Script/Engine.CollisionProfile] -Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision",bCanModify=False) diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index 1627dcd..29bf928 100755 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -93,6 +93,8 @@ FOVScale=0.011110 DoubleClickTime=0.200000 +ActionMappings=(ActionName="Shoot",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton) +ActionMappings=(ActionName="Shoot",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_RightTrigger) ++ActionMappings=(ActionName="Boost",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton) ++ActionMappings=(ActionName="Boost",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_RightShoulder) +AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W) +AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S) +AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=D) diff --git a/Content/PlayerPawn_BP.uasset b/Content/PlayerPawn_BP.uasset index b9d4e9863e02e106202f7d283a587ad078ac3d79..b3003fb210437b3c7dc970de65b625340dccbede 100755 GIT binary patch delta 5652 zcmcIodu)@}6~8C1VUi3dv12>VlNgj2k3vIvv>`x%W+~7Ox^|2<3&E|86Wg&(9wosJ zP!h^YpOMSPtKDI%wjc>7zpQPB2V4gg z?Tw?Tn`)n^=AXC#lUc4JrQID0MPr@4`+8#jaF5>`5et5?=F&t@P8L*e2=(;%qyA7( z{NZ$>X|5u7n>0i3YsYi@E9|;D)Uziv5bTWkBHpM^37t_f*|6FU`$+p?%Zn=?S(h8ik?*MYn*WwTR=O*)+F5W&5(O#HLLuyELndD@a9 zH!RdTirjGy8hL7o^=9x$MvN1m3A-o5yf0C@xfyG!{>f4Pa^k!J!fvSX-_?gi z@py7z6?l+(NvrM-?WC<L4lP(}b(}J3 ze@NrXD7oR7-%>=i_Ig9}^)&u%l+BlGEe@*#k1VExE<6Qz_fyCgN|L9!H-dVMDiBv=e@pFp<#OE3N`J z5_nf&q6IihwKvD65`D#Gbu=f{dLb6l_>VegYN1QZtPVU(939(&ag*b{Wgf>PDiM;O$(mV6SQ zkxTZ1XECQ9VHWjoANx4Ig?p5{3Smqaq%Xz}6-_vvc&9fSHAiMZ1} zDZ~K3Ufl!;T+5{-a6%hNevo>0^Aw#hjr970Gl`WC5oxV@0GzH?qB2@b^3#aQ*8@=N z8c(5cGT+8;N-akT?V#Q$t`Lc}9B^xj2?xnZFO9=c;Mv%(zPW6UbcKB)qr;9{awy3G zuZ$6u`VuI%F(~c5u%d`lM+n=O_0(g%V6}7nsCMEX)in7+FVwk`FRc=jTJb&}F4gLB z_FV^)g0TU9MJTiNo0CbbJd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FpwwL3+OG!8$l~vDh=efxbn`s4oVzNH+6)$x5En_uvM~9v?2j4+-xH{~s^H~;_u diff --git a/Content/TestMap.umap b/Content/TestMap.umap index 6c4dfc6adc49156652e29d5cac00ca8e0a953b65..65883e09d86487cfd39a67b3e23fb64cd145738f 100755 GIT binary patch delta 159 zcmdmXSAE-E^$lK(0%|U`M$Y{cJQjz^PkMOhZz;MakqWU2lDR8E##S;SS&L6LM6-OnC8{O3=YDn5{_S7CjL7aR&?e- zCIbV*Gy!fS47C*?^cGh&i_Bws3l8 F0RS68KVSd= delta 159 zcmdmXSAE-E^$lK(0?eQDw12xEciV35r!B313e=HJwwyUiQ!U{Z$$`f zW(haY5eW1Tw3)k>#c^I;KgWFEZ+|8y7K=>2P{}emrg^pSiQ}<9c0AtfyeFpc!rF9%m&2lK+Lf{w}sO) F3jo{uLM#9P diff --git a/Content/TestMap_BuiltData.uasset b/Content/TestMap_BuiltData.uasset index 76c0319de1918f2c0df4fdd6c793e4fec79d141b..51dfcd2a2a7f3ff032495231f35162d14ea17813 100755 GIT binary patch delta 86 zcmV~$yA6U+06@{G$XDeFgFwj;#Boe4EpD$1XhCOdj0qJ5v$%n`=A3cp$DzOd!h3Ft q$Mto sh4u%9_6UXc35E6wh4u@D_6&vg4Tbg&h4v4H_7H{k5ry^=we}Ol5MhxkWB>pF diff --git a/Source/PresidentsBrigade/PlayerPawn.cpp b/Source/PresidentsBrigade/PlayerPawn.cpp index 92d89fc..574a8f9 100755 --- a/Source/PresidentsBrigade/PlayerPawn.cpp +++ b/Source/PresidentsBrigade/PlayerPawn.cpp @@ -3,13 +3,25 @@ #include "PlayerPawn.h" #include "Camera/CameraComponent.h" +#include "GameFramework/FloatingPawnMovement.h" +#include "Math/UnrealMathUtility.h" +#include "Util.h" +#define LogError(Msg) Util::log_error(TEXT("APlayerPawn"), Msg) APlayerPawn::APlayerPawn(const FObjectInitializer &object_initializer): ABasePawn(object_initializer) { main_camera = object_initializer.CreateDefaultSubobject(this, FName("MainCamera")); main_camera->SetupAttachment(root_component); + + boost_multiplier = 3.0f; + reset_threshold_s = .5f; + cooldown_threshold_s = 3.0f; + + // You can boost right away. + cooldown_wait_s = cooldown_threshold_s + 1.0f; + reset_wait_s = reset_threshold_s + 1.0f; } // Called to bind functionality to input @@ -19,4 +31,66 @@ void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen PlayerInputComponent->BindAxis("MoveForward", this, &ABasePawn::handle_move_forward); PlayerInputComponent->BindAxis("MoveRight", this, &ABasePawn::handle_move_right); PlayerInputComponent->BindAction("Shoot", EInputEvent::IE_Pressed, this, &ABasePawn::shoot); + PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Pressed, this, &APlayerPawn::boost); + PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Released, this, &APlayerPawn::reset_boost); +} + +void APlayerPawn::Tick(float delta_time) +{ + Super::Tick(delta_time); + if (cooldown_wait_s <= cooldown_threshold_s) + { + cooldown_wait_s += delta_time; + } + + if (reset_wait_s <= reset_threshold_s) + { + reset_wait_s += delta_time; + } + + if (reset_wait_s > reset_threshold_s) + { + reset_boost(); + } +} + +void APlayerPawn::boost() +{ + const bool boost_allowed = cooldown_wait_s > cooldown_threshold_s; + if (!boost_allowed) + { + LogError("Cannot boost! You're on cooldown"); + return; + } + + const float current_speed = movement_component->GetMaxSpeed(); + const float current_accel = movement_component->Acceleration; + if (!default_max_speed || FMath::IsNearlyEqual(current_speed, default_max_speed, 0.001f)) + { + default_max_speed = current_speed; + default_max_accel = current_accel; + movement_component->MaxSpeed = default_max_speed * boost_multiplier; + movement_component->Acceleration = default_max_accel * boost_multiplier; + + reset_wait_s = 0; + } +} + +void APlayerPawn::reset_boost() +{ + if (!default_max_speed) + { + // We haven't boosted yet. Ignore. + return; + } + + const float current_speed = movement_component->GetMaxSpeed(); + const float current_accel = movement_component->Acceleration; + if (!FMath::IsNearlyEqual(current_speed, default_max_speed, 0.001f)) + { + movement_component->MaxSpeed = default_max_speed; + movement_component->Acceleration = default_max_accel; + + cooldown_wait_s = 0; + } } \ No newline at end of file diff --git a/Source/PresidentsBrigade/PlayerPawn.h b/Source/PresidentsBrigade/PlayerPawn.h index 44cb677..0445341 100755 --- a/Source/PresidentsBrigade/PlayerPawn.h +++ b/Source/PresidentsBrigade/PlayerPawn.h @@ -18,10 +18,54 @@ class PRESIDENTSBRIGADE_API APlayerPawn : public ABasePawn public: // Sets default values for this pawn's properties APlayerPawn(const FObjectInitializer &object_initializer); + + virtual void Tick(float delta_time) override; // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; protected: UPROPERTY(EditAnywhere, Category="Player") UCameraComponent* main_camera; + + /** + * Multiplier to apply to current speed while boosting. Applies to max speed and accleration. + */ + UPROPERTY(EditAnywhere, Category = "Movement") + float boost_multiplier; + + /** + * Time in seconds before auto resetting boost. + */ + UPROPERTY(EditAnywhere, Category = "Movement") + float reset_threshold_s; + + /** + * Time in seconds before allowed to boost again. + */ + UPROPERTY(EditAnywhere, Category = "Movement") + float cooldown_threshold_s; + +private: + void boost(); + void reset_boost(); + + /** + * Default max speed. Cached when boost is called. + */ + float default_max_speed; + + /** + * Default max acceleration. Cached when boost is called. + */ + float default_max_accel; + + /** + * Time waited for boost reset. + */ + float reset_wait_s; + + /** + * Time waited for cooldown. + */ + float cooldown_wait_s; }; diff --git a/todo.txt b/todo.txt index 200ba0c..1c85886 100644 --- a/todo.txt +++ b/todo.txt @@ -9,10 +9,12 @@ xAdd presidents car xAdd enemy cars xComes from off screen xAttacks president car -Add dash +xAdd dash +Shoot from any direction +Shoot at continuous rate when holding shoot button +Add local multiplayer Add netcode Add player damage -Shoot at continuous rate when holding shoot button Add HUD UI Add menu Add sounds