presidents-brigade/Source/PresidentsBrigade/BasePawn.h
2022-11-03 21:55:35 -07:00

108 lines
2.5 KiB
C++
Executable File

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Kismet/KismetMathLibrary.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/FloatingPawnMovement.h"
#include "BasePawn.generated.h"
class UCameraComponent;
//enum movement_t : uint8
//{
// UP,
// DOWN,
// LEFT,
// RIGHT
//};
UCLASS()
class PRESIDENTSBRIGADE_API ABasePawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ABasePawn(const FObjectInitializer &object_initializer);
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
virtual UPawnMovementComponent* GetMovementComponent() const;
UPROPERTY(EditAnywhere, Category="Player")
UCameraComponent* main_camera;
UPROPERTY(EditAnywhere, Category="Player")
UStaticMeshComponent* player_mesh;
UPROPERTY(EditAnywhere, Category="Player")
UFloatingPawnMovement* movement_component;
// Accel max time.
UPROPERTY(EditDefaultsOnly, Category="Gameplay")
float accel_max_time;
// Maximum horizontal speed.
UPROPERTY(EditDefaultsOnly, Category="Gameplay")
float horizontal_speed_max;
// Maximum vertical speed.
UPROPERTY(EditDefaultsOnly, Category="Gameplay")
float vertical_speed_max;
private:
struct AccelerationAnim
{
float start;
float end;
float max_time;
float time_elapsed;
void set(float _start, float _end, float _max_time)
{
start = _start;
end = _end;
max_time = _max_time;
time_elapsed = 0;
};
float update(const float delta_time)
{
float percentage = time_elapsed / max_time;
// Animation is complete.
if (time_elapsed > max_time)
{
percentage = 1;
}
time_elapsed += delta_time;
return UKismetMathLibrary::Lerp(start, end, percentage);
};
};
USceneComponent* root_component;
// DECLARE_DELEGATE_TwoParams(FMovementDelegate, const movement_t, const int);
// void handle_move_input(const movement_t move_type, const int direction);
void handle_move_right(float axis);
void handle_move_forward(float axis);
float horizontal_speed;
float vertical_speed;
AccelerationAnim horizontal_accel;
AccelerationAnim vertical_accel;
};