49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "ToonTanksGameMode.h"
|
|
#include "Tank.h"
|
|
#include "ToonTanksPlayerController.h"
|
|
#include "Tower.h"
|
|
#include "Kismet/GameplayStatics.h"
|
|
|
|
void AToonTanksGameMode::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
HandleGameStart();
|
|
}
|
|
|
|
void AToonTanksGameMode::ActorDied(AActor* DeadActor)
|
|
{
|
|
if (DeadActor == Tank)
|
|
{
|
|
Tank->HandleDestruction();
|
|
if (PlayerController)
|
|
PlayerController->SetPlayerEnabledState(false);
|
|
}
|
|
else if (ATower* DestroyedTower = Cast<ATower>(DeadActor))
|
|
DestroyedTower->HandleDestruction();
|
|
}
|
|
|
|
void AToonTanksGameMode::HandleGameStart()
|
|
{
|
|
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
|
|
PlayerController = Cast<AToonTanksPlayerController>(UGameplayStatics::GetPlayerController(this, 0));
|
|
StartGame();
|
|
if (PlayerController)
|
|
{
|
|
PlayerController->SetPlayerEnabledState(false);
|
|
FTimerHandle PlayerEnableTimerHandle;
|
|
FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(
|
|
PlayerController,
|
|
&AToonTanksPlayerController::SetPlayerEnabledState,
|
|
true
|
|
);
|
|
GetWorldTimerManager().SetTimer(
|
|
PlayerEnableTimerHandle,
|
|
TimerDelegate,
|
|
StartDelay,
|
|
false
|
|
);
|
|
}
|
|
} |