Compare commits
3 Commits
4e5daf9a54
...
bf043b91fd
Author | SHA1 | Date | |
---|---|---|---|
bf043b91fd | |||
0ff8baf48f | |||
c5f5288e96 |
@ -7,6 +7,7 @@ r.DefaultFeature.AutoExposure=False
|
|||||||
[/Script/EngineSettings.GameMapsSettings]
|
[/Script/EngineSettings.GameMapsSettings]
|
||||||
EditorStartupMap=/Game/Maps/Main.Main
|
EditorStartupMap=/Game/Maps/Main.Main
|
||||||
GameDefaultMap=/Game/Maps/Main.Main
|
GameDefaultMap=/Game/Maps/Main.Main
|
||||||
|
GlobalDefaultGameMode=/Game/Blueprints/GameMode/BP_ToonTanksGameMode.BP_ToonTanksGameMode_C
|
||||||
|
|
||||||
[/Script/HardwareTargeting.HardwareTargetingSettings]
|
[/Script/HardwareTargeting.HardwareTargetingSettings]
|
||||||
TargetedHardwareClass=Desktop
|
TargetedHardwareClass=Desktop
|
||||||
@ -71,3 +72,6 @@ ConnectionType=USBOnly
|
|||||||
bUseManualIPAddress=False
|
bUseManualIPAddress=False
|
||||||
ManualIPAddress=
|
ManualIPAddress=
|
||||||
|
|
||||||
|
|
||||||
|
[CoreRedirects]
|
||||||
|
+PropertyRedirects=(OldName="/Script/ToonTanks.Tank.PlayerControllerRef",NewName="/Script/ToonTanks.Tank.PlayerController")
|
BIN
Content/Blueprints/Controller/BP_ToonTanksPlayerController.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/Controller/BP_ToonTanksPlayerController.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Blueprints/GameMode/BP_ToonTanksGameMode.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/GameMode/BP_ToonTanksGameMode.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Blueprints/Pawns/BP_PawnTank.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Pawns/BP_PawnTank.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Maps/Main.umap
(Stored with Git LFS)
BIN
Content/Maps/Main.umap
(Stored with Git LFS)
Binary file not shown.
@ -26,6 +26,12 @@ ABasePawn::ABasePawn()
|
|||||||
ProjectileSpawnPoint->SetupAttachment(TurretMesh);
|
ProjectileSpawnPoint->SetupAttachment(TurretMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABasePawn::HandleDestruction()
|
||||||
|
{
|
||||||
|
// TODO: Visual & Sound Effect Implementation
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ABasePawn::RotateTurret(FVector LookAtTarget)
|
void ABasePawn::RotateTurret(FVector LookAtTarget)
|
||||||
{
|
{
|
||||||
FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();
|
FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();
|
||||||
|
@ -15,6 +15,9 @@ public:
|
|||||||
// Sets default values for this pawn's properties
|
// Sets default values for this pawn's properties
|
||||||
ABasePawn();
|
ABasePawn();
|
||||||
|
|
||||||
|
// Handles Base Pawn destruction by Damage
|
||||||
|
virtual void HandleDestruction();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Rotate Turret to Target Location
|
// Rotate Turret to Target Location
|
||||||
void RotateTurret(FVector LookAtTarget);
|
void RotateTurret(FVector LookAtTarget);
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
|
|
||||||
|
#include "ToonTanksGameMode.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
// Sets default values for this component's properties
|
// Sets default values for this component's properties
|
||||||
UHealthComponent::UHealthComponent()
|
UHealthComponent::UHealthComponent()
|
||||||
{
|
{
|
||||||
@ -20,6 +23,7 @@ void UHealthComponent::BeginPlay()
|
|||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
Health = MaxHealth;
|
Health = MaxHealth;
|
||||||
GetOwner()->OnTakeAnyDamage.AddDynamic(this, &UHealthComponent::DamageTaken);
|
GetOwner()->OnTakeAnyDamage.AddDynamic(this, &UHealthComponent::DamageTaken);
|
||||||
|
GameMode = Cast<AToonTanksGameMode>(UGameplayStatics::GetGameMode(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -33,8 +37,14 @@ void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
|
|||||||
|
|
||||||
void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser)
|
void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser)
|
||||||
{
|
{
|
||||||
if (Damage <= 0.0f)
|
if (Health <= 0.0f)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
Health -= Damage;
|
Health -= Damage;
|
||||||
|
if (Health <= 0.0f && GameMode)
|
||||||
|
{
|
||||||
|
GameMode->ActorDied(DamagedActor);
|
||||||
|
}
|
||||||
UE_LOG(LogTemp, Warning, TEXT("Health: %f"), Health);
|
UE_LOG(LogTemp, Warning, TEXT("Health: %f"), Health);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,10 @@ private:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser);
|
void DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser);
|
||||||
|
|
||||||
|
// AToonTanksGameMode Pointer for Handling Dead Actor
|
||||||
|
UPROPERTY()
|
||||||
|
class AToonTanksGameMode* GameMode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Called every frame
|
// Called every frame
|
||||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "Tank.h"
|
#include "Tank.h"
|
||||||
|
|
||||||
|
#include "ToonTanksPlayerController.h"
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
#include "GameFramework/SpringArmComponent.h"
|
#include "GameFramework/SpringArmComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
@ -29,30 +30,35 @@ void ATank::Tick(float DeltaTime)
|
|||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
// Rotate Tank to Mouse Pointer Location
|
// Rotate Tank to Mouse Pointer Location
|
||||||
if (PlayerControllerRef)
|
if (PlayerController)
|
||||||
{
|
{
|
||||||
FHitResult HitResult;
|
FHitResult HitResult;
|
||||||
PlayerControllerRef->GetHitResultUnderCursor(
|
PlayerController->GetHitResultUnderCursor(
|
||||||
ECollisionChannel::ECC_Visibility,
|
ECollisionChannel::ECC_Visibility,
|
||||||
false,
|
false,
|
||||||
HitResult
|
HitResult
|
||||||
);
|
);
|
||||||
DrawDebugSphere(
|
|
||||||
GetWorld(),
|
|
||||||
HitResult.ImpactPoint,
|
|
||||||
25,
|
|
||||||
12,
|
|
||||||
FColor::Green
|
|
||||||
);
|
|
||||||
RotateTurret(HitResult.ImpactPoint);
|
RotateTurret(HitResult.ImpactPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ATank::HandleDestruction()
|
||||||
|
{
|
||||||
|
Super::HandleDestruction();
|
||||||
|
SetActorHiddenInGame(true);
|
||||||
|
SetActorTickEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
APlayerController* ATank::GetPlayerController() const
|
||||||
|
{
|
||||||
|
return this->PlayerController;
|
||||||
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
void ATank::BeginPlay()
|
void ATank::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
PlayerControllerRef = Cast<APlayerController>(GetController());
|
PlayerController = Cast<APlayerController>(GetController());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATank::Move(float Value)
|
void ATank::Move(float Value)
|
||||||
|
@ -22,6 +22,12 @@ public:
|
|||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
// Handle's Tank Destruction by Damage
|
||||||
|
virtual void HandleDestruction() override;
|
||||||
|
|
||||||
|
// Get Current Player Controller Pointer
|
||||||
|
APlayerController* GetPlayerController() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
@ -46,7 +52,7 @@ private:
|
|||||||
|
|
||||||
// PlayerController Pointer for Mouse Location Detection
|
// PlayerController Pointer for Mouse Location Detection
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
APlayerController* PlayerControllerRef;
|
APlayerController* PlayerController;
|
||||||
|
|
||||||
// Move operation through W/S key
|
// Move operation through W/S key
|
||||||
void Move(float Value);
|
void Move(float Value);
|
||||||
|
31
Source/ToonTanks/ToonTanksGameMode.cpp
Normal file
31
Source/ToonTanks/ToonTanksGameMode.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// 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();
|
||||||
|
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
|
||||||
|
PlayerController = Cast<AToonTanksPlayerController>(UGameplayStatics::GetPlayerController(this, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AToonTanksGameMode::ActorDied(AActor* DeadActor)
|
||||||
|
{
|
||||||
|
if (DeadActor == Tank)
|
||||||
|
{
|
||||||
|
Tank->HandleDestruction();
|
||||||
|
if (PlayerController)
|
||||||
|
{
|
||||||
|
PlayerController->SetPlayerEnabledState(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ATower* DestroyedTower = Cast<ATower>(DeadActor))
|
||||||
|
{
|
||||||
|
DestroyedTower->HandleDestruction();
|
||||||
|
}
|
||||||
|
}
|
33
Source/ToonTanks/ToonTanksGameMode.h
Normal file
33
Source/ToonTanks/ToonTanksGameMode.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/GameModeBase.h"
|
||||||
|
#include "ToonTanksGameMode.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class TOONTANKS_API AToonTanksGameMode : public AGameModeBase
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Handles input or something after Actor died.
|
||||||
|
void ActorDied(AActor* DeadActor);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Tank Pointer for DeadActor which is ATank.
|
||||||
|
UPROPERTY()
|
||||||
|
class ATank* Tank;
|
||||||
|
|
||||||
|
// ToonTanksPlayerController Pointer of player pawn.
|
||||||
|
UPROPERTY()
|
||||||
|
class AToonTanksPlayerController* PlayerController;
|
||||||
|
|
||||||
|
};
|
17
Source/ToonTanks/ToonTanksPlayerController.cpp
Normal file
17
Source/ToonTanks/ToonTanksPlayerController.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "ToonTanksPlayerController.h"
|
||||||
|
|
||||||
|
void AToonTanksPlayerController::SetPlayerEnabledState(bool bPlayerEnabled)
|
||||||
|
{
|
||||||
|
if (bPlayerEnabled)
|
||||||
|
{
|
||||||
|
GetPawn()->EnableInput(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetPawn()->DisableInput(this);
|
||||||
|
}
|
||||||
|
bShowMouseCursor = bPlayerEnabled;
|
||||||
|
}
|
21
Source/ToonTanks/ToonTanksPlayerController.h
Normal file
21
Source/ToonTanks/ToonTanksPlayerController.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/PlayerController.h"
|
||||||
|
#include "ToonTanksPlayerController.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class TOONTANKS_API AToonTanksPlayerController : public APlayerController
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Set this controller to Enabled or Disabled.
|
||||||
|
void SetPlayerEnabledState(bool bPlayerEnabled);
|
||||||
|
|
||||||
|
};
|
@ -14,6 +14,12 @@ void ATower::Tick(float DeltaTime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ATower::HandleDestruction()
|
||||||
|
{
|
||||||
|
Super::HandleDestruction();
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
void ATower::BeginPlay()
|
void ATower::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
@ -17,11 +17,15 @@ class TOONTANKS_API ATower : public ABasePawn
|
|||||||
public:
|
public:
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
// Handles Tower Destruction by Damage
|
||||||
|
virtual void HandleDestruction() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Tank Object Pointer which is target
|
// Tank Object Pointer which is target
|
||||||
|
UPROPERTY()
|
||||||
class ATank* Tank;
|
class ATank* Tank;
|
||||||
|
|
||||||
// Distance to Start Tracking the target
|
// Distance to Start Tracking the target
|
||||||
|
Loading…
x
Reference in New Issue
Block a user