게임 시작하기
This commit is contained in:
parent
bf043b91fd
commit
9625075c19
@ -38,13 +38,9 @@ void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
|
||||
void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser)
|
||||
{
|
||||
if (Health <= 0.0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Health -= Damage;
|
||||
if (Health <= 0.0f && GameMode)
|
||||
{
|
||||
GameMode->ActorDied(DamagedActor);
|
||||
}
|
||||
UE_LOG(LogTemp, Warning, TEXT("Health: %f"), Health);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ AProjectile::AProjectile()
|
||||
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
|
||||
ProjectileMovement->InitialSpeed = 400.0f;
|
||||
ProjectileMovement->MaxSpeed = 1000.0f;
|
||||
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
@ -24,14 +23,12 @@ void AProjectile::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
ProjectileMesh->OnComponentHit.AddDynamic(this, &AProjectile::OnHit);
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void AProjectile::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
|
@ -10,8 +10,7 @@
|
||||
void AToonTanksGameMode::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
|
||||
PlayerController = Cast<AToonTanksPlayerController>(UGameplayStatics::GetPlayerController(this, 0));
|
||||
HandleGameStart();
|
||||
}
|
||||
|
||||
void AToonTanksGameMode::ActorDied(AActor* DeadActor)
|
||||
@ -20,12 +19,30 @@ void AToonTanksGameMode::ActorDied(AActor* DeadActor)
|
||||
{
|
||||
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));
|
||||
if (PlayerController)
|
||||
{
|
||||
PlayerController->SetPlayerEnabledState(false);
|
||||
FTimerHandle PlayerEnableTimerHandle;
|
||||
FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(
|
||||
PlayerController,
|
||||
&AToonTanksPlayerController::SetPlayerEnabledState,
|
||||
true
|
||||
);
|
||||
GetWorldTimerManager().SetTimer(
|
||||
PlayerEnableTimerHandle,
|
||||
TimerDelegate,
|
||||
StartDelay,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
@ -29,5 +29,11 @@ private:
|
||||
// ToonTanksPlayerController Pointer of player pawn.
|
||||
UPROPERTY()
|
||||
class AToonTanksPlayerController* PlayerController;
|
||||
|
||||
// Delay time for starting game
|
||||
float StartDelay = 3.f;
|
||||
|
||||
// Handles Game Start Action
|
||||
void HandleGameStart();
|
||||
|
||||
};
|
||||
|
@ -6,12 +6,8 @@
|
||||
void AToonTanksPlayerController::SetPlayerEnabledState(bool bPlayerEnabled)
|
||||
{
|
||||
if (bPlayerEnabled)
|
||||
{
|
||||
GetPawn()->EnableInput(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetPawn()->DisableInput(this);
|
||||
}
|
||||
bShowMouseCursor = bPlayerEnabled;
|
||||
}
|
@ -9,9 +9,7 @@ void ATower::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
if (InFireRange())
|
||||
{
|
||||
RotateTurret(Tank->GetActorLocation());
|
||||
}
|
||||
}
|
||||
|
||||
void ATower::HandleDestruction()
|
||||
@ -30,9 +28,7 @@ void ATower::BeginPlay()
|
||||
void ATower::TryFire()
|
||||
{
|
||||
if (InFireRange())
|
||||
{
|
||||
Fire();
|
||||
}
|
||||
}
|
||||
|
||||
bool ATower::InFireRange() const
|
||||
@ -41,9 +37,7 @@ bool ATower::InFireRange() const
|
||||
{
|
||||
float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation());
|
||||
if (Distance <= FireRange)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user