-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into AnimationFixes
- Loading branch information
Showing
11 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
|
||
#include "SRespawnGameMode.h" | ||
|
||
#include "Chaos/SpatialAccelerationCollection.h" | ||
#include "GameFramework/DefaultPawn.h" | ||
|
||
|
||
void ASRespawnGameMode::BeginPlay() | ||
{ | ||
Super::BeginPlay(); | ||
|
||
CurLives = MaxLives; | ||
|
||
SetSpawnLocation(FindPlayerStart(UGameplayStatics::GetPlayerController(GetWorld(), 0))->GetTransform()); | ||
UGameplayStatics::GetPlayerPawn(GetWorld(),0)->OnDestroyed.AddDynamic(this, &ASRespawnGameMode::RespawnPlayer); | ||
|
||
} | ||
|
||
void ASRespawnGameMode::SpawnPlayer() | ||
{ | ||
// spawn and possess player | ||
if(APawn* SpawnedPlayer = GetWorld()->SpawnActor<APawn>(DefaultPawnClass, SpawnLocation)) | ||
{ | ||
SpawnedPlayer->OnDestroyed.AddDynamic(this, &ASRespawnGameMode::RespawnPlayer); | ||
UGameplayStatics::GetPlayerController(GetWorld(), 0)->Possess(SpawnedPlayer); | ||
} | ||
else | ||
{ | ||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Could not spawn player")); | ||
} | ||
} | ||
|
||
void ASRespawnGameMode::RespawnPlayer(AActor* Destroyed) | ||
{ | ||
CurLives--; | ||
|
||
if (CheckLoss()) return; | ||
|
||
// spawn player with delay, or no delay if 0. | ||
if(SpawnDelay > 0.0f) | ||
{ | ||
FTimerHandle UnusedHandle; | ||
GetWorldTimerManager().SetTimer( | ||
UnusedHandle, this, &ASRespawnGameMode::SpawnPlayer, SpawnDelay, false); | ||
} | ||
else SpawnPlayer(); | ||
|
||
} | ||
|
||
bool ASRespawnGameMode::CheckLoss() | ||
{ | ||
if(CurLives <= 0) | ||
{ | ||
EndGame(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void ASRespawnGameMode::EndGame() | ||
{ | ||
GameOver.Broadcast(false); | ||
} | ||
|
||
void ASRespawnGameMode::SetSpawnLocation(FTransform Location) | ||
{ | ||
SpawnLocation = Location; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "GameFramework/GameMode.h" | ||
#include "Kismet/GameplayStatics.h" | ||
#include "SRespawnGameMode.generated.h" | ||
|
||
/** | ||
* | ||
*/ | ||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGameOver, bool, Won); | ||
|
||
|
||
UCLASS() | ||
|
||
class UNBREAD_API ASRespawnGameMode : public AGameMode | ||
{ | ||
GENERATED_BODY() | ||
protected: | ||
UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||
FTransform SpawnLocation; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||
float SpawnDelay; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||
int CurLives; | ||
|
||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||
int MaxLives = 3; | ||
|
||
UPROPERTY(BlueprintAssignable) | ||
FGameOver GameOver; | ||
|
||
virtual void BeginPlay() override; | ||
|
||
UFUNCTION() | ||
void SpawnPlayer(); | ||
|
||
UFUNCTION() | ||
void RespawnPlayer(AActor* Destroyed); | ||
|
||
UFUNCTION() | ||
bool CheckLoss(); | ||
|
||
UFUNCTION() | ||
void EndGame(); | ||
|
||
public: | ||
UFUNCTION(BlueprintCallable) | ||
void SetSpawnLocation(FTransform Location); | ||
|
||
}; |