// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/GameModeBase.h"
#include "BatteryCollectorGameMode.generated.h"
UCLASS(minimalapi)
class ABatteryCollectorGameMode : public AGameModeBase
{
GENERATED_BODY()
public:
ABatteryCollectorGameMode();
virtual void Tick(float DeltaTime) override;
protected:
// the rate at which the character loses power
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Power")
float DecayRate;
};
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "BatteryCollector.h"
#include "BatteryCollectorGameMode.h"
#include "BatteryCollectorCharacter.h"
#include "Kismet/GameplayStatics.h"
ABatteryCollectorGameMode::ABatteryCollectorGameMode()
{
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/ThirdPersonCPP/Blueprints/ThirdPersonCharacter"));
if (PlayerPawnBPClass.Class != NULL)
{
DefaultPawnClass = PlayerPawnBPClass.Class;
}
// base decay rate
DecayRate = 0.01f;
}
void ABatteryCollectorGameMode::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// Check that we using the battery collector character
ABatteryCollectorCharacter* MyCharacter = Cast<ABatteryCollectorCharacter>(UGameplayStatics::GetPlayerPawn(this, 0));
if (MyCharacter)
{
// if the character's power is positive
if (MyCharacter->GetCurrentPower() > 0)
{
// decrease the characters's power using the decay rate
MyCharacter->UpdatePower(-DeltaTime*DecayRate*(MyCharacter->GetInitialPower()));
}
}
}