-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainGameMode.cpp
More file actions
130 lines (98 loc) · 3.08 KB
/
MainGameMode.cpp
File metadata and controls
130 lines (98 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Fill out your copyright notice in the Description page of Project Settings.
#include "MainGameMode.h"
#include "AnomalyBase.h" // AAnomalyBase 클래스 포함
#include "Blueprint/UserWidget.h" // UUserWidget 클래스 포함
#include "Kismet/GameplayStatics.h" // GameplayStatics 클래스 포함
#include "CameraPlayerController.h"
#include "CameraPlayerController.h"
AAnomalyBase* AnomalyCount;
AMainGameMode::AMainGameMode()
{
PrimaryActorTick.bCanEverTick = true;
}
bool AMainGameMode::CheckIfRightKeyIsDown()
{
if(bIsRightKeyDown)
{
return true;
}
else
{
return false;
}
}
void AMainGameMode::EndGame()
{
if (AnomalyCount == nullptr)
{
UE_LOG(LogTemp, Error, TEXT("AnomalyCount is null"));
return;
}
//UE_LOG(LogTemp, Warning, TEXT("UnfixedAnamolyCount: %d"), AnomalyCount->UnfixedAnamolyCount);
if (AnomalyCount->UnfixedAnamolyCount >= 60)
{
bIsGameOver = true;
//UE_LOG(LogTemp, Warning, TEXT("게임 오버"));
//UE_LOG(LogTemp, Warning, TEXT("bIsGameOver: %d"), bIsGameOver);
}
else
{
bIsGameOver = false;
//UE_LOG(LogTemp, Warning, TEXT("게임 계속 진행"));
}
}
void AMainGameMode::WinGame()
{
// 플레이어 컨트롤러에서 직접 GetElapsedTime() 호출
if (ACameraPlayerController* CameraController = Cast<ACameraPlayerController>(UGameplayStatics::GetPlayerController(GetWorld(), 0)))
{
CurrentTime = CameraController->GetElapsedTime();
}
else
{
UE_LOG(LogTemp, Error, TEXT("CameraController is null"));
}
//6시
if(CurrentTime >= 360)
{
bIsPlayerWinner = true;
}
else
{
bIsPlayerWinner = false;
}
}
void AMainGameMode::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
CheckIfRightKeyIsDown();
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
if(PlayerController && PlayerController->WasInputKeyJustPressed(EKeys::Right))
{
bIsRightKeyDown = true;
}
EndGame();
// UE_LOG(LogTemp, Error, TEXT("EndGame Function Called") );
WinGame();
}
void AMainGameMode::BeginPlay()
{
Super::BeginPlay();
RandomTime = FMath::RandRange(100.0f, 300.0f);
bIsRightKeyDown = false;
// 게임 시작 시 AnomalyCount를 찾음 (맵에 배치된 첫 번째 AnomalyBase 인스턴스를 가져옴)
TArray<AActor*> FoundAnomalies;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AAnomalyBase::StaticClass(), FoundAnomalies);
if (FoundAnomalies.Num() > 0)
{
AnomalyCount = Cast<AAnomalyBase>(FoundAnomalies[0]); // 첫 번째 AnomalyBase 인스턴스를 참조
UE_LOG(LogTemp, Warning, TEXT("AnomalyCount 초기화 성공"));
}
else
{
AnomalyCount = nullptr;
UE_LOG(LogTemp, Error, TEXT("AnomalyCount 초기화 실패"));
}
bIsGameOver = false;
bIsPlayerWinner = false;
}