Add single player HUD
This commit is contained in:
parent
f538a55384
commit
b7ac77f7c1
Binary file not shown.
Binary file not shown.
BIN
Content/HUDWidget.uasset
Executable file
BIN
Content/HUDWidget.uasset
Executable file
Binary file not shown.
BIN
Content/PlayerHUD.uasset
Executable file
BIN
Content/PlayerHUD.uasset
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,7 +8,6 @@
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "Util.h"
|
||||
|
||||
#define LogInfo(Msg) Util::log_info(TEXT("ABasePawn"), Msg)
|
||||
#define LogError(Msg) Util::log_error(TEXT("ABasePawn"), Msg)
|
||||
|
||||
// Sets default values
|
||||
@ -71,7 +70,6 @@ void ABasePawn::handle_hit(
|
||||
{
|
||||
// Update current health.
|
||||
current_health -= damage_class_map[other_class];
|
||||
LogInfo(FString::Printf(TEXT("Total health %d"), current_health));
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,10 +100,10 @@ void ABasePawn::Tick(float DeltaTime)
|
||||
/*
|
||||
* Handle death.
|
||||
*/
|
||||
if (current_health <= 0)
|
||||
if (current_health <= 0 && !death_handled)
|
||||
{
|
||||
handle_death();
|
||||
current_health = max_health;
|
||||
death_handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,10 +153,9 @@ void ABasePawn::shoot()
|
||||
if (use_aim_assist)
|
||||
{
|
||||
float assist_yaw;
|
||||
const bool succeess = aim_assist(player_location, rotator, assist_yaw);
|
||||
if (assist_yaw)
|
||||
const bool success = aim_assist(player_location, rotator, assist_yaw);
|
||||
if (success)
|
||||
{
|
||||
LogInfo("Aim assist activated!");
|
||||
rotator.Yaw = assist_yaw;
|
||||
}
|
||||
}
|
||||
@ -272,4 +269,4 @@ void ABasePawn::destroy_self()
|
||||
* Remove thyself from this world.
|
||||
*/
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
#include "BasePawn.generated.h"
|
||||
|
||||
#define LogInfo(Msg) Util::log_info(TEXT("ABasePawn"), Msg)
|
||||
|
||||
class UFloatingPawnMovement;
|
||||
|
||||
UCLASS()
|
||||
@ -21,6 +23,16 @@ public:
|
||||
|
||||
FVector get_location() const;
|
||||
|
||||
FORCEINLINE float get_current_health_percentage() const
|
||||
{
|
||||
if (max_health == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (current_health * 1.0f) / max_health;
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
virtual void handle_move_right(float axis);
|
||||
@ -141,6 +153,11 @@ protected:
|
||||
*/
|
||||
int32 current_health;
|
||||
|
||||
/**
|
||||
* Death handled.
|
||||
*/
|
||||
bool death_handled;
|
||||
|
||||
/**
|
||||
* Current ammo.
|
||||
*/
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "GameFramework/FloatingPawnMovement.h"
|
||||
#include "Math/UnrealMathUtility.h"
|
||||
#include "Util.h"
|
||||
#include "EngineUtils.h"
|
||||
|
||||
#define LogInfo(Msg) Util::log_info(TEXT("APlayerPawn"), Msg)
|
||||
#define LogError(Msg) Util::log_error(TEXT("APlayerPawn"), Msg)
|
||||
@ -68,24 +69,29 @@ void APlayerPawn::handle_overlap(
|
||||
}
|
||||
|
||||
other_actor->Destroy();
|
||||
LogInfo(FString::Printf(TEXT("Total ammo %d"), current_ammo));
|
||||
}
|
||||
}
|
||||
|
||||
void APlayerPawn::Tick(float delta_time)
|
||||
{
|
||||
Super::Tick(delta_time);
|
||||
if (cooldown_wait_s <= cooldown_threshold_s)
|
||||
if (!init)
|
||||
{
|
||||
president_ref = get_president();
|
||||
init = true;
|
||||
}
|
||||
|
||||
if (cooldown_wait_s < cooldown_threshold_s)
|
||||
{
|
||||
cooldown_wait_s += delta_time;
|
||||
}
|
||||
|
||||
if (reset_wait_s <= reset_threshold_s)
|
||||
if (reset_wait_s < reset_threshold_s)
|
||||
{
|
||||
reset_wait_s += delta_time;
|
||||
}
|
||||
|
||||
if (reset_wait_s > reset_threshold_s)
|
||||
if (reset_wait_s >= reset_threshold_s)
|
||||
{
|
||||
reset_boost();
|
||||
}
|
||||
@ -102,10 +108,9 @@ void APlayerPawn::Tick(float delta_time)
|
||||
|
||||
void APlayerPawn::boost()
|
||||
{
|
||||
const bool boost_allowed = cooldown_wait_s > cooldown_threshold_s;
|
||||
const bool boost_allowed = cooldown_wait_s >= cooldown_threshold_s;
|
||||
if (!boost_allowed)
|
||||
{
|
||||
LogError("Cannot boost! You're on cooldown");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -180,4 +185,39 @@ void APlayerPawn::respawn()
|
||||
EnableInput(controller);
|
||||
player_mesh->SetHiddenInGame(false);
|
||||
collision->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
||||
current_health = max_health;
|
||||
death_handled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to find president in level.
|
||||
*/
|
||||
ABasePawn* APlayerPawn::get_president() const
|
||||
{
|
||||
ABasePawn* found = nullptr;
|
||||
for (TActorIterator<AActor> iterator(GetWorld()); iterator; ++iterator)
|
||||
{
|
||||
AActor* actor = *iterator;
|
||||
if (actor && actor != this)
|
||||
{
|
||||
UClass* actor_class = actor->GetClass();
|
||||
if (actor_class == (*president_class))
|
||||
{
|
||||
if (found)
|
||||
{
|
||||
LogError("Multiple presidents found!");
|
||||
break;
|
||||
}
|
||||
|
||||
found = Cast<ABasePawn>(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
// LogError("No president found!");
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
@ -23,6 +23,46 @@ public:
|
||||
|
||||
// Called to bind functionality to input
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FORCEINLINE float get_president_health() const
|
||||
{
|
||||
if (president_ref)
|
||||
{
|
||||
return president_ref->get_current_health_percentage();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FORCEINLINE float get_boost_cooldown_percentage() const
|
||||
{
|
||||
if (reset_wait_s < reset_threshold_s)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cooldown_wait_s >= cooldown_threshold_s)
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return cooldown_wait_s / cooldown_threshold_s;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FORCEINLINE int32 get_current_ammo() const
|
||||
{
|
||||
return current_ammo;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FORCEINLINE int32 get_max_ammo() const
|
||||
{
|
||||
return max_ammo;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
virtual void destroy_self() override;
|
||||
@ -42,6 +82,9 @@ protected:
|
||||
UPROPERTY(EditAnywhere, Category = "Player")
|
||||
TMap<UClass*, int> ammo_class_map;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Player")
|
||||
TSubclassOf<ABasePawn> president_class;
|
||||
|
||||
/**
|
||||
* Multiplier to apply to current speed while boosting. Applies to max speed and accleration.
|
||||
*/
|
||||
@ -74,6 +117,7 @@ private:
|
||||
void boost();
|
||||
void reset_boost();
|
||||
void respawn();
|
||||
ABasePawn* get_president() const;
|
||||
|
||||
/**
|
||||
* Default max speed. Cached when boost is called.
|
||||
@ -99,4 +143,14 @@ private:
|
||||
* Time waiting for respawn.
|
||||
*/
|
||||
float respawn_wait_s;
|
||||
|
||||
/**
|
||||
* True after post tick initialization.
|
||||
*/
|
||||
bool init;
|
||||
|
||||
/**
|
||||
* Cached reference to the president.
|
||||
*/
|
||||
ABasePawn* president_ref;
|
||||
};
|
||||
|
7
todo.txt
7
todo.txt
@ -18,10 +18,8 @@ xAdd auto aim
|
||||
xAdd art
|
||||
x Car models
|
||||
x Street shader
|
||||
Add HUD UI
|
||||
xAdd HUD UI for single player.
|
||||
Add sounds
|
||||
Add win condition
|
||||
- Time based. Keep president alive until he reaches destination.
|
||||
Add juice
|
||||
Add muzzle on shoot
|
||||
Camera zoom out based on screen size? Looks too small when I shrink the window
|
||||
@ -29,8 +27,11 @@ Add juice
|
||||
Improve street shader
|
||||
Screen shake on zoom
|
||||
Particle effect on brake
|
||||
Add win condition
|
||||
- Time based. Keep president alive until he reaches destination.
|
||||
Add menu
|
||||
Add local multiplayer
|
||||
x Blueprint
|
||||
- C++
|
||||
- HUD UI for multiplayer
|
||||
Add netcode
|
||||
|
Loading…
Reference in New Issue
Block a user