Create LevelKeyPickup

This commit is contained in:
baz 2024-03-11 21:01:50 +00:00
parent a183445aba
commit 532bcc7e66
5 changed files with 81 additions and 9 deletions

View File

@ -0,0 +1,33 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "LevelKeyPickup.h"
#include "NakatomiGameInstance.h"
#include "Kismet/GameplayStatics.h"
void ALevelKeyPickup::BeginPlay()
{
Super::BeginPlay();
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
gameInstance->GetCurrentLevelManager()->IncrementInitialLevelKeys();
}
}
void ALevelKeyPickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ALevelKeyPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
gameInstance->GetCurrentLevelManager()->IncrementInitialLevelKeys();
}
Super::OnOverlapBegin(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Pickup.h"
#include "LevelKeyPickup.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API ALevelKeyPickup : public APickup
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
virtual void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
};

View File

@ -10,14 +10,9 @@ UNakatomiAIAttackTokenManager* UNakatomiGameInstance::GetAIAttackTokenManager()
UNakatomiLevelManager* UNakatomiGameInstance::GetCurrentLevelManager() UNakatomiLevelManager* UNakatomiGameInstance::GetCurrentLevelManager()
{ {
if (IsValid(currentLevelManager)) return IsValid(currentLevelManager)
{ ? currentLevelManager
return currentLevelManager; : currentLevelManager = NewObject<UNakatomiLevelManager>(this, TEXT("Level Manager"));
}
UE_LOG(LogTemp, Warning, TEXT("No Level manager set."))
return nullptr;
} }
void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager) void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager)

View File

@ -26,3 +26,13 @@ void UNakatomiLevelManager::LoadNextLevel()
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel); UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel);
} }
} }
void UNakatomiLevelManager::IncrementInitialLevelKeys()
{
LevelKeys++;
}
void UNakatomiLevelManager::IncrementCollectedLevelKeys()
{
CollectedLevelKeys++;
}

View File

@ -19,11 +19,20 @@ private:
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TSoftObjectPtr<UWorld> NextLevel; TSoftObjectPtr<UWorld> NextLevel;
public: int LevelKeys = 0;
int CollectedLevelKeys = 0;
public:
UFUNCTION() UFUNCTION()
void LoadNextLevel(); void LoadNextLevel();
UFUNCTION()
void IncrementInitialLevelKeys();
UFUNCTION()
void IncrementCollectedLevelKeys();
private: private:
UFUNCTION() UFUNCTION()