Disable any non-basic logic.

pull/5/head
eyakm1 2 years ago
parent 6f5376e01d
commit 29c31b81af

@ -4,14 +4,16 @@
#include "Kismet/GameplayStatics.h"
AMyGameMode::AMyGameMode() : Super() {
AMyGameMode::AMyGameMode() : Super()
{
UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor"));
GameStateClass = AMyGameState::StaticClass();
PlayerControllerClass = AMyPlayerController::StaticClass();
DefaultPawnClass = AMyPawn::StaticClass();
}
AActor *AMyGameMode::ChoosePlayerStart_Implementation(AController *Player) {
AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player)
{
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers());
InitializeSpawnPointsIfNeeded();
auto ptr = *SpawnPoints.Find(GetNumPlayers());
@ -19,26 +21,21 @@ AActor *AMyGameMode::ChoosePlayerStart_Implementation(AController *Player) {
return ptr;
}
void AMyGameMode::InitializeSpawnPointsIfNeeded() {
if (SpawnPoints.Num() != 0) {
void AMyGameMode::InitializeSpawnPointsIfNeeded()
{
if (SpawnPoints.Num() != 0)
{
return;
}
for (TActorIterator <AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) {
UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex());
SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator);
}
}
void AMyGameMode::BeginPlay() {
Super::BeginPlay();
}
void AMyGameMode::StartGame() {
GetPlayerController()->StartTurn();
}
AMyPlayerController *AMyGameMode::GetPlayerController() {
return dynamic_cast<AMyPlayerController *>(
UGameplayStatics::GetPlayerController(GetWorld(), 0)
);
// TArray<AActor*> MyPlayerStartObjects;
// UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyPlayerStart::StaticClass(), MyPlayerStartObjects);
// for (const auto& PlayerStart : MyPlayerStartObjects)
// {
// SpawnPoints.Add(dynamic_cast<AMyPlayerStart*>(PlayerStart)->GetPlayerIndex(),
// dynamic_cast<AMyPlayerStart*>(PlayerStart));
// }
}

@ -12,7 +12,6 @@
#include "MyGameMode.generated.h"
UCLASS()
class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode
{
@ -21,15 +20,10 @@ class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode
public:
AMyGameMode();
void BeginPlay() override;
AActor* ChoosePlayerStart_Implementation(AController* Player);
AActor *ChoosePlayerStart_Implementation(AController * Player);
private:
void StartGame();
void InitializeSpawnPointsIfNeeded();
AMyPlayerController *GetPlayerController();
TMap<uint8, AMyPlayerStart*> SpawnPoints;
};

@ -2,62 +2,62 @@
#include "MyPlayerController.h"
AMyPlayerController::AMyPlayerController() : Super(), IsMyTurn(false), SelectedTrooper(nullptr) {
UE_LOG(LogTemp, Warning, TEXT("Player controller created"));
}
void AMyPlayerController::SetupInputComponent() {
Super::SetupInputComponent();
InputComponent->BindAction("MyAction", IE_Pressed, this,
&AMyPlayerController::OnLeftMouseClick);
}
void AMyPlayerController::StartTurn() {
IsMyTurn = true;
UE_LOG(LogTemp, Warning, TEXT("Your turn"));
}
void AMyPlayerController::EndTurn() {
IsMyTurn = false;
UE_LOG(LogTemp, Warning, TEXT("Not your turn"));
}
void AMyPlayerController::SetTrooperIsMoving(bool isMoving) {
IsThereTrooperMoving = isMoving;
}
void AMyPlayerController::OnLeftMouseClick() {
if (IsThereTrooperMoving) {
return;
}
UE_LOG(LogTemp, Warning, TEXT("Mouse clicked"));
FHitResult HitResult;
bool IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult);
if (IsHitResult) {
AActor *actor = HitResult.Actor.Get();
if (actor->ActorHasTag(FName("Trooper"))) {
ATrooper* trooper = dynamic_cast<ATrooper*>(actor);
if (trooper != nullptr && trooper != SelectedTrooper) {
if (trooper->IsOnPlayersSide()) {
UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, on our side"),
trooper->GetId());
SelectedTrooper = trooper;
}
else {
UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, enemy"),
trooper->GetId());
UE_LOG(LogTemp, Warning, TEXT("Trooper #%d hit enemy trooper #%d"),
SelectedTrooper->GetId(), trooper->GetId());
}
}
}
else if (actor->ActorHasTag(FName("Floor"))) {
UE_LOG(LogTemp, Warning, TEXT("Hitted floor: %f, %f, %f"), HitResult.Location.X,
HitResult.Location.Y, HitResult.Location.Z);
if (SelectedTrooper != nullptr) {
SelectedTrooper->MoveTrooper(HitResult.Location);
IsThereTrooperMoving = true;
}
}
}
}
// AMyPlayerController::AMyPlayerController() : Super(), IsMyTurn(false), SelectedTrooper(nullptr) {
// UE_LOG(LogTemp, Warning, TEXT("Player controller created"));
// }
//
// void AMyPlayerController::SetupInputComponent() {
// Super::SetupInputComponent();
// InputComponent->BindAction("MyAction", IE_Pressed, this,
// &AMyPlayerController::OnLeftMouseClick);
// }
//
// void AMyPlayerController::StartTurn() {
// IsMyTurn = true;
// UE_LOG(LogTemp, Warning, TEXT("Your turn"));
// }
//
// void AMyPlayerController::EndTurn() {
// IsMyTurn = false;
// UE_LOG(LogTemp, Warning, TEXT("Not your turn"));
// }
//
// void AMyPlayerController::SetTrooperIsMoving(bool isMoving) {
// IsThereTrooperMoving = isMoving;
// }
//
// void AMyPlayerController::OnLeftMouseClick() {
// if (IsThereTrooperMoving) {
// return;
// }
// UE_LOG(LogTemp, Warning, TEXT("Mouse clicked"));
// FHitResult HitResult;
// bool IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult);
// if (IsHitResult) {
// AActor *actor = HitResult.Actor.Get();
// if (actor->ActorHasTag(FName("Trooper"))) {
// ATrooper* trooper = dynamic_cast<ATrooper*>(actor);
// if (trooper != nullptr && trooper != SelectedTrooper) {
// if (trooper->IsOnPlayersSide()) {
// UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, on our side"),
// trooper->GetId());
// SelectedTrooper = trooper;
// }
// else {
// UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, enemy"),
// trooper->GetId());
// UE_LOG(LogTemp, Warning, TEXT("Trooper #%d hit enemy trooper #%d"),
// SelectedTrooper->GetId(), trooper->GetId());
// }
// }
// }
// else if (actor->ActorHasTag(FName("Floor"))) {
// UE_LOG(LogTemp, Warning, TEXT("Hitted floor: %f, %f, %f"), HitResult.Location.X,
// HitResult.Location.Y, HitResult.Location.Z);
// if (SelectedTrooper != nullptr) {
// SelectedTrooper->MoveTrooper(HitResult.Location);
// IsThereTrooperMoving = true;
// }
// }
// }
// }

@ -15,23 +15,23 @@ class TURNBASEDTUTORIAL_API AMyPlayerController : public APlayerController
GENERATED_BODY()
public:
AMyPlayerController();
void StartTurn();
void EndTurn();
virtual void SetupInputComponent() override;
void SetTrooperIsMoving(bool isMoving);
// AMyPlayerController();
//
// void StartTurn();
//
// void EndTurn();
//
// virtual void SetupInputComponent() override;
//
// void SetTrooperIsMoving(bool isMoving);
private:
bool IsMyTurn;
bool IsThereTrooperMoving = false;
ATrooper* SelectedTrooper;
void OnLeftMouseClick();
// bool IsMyTurn;
//
// bool IsThereTrooperMoving = false;
//
// ATrooper* SelectedTrooper;
//
// void OnLeftMouseClick();
};

@ -3,8 +3,7 @@
#include "MyPlayerStart.h"
uint8 AMyPlayerStart::GetPlayerIndex() const {
uint8 AMyPlayerStart::GetPlayerIndex() const
{
return PlayerIndex;
}

@ -26,22 +26,22 @@ void ATrooper::BeginPlay()
}
void ATrooper::Tick(float deltaTime) {
if (IsMoving) {
FVector vector = (MoveToVector - Position);
vector.Normalize();
vector *= (Speed * deltaTime);
if (vector.Size() >= (MoveToVector - Position).Size()) {
Position = MoveToVector;
IsMoving = false;
dynamic_cast<AMyPlayerController*>(
UGameplayStatics::GetPlayerController(GetWorld(), 0)
)->SetTrooperIsMoving(false);
}
else {
Position += vector;
}
SetActorLocation(Position);
}
// if (IsMoving) {
// FVector vector = (MoveToVector - Position);
// vector.Normalize();
// vector *= (Speed * deltaTime);
// if (vector.Size() >= (MoveToVector - Position).Size()) {
// Position = MoveToVector;
// IsMoving = false;
// dynamic_cast<AMyPlayerController*>(
// UGameplayStatics::GetPlayerController(GetWorld(), 0)
// )->SetTrooperIsMoving(false);
// }
// else {
// Position += vector;
// }
// SetActorLocation(Position);
// }
}
void ATrooper::MoveTrooper(FVector newPos) {

@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "{B4FE6467-4579-3D84-B22A-558A3D607596}",
"EngineAssociation": "4.27",
"Category": "",
"Description": "",
"Modules": [

Loading…
Cancel
Save