Skip to content

Commit

Permalink
BT78 Adding TickComponent() Back.cmproj
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Tristem committed Jul 17, 2016
1 parent e53e945 commit 3bb86fc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
22 changes: 22 additions & 0 deletions BattleTank/BattleTank.uproject
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,27 @@
"AIModule"
]
}
],
"Plugins": [
{
"Name": "GearVR",
"Enabled": false
},
{
"Name": "OculusInput",
"Enabled": false
},
{
"Name": "OculusLibrary",
"Enabled": false
},
{
"Name": "OculusRift",
"Enabled": false
},
{
"Name": "SteamVR",
"Enabled": false
}
]
}
24 changes: 18 additions & 6 deletions BattleTank/Source/BattleTank/Private/TankAimingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@ UTankAimingComponent::UTankAimingComponent()
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
bWantsBeginPlay = true;
PrimaryComponentTick.bCanEverTick = false;
PrimaryComponentTick.bCanEverTick = true;
}

void UTankAimingComponent::BeginPlay()
{
// So that first first is after initial reload
LastFireTime = FPlatformTime::Seconds();
}

// ...
void UTankAimingComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
if ((FPlatformTime::Seconds() - LastFireTime) > ReloadTimeInSeconds)
{
FiringState = EFiringState::Reloading;
}
// TODO Handle aiming and locked states
}

void UTankAimingComponent::Initialise(UTankBarrel* BarrelToSet, UTankTurret* TurretToSet)
Expand Down Expand Up @@ -66,12 +79,11 @@ void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection)

void UTankAimingComponent::Fire()
{
if (!ensure(Barrel && ProjectileBlueprint)) { return; }
bool isReloaded = (FPlatformTime::Seconds() - LastFireTime) > ReloadTimeInSeconds;

if (isReloaded)
if (FiringState != EFiringState::Reloading)
{
// Spawn a projectile at the socket location on the barrel
if (!ensure(Barrel)) { return; }
if (!ensure(ProjectileBlueprint)) { return; }
auto Projectile = GetWorld()->SpawnActor<AProjectile>(
ProjectileBlueprint,
Barrel->GetSocketLocation(FName("Projectile")),
Expand Down
6 changes: 5 additions & 1 deletion BattleTank/Source/BattleTank/Public/TankAimingComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ class BATTLETANK_API UTankAimingComponent : public UActorComponent

protected:
UPROPERTY(BlueprintReadOnly, Category = "State")
EFiringState FiringState = EFiringState::Locked;
EFiringState FiringState = EFiringState::Reloading;

private:
// Sets default values for this component's properties
UTankAimingComponent();

virtual void BeginPlay() override;

virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;

void MoveBarrelTowards(FVector AimDirection);

UTankBarrel* Barrel = nullptr;
Expand Down

0 comments on commit 3bb86fc

Please sign in to comment.