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 b9d4e98..b3003fb 100755 Binary files a/Content/PlayerPawn_BP.uasset and b/Content/PlayerPawn_BP.uasset differ diff --git a/Content/TestMap.umap b/Content/TestMap.umap index 6c4dfc6..65883e0 100755 Binary files a/Content/TestMap.umap and b/Content/TestMap.umap differ diff --git a/Content/TestMap_BuiltData.uasset b/Content/TestMap_BuiltData.uasset index 76c0319..51dfcd2 100755 Binary files a/Content/TestMap_BuiltData.uasset and b/Content/TestMap_BuiltData.uasset differ 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