added different troopers, made camera spectate, changed floor material, made some other small changes + clang-format
parent
985612b4de
commit
114f9b28e1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,81 +1,91 @@
|
||||
#include "Trooper.h"
|
||||
#include <Kismet/GameplayStatics.h>
|
||||
#include "MyPlayerController.h"
|
||||
#include "Net/UnrealNetwork.h"
|
||||
|
||||
// Sets default values
|
||||
ATrooper::ATrooper()
|
||||
{
|
||||
bReplicates = true;
|
||||
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);
|
||||
}
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
Tags.Add(FName("Trooper"));
|
||||
MyStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
|
||||
RootComponent = MyStaticMesh;
|
||||
MeshPath = TEXT("StaticMesh'/Game/StarterContent/Props/SM_Chair.SM_Chair'");
|
||||
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshToUse(MeshPath);
|
||||
if (MeshToUse.Object) {
|
||||
MyStaticMesh->SetStaticMesh(MeshToUse.Object);
|
||||
}
|
||||
}
|
||||
|
||||
// void ATrooper::SetStaticMesh() const {
|
||||
// static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshToUse(MeshPath);
|
||||
// if (MeshToUse.Object) {
|
||||
// MyStaticMesh->SetStaticMesh(MeshToUse.Object);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ATrooper::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
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::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::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;
|
||||
void ATrooper::MoveTrooper(FVector const NewPos) {
|
||||
TargetLocation = NewPos;
|
||||
bIsMoving = true;
|
||||
}
|
||||
|
||||
uint8 ATrooper::GetId() const
|
||||
{
|
||||
return Id;
|
||||
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);
|
||||
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;
|
||||
uint8 ATrooper::GetPlayerIndex() const {
|
||||
return PlayerIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// ATrooperWizard::ATrooperWizard() {
|
||||
// MeshPath = TEXT(
|
||||
// // "StaticMesh'/Game/CityofBrass_Enemies/Static/Wizard_StaticMesh.Wizard_StaticMesh'");
|
||||
// "StaticMesh'/Game/CityofBrass_Enemies/Static/SkeletonMelee_StaticMesh.SkeletonMelee_StaticMesh'");
|
||||
// SetStaticMesh();
|
||||
// }
|
||||
//
|
||||
// ATrooperSkeletonMelee::ATrooperSkeletonMelee() {
|
||||
// MeshPath = TEXT(
|
||||
// "StaticMesh'/Game/CityofBrass_Enemies/Static/SkeletonMelee_StaticMesh.SkeletonMelee_StaticMesh'");
|
||||
// SetStaticMesh();
|
||||
// }
|
||||
|
@ -1,55 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "Components/StaticMeshComponent.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "Trooper.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class TURNBASEDTUTORIAL_API ATrooper : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
class TURNBASEDTUTORIAL_API ATrooper : public ACharacter {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
ATrooper();
|
||||
// Sets default values for this actor's properties
|
||||
ATrooper();
|
||||
|
||||
void Initialize(uint8 const NewPlayerIndex, FVector const SpawnLocation, uint8 const NewId);
|
||||
void Initialize(uint8 const NewPlayerIndex,
|
||||
FVector const SpawnLocation,
|
||||
uint8 const NewId);
|
||||
|
||||
UFUNCTION()
|
||||
uint8 GetPlayerIndex() const;
|
||||
UFUNCTION()
|
||||
uint8 GetPlayerIndex() const;
|
||||
|
||||
UFUNCTION()
|
||||
void MoveTrooper(FVector const NewPos);
|
||||
UFUNCTION()
|
||||
void MoveTrooper(FVector const NewPos);
|
||||
|
||||
UFUNCTION()
|
||||
uint8 GetId() const;
|
||||
UFUNCTION()
|
||||
uint8 GetId() const;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void Tick(float const DeltaTime) override;
|
||||
virtual void Tick(float const DeltaTime) override;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
UStaticMeshComponent* MyStaticMesh;
|
||||
// void SetStaticMesh() const;
|
||||
|
||||
private:
|
||||
UPROPERTY(Replicated)
|
||||
uint8 PlayerIndex;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
UStaticMeshComponent *MyStaticMesh;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
uint8 Id;
|
||||
const TCHAR *MeshPath = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
float Speed = 300.0f;
|
||||
UPROPERTY(Replicated)
|
||||
uint8 PlayerIndex;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
FVector CurrentLocation;
|
||||
UPROPERTY(Replicated)
|
||||
uint8 Id;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
FVector TargetLocation;
|
||||
UPROPERTY()
|
||||
float Speed = 300.0f;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
bool bIsMoving = false;
|
||||
UPROPERTY(Replicated)
|
||||
FVector CurrentLocation;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
FVector TargetLocation;
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
bool bIsMoving = false;
|
||||
};
|
||||
|
||||
// UCLASS()
|
||||
// class ATrooperWizard : public ATrooper {
|
||||
// GENERATED_BODY()
|
||||
//
|
||||
// public:
|
||||
// ATrooperWizard();
|
||||
//
|
||||
// };
|
||||
//
|
||||
// UCLASS()
|
||||
// class ATrooperSkeletonMelee : public ATrooper {
|
||||
// GENERATED_BODY()
|
||||
//
|
||||
// public:
|
||||
// ATrooperSkeletonMelee();
|
||||
//
|
||||
// };
|
||||
|
Loading…
Reference in new issue