|
|
|
#include "Trooper.h"
|
|
|
|
#include <Kismet/GameplayStatics.h>
|
|
|
|
#include "MyPlayerController.h"
|
|
|
|
#include "Net/UnrealNetwork.h"
|
|
|
|
|
|
|
|
// Sets default values
|
|
|
|
ATrooper::ATrooper()
|
|
|
|
{
|
|
|
|
bReplicates = true;
|
|
|
|
|
|
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
Tags.Add(FName("Trooper"));
|
|
|
|
MyStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
|
|
|
|
RootComponent = MyStaticMesh;
|
|
|
|
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshToUse(TEXT(
|
|
|
|
"StaticMesh'/Game/StarterContent/Props/SM_Chair.SM_Chair'"
|
|
|
|
));
|
|
|
|
if (MeshToUse.Object)
|
|
|
|
{
|
|
|
|
MyStaticMesh->SetStaticMesh(MeshToUse.Object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when the game starts or when spawned
|
|
|
|
void ATrooper::BeginPlay()
|
|
|
|
{
|
|
|
|
Super::BeginPlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATrooper::Initialize(uint8 const NewPlayerIndex, FVector const SpawnLocation, uint8 const NewId)
|
|
|
|
{
|
|
|
|
PlayerIndex = NewPlayerIndex;
|
|
|
|
bIsMoving = false;
|
|
|
|
CurrentLocation = SpawnLocation;
|
|
|
|
Id = NewId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATrooper::Tick(float const DeltaTime)
|
|
|
|
{
|
|
|
|
if (!bIsMoving)
|
|
|
|
return;
|
|
|
|
FVector PositionVector = (TargetLocation - CurrentLocation);
|
|
|
|
PositionVector.Normalize();
|
|
|
|
PositionVector *= (Speed * DeltaTime);
|
|
|
|
if (PositionVector.Size() >= (TargetLocation - CurrentLocation).Size())
|
|
|
|
{
|
|
|
|
CurrentLocation = TargetLocation;
|
|
|
|
bIsMoving = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentLocation += PositionVector;
|
|
|
|
}
|
|
|
|
SetActorLocation(CurrentLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATrooper::MoveTrooper(FVector const NewPos)
|
|
|
|
{
|
|
|
|
TargetLocation = NewPos;
|
|
|
|
bIsMoving = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 ATrooper::GetId() const
|
|
|
|
{
|
|
|
|
return Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ATrooper::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
|
|
{
|
|
|
|
DOREPLIFETIME(ATrooper, PlayerIndex);
|
|
|
|
DOREPLIFETIME(ATrooper, CurrentLocation);
|
|
|
|
DOREPLIFETIME(ATrooper, TargetLocation);
|
|
|
|
DOREPLIFETIME(ATrooper, bIsMoving);
|
|
|
|
DOREPLIFETIME(ATrooper, Id);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 ATrooper::GetPlayerIndex() const
|
|
|
|
{
|
|
|
|
return PlayerIndex;
|
|
|
|
}
|