Skip to content

Commit

Permalink
Merge branch 'dev' into AnimationFixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GageM committed Feb 14, 2024
2 parents fd0e8df + 8872cab commit 1bc2ead
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 13 deletions.
3 changes: 0 additions & 3 deletions Content/Unbread/Core/GameModes/BP_RespawnGameMode.uasset

This file was deleted.

4 changes: 2 additions & 2 deletions Content/Unbread/Core/GameModes/MainMenuGamemode.uasset
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Unbread/Core/GameModes/RespawnGamemode.uasset
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Unbread/Core/UI/Widgets/WBP_LoseMenu.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/Unbread/Core/UI/Widgets/WBP_Main_Menu.uasset
Git LFS file not shown
3 changes: 3 additions & 0 deletions Content/Unbread/Core/UI/Widgets/WBP_WinMenu.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/Unbread/Environment/SpawnVolume.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/Unbread/Maps/CoreLevelTest.umap
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/Unbread/Maps/DeathTesting.umap
Git LFS file not shown
70 changes: 70 additions & 0 deletions Source/unbread/Private/SRespawnGameMode.cpp
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;
}
55 changes: 55 additions & 0 deletions Source/unbread/Public/SRespawnGameMode.h
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);

};

0 comments on commit 1bc2ead

Please sign in to comment.