diff --git a/Content/Blueprints/Pawns/BP_PawnTank.uasset b/Content/Blueprints/Pawns/BP_PawnTank.uasset index dd9ae45..3f56fc5 100644 --- a/Content/Blueprints/Pawns/BP_PawnTank.uasset +++ b/Content/Blueprints/Pawns/BP_PawnTank.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7746e90f50e6d2dc0c841f00796f10ab58aa882de6049cfc1c6c87d8ebd95ebb -size 37786 +oid sha256:0dfa34e9e710dc948138b99e70d57b70248d6a9642112f216f9b31a96472416b +size 38048 diff --git a/Source/ToonTanks/BasePawn.cpp b/Source/ToonTanks/BasePawn.cpp index 6012e7d..2437584 100644 --- a/Source/ToonTanks/BasePawn.cpp +++ b/Source/ToonTanks/BasePawn.cpp @@ -3,6 +3,7 @@ #include "BasePawn.h" +#include "Projectile.h" #include "Components/CapsuleComponent.h" #include "Kismet/GameplayStatics.h" @@ -25,7 +26,6 @@ ABasePawn::ABasePawn() ProjectileSpawnPoint->SetupAttachment(TurretMesh); } -// Rotate Turret to Target Location void ABasePawn::RotateTurret(FVector LookAtTarget) { FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation(); @@ -40,7 +40,6 @@ void ABasePawn::RotateTurret(FVector LookAtTarget) ); } -// Fire Projectile at Projectile Spawn Point void ABasePawn::Fire() { DrawDebugSphere( @@ -52,4 +51,7 @@ void ABasePawn::Fire() false, 3.0 ); + FVector Location = ProjectileSpawnPoint->GetComponentLocation(); + FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation(); + GetWorld()->SpawnActor(ProjectileClass, Location, Rotation); } diff --git a/Source/ToonTanks/BasePawn.h b/Source/ToonTanks/BasePawn.h index 161fae0..c415976 100644 --- a/Source/ToonTanks/BasePawn.h +++ b/Source/ToonTanks/BasePawn.h @@ -16,8 +16,10 @@ public: ABasePawn(); protected: + // Rotate Turret to Target Location void RotateTurret(FVector LookAtTarget); + // Fire Projectile at Projectile Spawn Point void Fire(); private: @@ -36,5 +38,8 @@ private: // Scene Component of Projectile Spawn Point UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) USceneComponent* ProjectileSpawnPoint; + + UPROPERTY(EditDefaultsOnly, Category = "Combat") + TSubclassOf ProjectileClass; }; diff --git a/Source/ToonTanks/Tank.cpp b/Source/ToonTanks/Tank.cpp index 08a29f6..6fab97f 100644 --- a/Source/ToonTanks/Tank.cpp +++ b/Source/ToonTanks/Tank.cpp @@ -55,7 +55,6 @@ void ATank::BeginPlay() PlayerControllerRef = Cast(GetController()); } -// Move operation through W/S key void ATank::Move(float Value) { FVector DeltaLocation = FVector::ZeroVector; @@ -64,7 +63,6 @@ void ATank::Move(float Value) this->AddActorLocalOffset(DeltaLocation, true); } -// Turn operation through A/D key void ATank::Turn(float Value) { FRotator DeltaRotation = FRotator::ZeroRotator; diff --git a/Source/ToonTanks/Tank.h b/Source/ToonTanks/Tank.h index 9aabc33..34342f4 100644 --- a/Source/ToonTanks/Tank.h +++ b/Source/ToonTanks/Tank.h @@ -28,21 +28,29 @@ protected: virtual void BeginPlay() override; private: + // USpringArmComponent for Camera UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) class USpringArmComponent* SpringArm; + // UCameraComponent for Camera Component UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) class UCameraComponent* Camera; + // Movement speed for Move() operation UPROPERTY(EditAnywhere, Category = "Movement", BlueprintReadWrite, meta=(AllowPrivateAccess="true")) float Speed = 400.0f; + // Turn speed for Turn() operation UPROPERTY(EditAnywhere, Category = "Movement") float TurnRate = 45.0f; + // PlayerController Pointer for Mouse Location Detection + UPROPERTY() APlayerController* PlayerControllerRef; - + + // Move operation through W/S key void Move(float Value); + // Turn operation through A/D key void Turn(float Value); }; diff --git a/Source/ToonTanks/Tower.cpp b/Source/ToonTanks/Tower.cpp index 6c8c297..d5e7707 100644 --- a/Source/ToonTanks/Tower.cpp +++ b/Source/ToonTanks/Tower.cpp @@ -18,10 +18,10 @@ void ATower::BeginPlay() { Super::BeginPlay(); Tank = Cast(UGameplayStatics::GetPlayerPawn(this, 0)); - GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &ATower::CheckFireCondition, FireRate, true); + GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &ATower::TryFire, FireRate, true); } -void ATower::CheckFireCondition() +void ATower::TryFire() { if (InFireRange()) { @@ -29,7 +29,7 @@ void ATower::CheckFireCondition() } } -bool ATower::InFireRange() +bool ATower::InFireRange() const { if (Tank) { diff --git a/Source/ToonTanks/Tower.h b/Source/ToonTanks/Tower.h index 543d242..961ec0c 100644 --- a/Source/ToonTanks/Tower.h +++ b/Source/ToonTanks/Tower.h @@ -21,16 +21,23 @@ protected: virtual void BeginPlay() override; private: + // Tank Object Pointer which is target class ATank* Tank; + // Distance to Start Tracking the target UPROPERTY(EditAnywhere, Category = "Rotate") - float FireRange = 400; + float FireRange = 400.0f; + // FTimerHandle for SetTimer. FTimerHandle FireRateTimerHandle; - float FireRate = 2.0f; - - void CheckFireCondition(); - bool InFireRange(); + // Fire Period + float FireRate = 2.0f; + + // Check Tank is in Range. If so, Fire operation occurs. + void TryFire(); + + // Check Tank is in Fire Range, + bool InFireRange() const; };