diff --git a/Source/Nakatomi/LevelKeyPickup.cpp b/Source/Nakatomi/LevelKeyPickup.cpp new file mode 100644 index 0000000..01ac428 --- /dev/null +++ b/Source/Nakatomi/LevelKeyPickup.cpp @@ -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(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(UGameplayStatics::GetGameInstance(GetWorld()))) + { + gameInstance->GetCurrentLevelManager()->IncrementInitialLevelKeys(); + } + + Super::OnOverlapBegin(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); +} diff --git a/Source/Nakatomi/LevelKeyPickup.h b/Source/Nakatomi/LevelKeyPickup.h new file mode 100644 index 0000000..9ddbaae --- /dev/null +++ b/Source/Nakatomi/LevelKeyPickup.h @@ -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; +}; diff --git a/Source/Nakatomi/NakatomiGameInstance.cpp b/Source/Nakatomi/NakatomiGameInstance.cpp index 23b012c..b91c284 100644 --- a/Source/Nakatomi/NakatomiGameInstance.cpp +++ b/Source/Nakatomi/NakatomiGameInstance.cpp @@ -10,14 +10,9 @@ UNakatomiAIAttackTokenManager* UNakatomiGameInstance::GetAIAttackTokenManager() UNakatomiLevelManager* UNakatomiGameInstance::GetCurrentLevelManager() { - if (IsValid(currentLevelManager)) - { - return currentLevelManager; - } - - UE_LOG(LogTemp, Warning, TEXT("No Level manager set.")) - - return nullptr; + return IsValid(currentLevelManager) + ? currentLevelManager + : currentLevelManager = NewObject(this, TEXT("Level Manager")); } void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager) diff --git a/Source/Nakatomi/NakatomiLevelManager.cpp b/Source/Nakatomi/NakatomiLevelManager.cpp index 6f0ab53..41a8400 100644 --- a/Source/Nakatomi/NakatomiLevelManager.cpp +++ b/Source/Nakatomi/NakatomiLevelManager.cpp @@ -26,3 +26,13 @@ void UNakatomiLevelManager::LoadNextLevel() UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel); } } + +void UNakatomiLevelManager::IncrementInitialLevelKeys() +{ + LevelKeys++; +} + +void UNakatomiLevelManager::IncrementCollectedLevelKeys() +{ + CollectedLevelKeys++; +} diff --git a/Source/Nakatomi/NakatomiLevelManager.h b/Source/Nakatomi/NakatomiLevelManager.h index 5875519..7fa4493 100644 --- a/Source/Nakatomi/NakatomiLevelManager.h +++ b/Source/Nakatomi/NakatomiLevelManager.h @@ -18,12 +18,21 @@ class NAKATOMI_API UNakatomiLevelManager : public UObject private: UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) TSoftObjectPtr NextLevel; + + int LevelKeys = 0; + + int CollectedLevelKeys = 0; public: - UFUNCTION() void LoadNextLevel(); + UFUNCTION() + void IncrementInitialLevelKeys(); + + UFUNCTION() + void IncrementCollectedLevelKeys(); + private: UFUNCTION()