|
|
@ -1,9 +1,8 @@
|
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "MyPlayerController.h"
|
|
|
|
#include "MyPlayerController.h"
|
|
|
|
|
|
|
|
|
|
|
|
AMyPlayerController::AMyPlayerController() : Super(), isMyTurn(false) {
|
|
|
|
AMyPlayerController::AMyPlayerController() : Super(), IsMyTurn(false), SelectedTrooper(nullptr) {
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Player controller created"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Player controller created"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -14,18 +13,51 @@ void AMyPlayerController::SetupInputComponent() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AMyPlayerController::StartTurn() {
|
|
|
|
void AMyPlayerController::StartTurn() {
|
|
|
|
isMyTurn = true;
|
|
|
|
IsMyTurn = true;
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Your turn"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Your turn"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AMyPlayerController::EndTurn() {
|
|
|
|
void AMyPlayerController::EndTurn() {
|
|
|
|
isMyTurn = false;
|
|
|
|
IsMyTurn = false;
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Not your turn"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Not your turn"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AMyPlayerController::SetTrooperIsMoving(bool isMoving) {
|
|
|
|
|
|
|
|
IsThereTrooperMoving = isMoving;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AMyPlayerController::OnLeftMouseClick() {
|
|
|
|
void AMyPlayerController::OnLeftMouseClick() {
|
|
|
|
|
|
|
|
if (IsThereTrooperMoving) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Mouse clicked"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Mouse clicked"));
|
|
|
|
FHitResult HitResult;
|
|
|
|
FHitResult HitResult;
|
|
|
|
bool IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult);
|
|
|
|
bool IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult);
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("hitted: %s"), IsHitResult ? "Yes" : "No");
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|