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 "Trooper.h"
|
||||||
#include <Kismet/GameplayStatics.h>
|
#include <Kismet/GameplayStatics.h>
|
||||||
#include "MyPlayerController.h"
|
|
||||||
#include "Net/UnrealNetwork.h"
|
#include "Net/UnrealNetwork.h"
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
ATrooper::ATrooper()
|
ATrooper::ATrooper() {
|
||||||
{
|
bReplicates = true;
|
||||||
bReplicates = true;
|
|
||||||
|
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
Tags.Add(FName("Trooper"));
|
Tags.Add(FName("Trooper"));
|
||||||
MyStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
|
MyStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
|
||||||
RootComponent = MyStaticMesh;
|
RootComponent = MyStaticMesh;
|
||||||
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshToUse(TEXT(
|
MeshPath = TEXT("StaticMesh'/Game/StarterContent/Props/SM_Chair.SM_Chair'");
|
||||||
"StaticMesh'/Game/StarterContent/Props/SM_Chair.SM_Chair'"
|
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshToUse(MeshPath);
|
||||||
));
|
if (MeshToUse.Object) {
|
||||||
if (MeshToUse.Object)
|
MyStaticMesh->SetStaticMesh(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
|
// Called when the game starts or when spawned
|
||||||
void ATrooper::BeginPlay()
|
void ATrooper::BeginPlay() {
|
||||||
{
|
Super::BeginPlay();
|
||||||
Super::BeginPlay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATrooper::Initialize(uint8 const NewPlayerIndex, FVector const SpawnLocation, uint8 const NewId)
|
void ATrooper::Initialize(uint8 const NewPlayerIndex,
|
||||||
{
|
FVector const SpawnLocation,
|
||||||
PlayerIndex = NewPlayerIndex;
|
uint8 const NewId) {
|
||||||
bIsMoving = false;
|
PlayerIndex = NewPlayerIndex;
|
||||||
CurrentLocation = SpawnLocation;
|
bIsMoving = false;
|
||||||
Id = NewId;
|
CurrentLocation = SpawnLocation;
|
||||||
|
Id = NewId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATrooper::Tick(float const DeltaTime)
|
void ATrooper::Tick(float const DeltaTime) {
|
||||||
{
|
if (!bIsMoving)
|
||||||
if (!bIsMoving)
|
return;
|
||||||
return;
|
FVector PositionVector = (TargetLocation - CurrentLocation);
|
||||||
FVector PositionVector = (TargetLocation - CurrentLocation);
|
PositionVector.Normalize();
|
||||||
PositionVector.Normalize();
|
PositionVector *= (Speed * DeltaTime);
|
||||||
PositionVector *= (Speed * DeltaTime);
|
if (PositionVector.Size() >= (TargetLocation - CurrentLocation).Size()) {
|
||||||
if (PositionVector.Size() >= (TargetLocation - CurrentLocation).Size())
|
CurrentLocation = TargetLocation;
|
||||||
{
|
bIsMoving = false;
|
||||||
CurrentLocation = TargetLocation;
|
} else {
|
||||||
bIsMoving = false;
|
CurrentLocation += PositionVector;
|
||||||
}
|
}
|
||||||
else
|
SetActorLocation(CurrentLocation);
|
||||||
{
|
|
||||||
CurrentLocation += PositionVector;
|
|
||||||
}
|
|
||||||
SetActorLocation(CurrentLocation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATrooper::MoveTrooper(FVector const NewPos)
|
void ATrooper::MoveTrooper(FVector const NewPos) {
|
||||||
{
|
TargetLocation = NewPos;
|
||||||
TargetLocation = NewPos;
|
bIsMoving = true;
|
||||||
bIsMoving = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 ATrooper::GetId() const
|
uint8 ATrooper::GetId() const {
|
||||||
{
|
return Id;
|
||||||
return Id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ATrooper::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
void ATrooper::GetLifetimeReplicatedProps(
|
||||||
{
|
TArray<FLifetimeProperty> &OutLifetimeProps) const {
|
||||||
DOREPLIFETIME(ATrooper, PlayerIndex);
|
DOREPLIFETIME(ATrooper, PlayerIndex);
|
||||||
DOREPLIFETIME(ATrooper, CurrentLocation);
|
DOREPLIFETIME(ATrooper, CurrentLocation);
|
||||||
DOREPLIFETIME(ATrooper, TargetLocation);
|
DOREPLIFETIME(ATrooper, TargetLocation);
|
||||||
DOREPLIFETIME(ATrooper, bIsMoving);
|
DOREPLIFETIME(ATrooper, bIsMoving);
|
||||||
DOREPLIFETIME(ATrooper, Id);
|
DOREPLIFETIME(ATrooper, Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 ATrooper::GetPlayerIndex() const
|
uint8 ATrooper::GetPlayerIndex() const {
|
||||||
{
|
return PlayerIndex;
|
||||||
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
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameFramework/Actor.h"
|
|
||||||
#include "Components/StaticMeshComponent.h"
|
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "Trooper.generated.h"
|
#include "Trooper.generated.h"
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class TURNBASEDTUTORIAL_API ATrooper : public ACharacter
|
class TURNBASEDTUTORIAL_API ATrooper : public ACharacter {
|
||||||
{
|
GENERATED_BODY()
|
||||||
GENERATED_BODY()
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
ATrooper();
|
ATrooper();
|
||||||
|
|
||||||
void Initialize(uint8 const NewPlayerIndex, FVector const SpawnLocation, uint8 const NewId);
|
void Initialize(uint8 const NewPlayerIndex,
|
||||||
|
FVector const SpawnLocation,
|
||||||
|
uint8 const NewId);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
uint8 GetPlayerIndex() const;
|
uint8 GetPlayerIndex() const;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void MoveTrooper(FVector const NewPos);
|
void MoveTrooper(FVector const NewPos);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
uint8 GetId() const;
|
uint8 GetId() const;
|
||||||
|
|
||||||
protected:
|
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)
|
// void SetStaticMesh() const;
|
||||||
UStaticMeshComponent* MyStaticMesh;
|
|
||||||
|
|
||||||
private:
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||||
UPROPERTY(Replicated)
|
UStaticMeshComponent *MyStaticMesh;
|
||||||
uint8 PlayerIndex;
|
|
||||||
|
|
||||||
UPROPERTY(Replicated)
|
const TCHAR *MeshPath = nullptr;
|
||||||
uint8 Id;
|
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY(Replicated)
|
||||||
float Speed = 300.0f;
|
uint8 PlayerIndex;
|
||||||
|
|
||||||
UPROPERTY(Replicated)
|
UPROPERTY(Replicated)
|
||||||
FVector CurrentLocation;
|
uint8 Id;
|
||||||
|
|
||||||
UPROPERTY(Replicated)
|
UPROPERTY()
|
||||||
FVector TargetLocation;
|
float Speed = 300.0f;
|
||||||
|
|
||||||
UPROPERTY(Replicated)
|
UPROPERTY(Replicated)
|
||||||
bool bIsMoving = false;
|
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