Skip to content

Commit 61a0f58

Browse files
committed
Handle states in 'BatteryCollectorGameMode' class
1 parent d459faa commit 61a0f58

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Source/BatteryCollector/BatteryCollectorGameMode.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,65 @@ void ABatteryCollectorGameMode::SetCurrentState(EBatteryPlayState NewState)
9999
{
100100
//set current state
101101
CurrentState = NewState;
102+
// handle the new current state
103+
HandleNewState(CurrentState);
104+
102105
}
106+
107+
void ABatteryCollectorGameMode::HandleNewState(EBatteryPlayState NewState)
108+
{
109+
switch (NewState)
110+
{
111+
// If the game is playing
112+
case EBatteryPlayState::EPlaying:
113+
{
114+
// spawn volumes active
115+
for (ASpawnVolume* Volume : SpawnVolumeActors)
116+
{
117+
Volume->SetSpawningActive(true);
118+
}
119+
}
120+
break;
121+
// If we've won the game
122+
case EBatteryPlayState::EWon:
123+
{
124+
// spawn volumes inactive
125+
for (ASpawnVolume* Volume : SpawnVolumeActors)
126+
{
127+
Volume->SetSpawningActive(false);
128+
}
129+
}
130+
break;
131+
// If we've lost the game
132+
case EBatteryPlayState::EGameOver:
133+
{
134+
// spawn volumes inactive
135+
for (ASpawnVolume* Volume : SpawnVolumeActors)
136+
{
137+
Volume->SetSpawningActive(false);
138+
}
139+
// block player input
140+
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0);
141+
if (PlayerController)
142+
{
143+
PlayerController->SetCinematicMode(true, false, false, true, true);
144+
}
145+
// ragdoll the character
146+
ACharacter* MyCharacter = UGameplayStatics::GetPlayerCharacter(this, 0);
147+
if (MyCharacter)
148+
{
149+
MyCharacter->GetMesh()->SetSimulatePhysics(true);
150+
MyCharacter->GetMovementComponent()->MovementState.bCanJump = false;
151+
}
152+
}
153+
break;
154+
// Unknown/default state
155+
default:
156+
case EBatteryPlayState::EUnknown:
157+
{
158+
// do nothing
159+
}
160+
break;
161+
}
162+
163+
}

Source/BatteryCollector/BatteryCollectorGameMode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class ABatteryCollectorGameMode : public AGameMode
5959
EBatteryPlayState CurrentState;
6060

6161
TArray<class ASpawnVolume*> SpawnVolumeActors;
62+
63+
void HandleNewState(EBatteryPlayState NewState);
6264
};
6365

6466

0 commit comments

Comments
 (0)