Add boost

This commit is contained in:
Sara Montecino 2022-11-11 17:33:00 -08:00
parent 1a864c9a73
commit 0bf9105fcd
8 changed files with 125 additions and 2 deletions

View File

@ -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)

View File

@ -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)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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<UCameraComponent>(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;
}
}

View File

@ -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;
};

View File

@ -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