Add player damage, death, and respawn
This commit is contained in:
parent
7780f965fc
commit
88db9deea4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -100,6 +100,7 @@ void ABasePawn::Tick(float DeltaTime)
|
||||
if (current_health <= 0)
|
||||
{
|
||||
handle_death();
|
||||
current_health = max_health;
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,8 +108,7 @@ void ABasePawn::handle_move_forward(float axis)
|
||||
{
|
||||
if (axis != 0)
|
||||
{
|
||||
FVector forward = FRotationMatrix(FRotator()).GetUnitAxis(EAxis::X);
|
||||
AddMovementInput(forward, axis);
|
||||
AddMovementInput(FVector(1,0,0), axis);
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,8 +116,7 @@ void ABasePawn::handle_move_right(float axis)
|
||||
{
|
||||
if (axis != 0)
|
||||
{
|
||||
FVector right = FRotationMatrix(FRotator()).GetUnitAxis(EAxis::Y);
|
||||
AddMovementInput(right, axis);
|
||||
AddMovementInput(FVector(0, 1, 0), axis);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,19 +171,30 @@ void ABasePawn::handle_death()
|
||||
*/
|
||||
collision->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||
|
||||
if (death_effect)
|
||||
{
|
||||
death_effect->Destroy();
|
||||
death_effect = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Spawn particle effect.
|
||||
*/
|
||||
FVector player_location = player_mesh->GetComponentLocation();
|
||||
FActorSpawnParameters spawnParameters;
|
||||
spawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
AActor* bullet = GetWorld()->SpawnActor<AActor>(
|
||||
death_effect = GetWorld()->SpawnActor<AActor>(
|
||||
death_class,
|
||||
player_location,
|
||||
FRotator(0,0,0),
|
||||
spawnParameters
|
||||
);
|
||||
|
||||
destroy_self();
|
||||
}
|
||||
|
||||
void ABasePawn::destroy_self()
|
||||
{
|
||||
/*
|
||||
* Remove thyself from this world.
|
||||
*/
|
||||
|
@ -49,6 +49,8 @@ protected:
|
||||
};
|
||||
};
|
||||
|
||||
virtual void destroy_self();
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
@ -125,4 +127,9 @@ protected:
|
||||
* Last yaw.
|
||||
*/
|
||||
Yaw yaw;
|
||||
|
||||
/**
|
||||
* Spawned death effect actor.
|
||||
*/
|
||||
AActor* death_effect;
|
||||
};
|
||||
|
@ -55,6 +55,15 @@ void APlayerPawn::Tick(float delta_time)
|
||||
{
|
||||
reset_boost();
|
||||
}
|
||||
|
||||
if (respawn_wait_s > 0)
|
||||
{
|
||||
respawn_wait_s -= delta_time;
|
||||
if (respawn_wait_s <= 0)
|
||||
{
|
||||
respawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void APlayerPawn::boost()
|
||||
@ -96,4 +105,45 @@ void APlayerPawn::reset_boost()
|
||||
|
||||
cooldown_wait_s = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void APlayerPawn::destroy_self()
|
||||
{
|
||||
APlayerController* controller = Cast<APlayerController>(Controller);
|
||||
if (!controller)
|
||||
{
|
||||
LogError("Cannot find palyer controller");
|
||||
return;
|
||||
}
|
||||
|
||||
stop_shooting();
|
||||
reset_boost();
|
||||
|
||||
DisableInput(controller);
|
||||
player_mesh->SetHiddenInGame(true);
|
||||
|
||||
if (death_effect)
|
||||
{
|
||||
death_effect->Destroy();
|
||||
death_effect = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start respawn timer.
|
||||
*/
|
||||
respawn_wait_s = respawn_s;
|
||||
}
|
||||
|
||||
void APlayerPawn::respawn()
|
||||
{
|
||||
APlayerController* controller = Cast<APlayerController>(Controller);
|
||||
if (!controller)
|
||||
{
|
||||
LogError("Cannot find palyer controller");
|
||||
return;
|
||||
}
|
||||
|
||||
EnableInput(controller);
|
||||
player_mesh->SetHiddenInGame(false);
|
||||
collision->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
||||
}
|
@ -24,9 +24,17 @@ public:
|
||||
// Called to bind functionality to input
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
protected:
|
||||
virtual void destroy_self() override;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Player")
|
||||
UCameraComponent* main_camera;
|
||||
|
||||
/**
|
||||
* Time in seconds before respawn.
|
||||
*/
|
||||
UPROPERTY(EditAnywhere, Category = "Player")
|
||||
float respawn_s;
|
||||
|
||||
/**
|
||||
* Multiplier to apply to current speed while boosting. Applies to max speed and accleration.
|
||||
*/
|
||||
@ -48,6 +56,7 @@ protected:
|
||||
private:
|
||||
void boost();
|
||||
void reset_boost();
|
||||
void respawn();
|
||||
|
||||
/**
|
||||
* Default max speed. Cached when boost is called.
|
||||
@ -68,4 +77,9 @@ private:
|
||||
* Time waited for cooldown.
|
||||
*/
|
||||
float cooldown_wait_s;
|
||||
|
||||
/**
|
||||
* Time waiting for respawn.
|
||||
*/
|
||||
float respawn_wait_s;
|
||||
};
|
||||
|
16
todo.txt
16
todo.txt
@ -12,18 +12,20 @@ xAdd enemy cars
|
||||
xAdd dash
|
||||
xShoot from any direction
|
||||
xShoot at continuous rate when holding shoot button
|
||||
Add local multiplayer
|
||||
x Blueprint
|
||||
- C++
|
||||
Add player damage
|
||||
xAdd player damage
|
||||
Add player ammo
|
||||
Add player health pickups
|
||||
Add HUD UI
|
||||
Add win condition
|
||||
- Time based. Keep president alive until he reaches destination.
|
||||
Add menu
|
||||
Add local multiplayer
|
||||
x Blueprint
|
||||
- C++
|
||||
Add netcode
|
||||
Add art
|
||||
- Car models
|
||||
- Street shader
|
||||
Add sounds
|
||||
Add juice
|
||||
Add muzzle on shoot
|
||||
Camera zoom out based on screen size? Looks too small when I shrink the window
|
||||
Add menu
|
||||
Add netcode
|
||||
|
Loading…
Reference in New Issue
Block a user