diff --git a/Content/GameModeBase_BP.uasset b/Content/GameModeBase_BP.uasset index 670f448..5f15a35 100755 Binary files a/Content/GameModeBase_BP.uasset and b/Content/GameModeBase_BP.uasset differ diff --git a/Content/PlayerPawn_BP.uasset b/Content/PlayerPawn_BP.uasset index 9553a5d..6861cf2 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 fd0d340..e04c8e1 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 754e05d..ecbcb72 100755 Binary files a/Content/TestMap_BuiltData.uasset and b/Content/TestMap_BuiltData.uasset differ diff --git a/Source/PresidentsBrigade/BasePawn.cpp b/Source/PresidentsBrigade/BasePawn.cpp index 7f8d42f..0656841 100755 --- a/Source/PresidentsBrigade/BasePawn.cpp +++ b/Source/PresidentsBrigade/BasePawn.cpp @@ -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( + death_effect = GetWorld()->SpawnActor( death_class, player_location, FRotator(0,0,0), spawnParameters ); + destroy_self(); +} + +void ABasePawn::destroy_self() +{ /* * Remove thyself from this world. */ diff --git a/Source/PresidentsBrigade/BasePawn.h b/Source/PresidentsBrigade/BasePawn.h index 254bb58..67f342a 100755 --- a/Source/PresidentsBrigade/BasePawn.h +++ b/Source/PresidentsBrigade/BasePawn.h @@ -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; }; diff --git a/Source/PresidentsBrigade/PlayerPawn.cpp b/Source/PresidentsBrigade/PlayerPawn.cpp index 2d93307..9ed9462 100755 --- a/Source/PresidentsBrigade/PlayerPawn.cpp +++ b/Source/PresidentsBrigade/PlayerPawn.cpp @@ -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(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(Controller); + if (!controller) + { + LogError("Cannot find palyer controller"); + return; + } + + EnableInput(controller); + player_mesh->SetHiddenInGame(false); + collision->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); } \ No newline at end of file diff --git a/Source/PresidentsBrigade/PlayerPawn.h b/Source/PresidentsBrigade/PlayerPawn.h index 0445341..12298ac 100755 --- a/Source/PresidentsBrigade/PlayerPawn.h +++ b/Source/PresidentsBrigade/PlayerPawn.h @@ -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; }; diff --git a/todo.txt b/todo.txt index da2778e..33c95c2 100644 --- a/todo.txt +++ b/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