@@ -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+ }
0 commit comments