From a6f936e73e9edce6c35cef3512eefb47be6b864c Mon Sep 17 00:00:00 2001 From: Maxim <73167493+m4xxx1m@users.noreply.github.com> Date: Sun, 12 Mar 2023 01:09:13 +0300 Subject: [PATCH] added movement, definition of side of trooper, 5 troopers on each side, moved camera etc --- Content/BattleField/BattleFieldMap.umap | Bin 633129 -> 631866 bytes Content/MainMenu/MainMenuLevel.umap | Bin 34008 -> 34008 bytes Source/TurnBasedTutorial/MyGameMode.cpp | 18 +++++-- .../TurnBasedTutorial/MyPlayerController.cpp | 42 +++++++++++++-- Source/TurnBasedTutorial/MyPlayerController.h | 10 +++- Source/TurnBasedTutorial/Trooper.cpp | 51 +++++++++++++++++- Source/TurnBasedTutorial/Trooper.h | 33 ++++++++++-- 7 files changed, 139 insertions(+), 15 deletions(-) diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index 61b7e15ef0fbaec0c8db50504066e3ccf7499009..8f7cb0e92651c9d7f80572daa882b37dbcaf11e7 100644 GIT binary patch delta 12205 zcmd^F33OED6@C)}Bq5QBOeRc(GJ#1T3zI!0#wsBs%B~`)AjAX$Ss($z8iWb^qG0fk z5|Fk~6a_(zLC~;QLjh4itF|gtw7B5fo{Fa&+v&aU-TUUvn|Z^u=k%QR^q%wQU+(wc z?Z5x>26n%d*nTRp>Fo6#lO?IMBuS&|YAc}XB3;<@$Lvu9p&8y!lEy(D6Dvt~2uNn4R^&dK`z>d^&*AD?vj>(XU($!#NeUoD?m`1)X*B*LSkhvfkD%ip@5h*L0}&Bivj;x8HPH_FUT9iJB61_Z#2r`3=f2n z6CC3o2*imQ2;&ICXwE0S9GBL6PAEM{i{XR{gc%uxL8BCmE1>tc2O+3D2+R~i4DCN$ zvnoT7!a&S|ATW!9z%($1^h^GdXf1=N_J{d(5SS+dU}XL1*{%Q}WFcmM5SSN(z#R2p z6#xBscFY5kTmCTb27!4mAO`fKXTJ{!QZOG}19Jf6JQM`xVJ!yz*L(IN2wJZN`N8Z5 z%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FP+nM62iMMQj9CKb%&9Kz!Hd5z@A4ZQ|NiPAmB{Jmt4DKFA`%&63Fb;L8Ep0BfoKeTP9j*d;;D*apr*$%3gp+AJ9Fau!)oJLs+76;&Xq zHKJo*{G{vTllkh>b0PWvCyP9s_U49rixWR;JwJIsjL+JigiLt+^2w4>C(rue$bUZH z+VnH=AHR#A`$a#>a|7>+Yu_2yZll_d YYJaK`R0mKUNc9@3k*DI?qsGSmFSdhMVE_OC diff --git a/Content/MainMenu/MainMenuLevel.umap b/Content/MainMenu/MainMenuLevel.umap index 80e9e23da1deceeda6ba345dfe437ce91598f324..dbee8ab85c241418c18968b6c5484c8b87e90650 100644 GIT binary patch delta 233 zcmVj@jvI2L2NFQad=D+s7-GPbZuNku>@&N4A5@yv(0#R2Mn>FHAQ*hsza5B5JZ!~ jfiVb*r>H}$w<|-FL4i4wkX{Otpnk8D?1ICyJ%XD8$$wS9 delta 233 zcmVe@E#j{oc zB2)`7I4v?UE-^PQFfp@(RWTSKGekl{K`}NoG(MmI%7GB!p*GPBoiTnP}2IKXe;%Ggi5 zK!g8q|FPebL2NFQad=D+ETtRbSrP_MkQW}>Pdb+7v(0#R2Mn4RWGetMapName().Contains("BattleFieldMap")) { UE_LOG(LogTemp, Warning, TEXT("Player Logined")); @@ -19,10 +20,21 @@ void AMyGameMode::BeginPlay() { } void AMyGameMode::StartGame() { - FVector Location(0.0f, 0.0f, 0.0f); - FRotator Rotation(0.0f, 0.0f, 0.0f); + FVector Location(2000.0f, -1000.0f, 0.0f); + FRotator Rotation(0.0f, 180.0f, 0.0f); FActorSpawnParameters SpawnInfo; - GetWorld()->SpawnActor(Location, Rotation, SpawnInfo); + for (int i = 0; i < 5; ++i) { + AActor *spawned = GetWorld()->SpawnActor(Location, Rotation, SpawnInfo); + dynamic_cast(spawned)->InitTrooper(Location, true); + Location += { 0.f, 500.f, 0.0f }; + } + Location = { -2000.0f, -1000.0f, 0.0f }; + Rotation = { 0.0f, 0.0f, 0.0f }; + for (int i = 0; i < 5; ++i) { + AActor* spawned = GetWorld()->SpawnActor(Location, Rotation, SpawnInfo); + dynamic_cast(spawned)->InitTrooper(Location, false); + Location += { 0.f, 500.f, 0.0f }; + } GetPlayerController()->StartTurn(); } diff --git a/Source/TurnBasedTutorial/MyPlayerController.cpp b/Source/TurnBasedTutorial/MyPlayerController.cpp index 663eabd..f069d84 100644 --- a/Source/TurnBasedTutorial/MyPlayerController.cpp +++ b/Source/TurnBasedTutorial/MyPlayerController.cpp @@ -1,9 +1,8 @@ // Fill out your copyright notice in the Description page of Project Settings. - #include "MyPlayerController.h" -AMyPlayerController::AMyPlayerController() : Super(), isMyTurn(false) { +AMyPlayerController::AMyPlayerController() : Super(), IsMyTurn(false), SelectedTrooper(nullptr) { UE_LOG(LogTemp, Warning, TEXT("Player controller created")); } @@ -14,18 +13,51 @@ void AMyPlayerController::SetupInputComponent() { } void AMyPlayerController::StartTurn() { - isMyTurn = true; + IsMyTurn = true; UE_LOG(LogTemp, Warning, TEXT("Your turn")); } void AMyPlayerController::EndTurn() { - isMyTurn = false; + 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); - 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(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; + } + } + } } diff --git a/Source/TurnBasedTutorial/MyPlayerController.h b/Source/TurnBasedTutorial/MyPlayerController.h index bdc7e25..90fb98a 100644 --- a/Source/TurnBasedTutorial/MyPlayerController.h +++ b/Source/TurnBasedTutorial/MyPlayerController.h @@ -1,8 +1,8 @@ // Fill out your copyright notice in the Description page of Project Settings. - #pragma once #include "CoreMinimal.h" +#include "Trooper.h" #include "GameFramework/PlayerController.h" #include "MyPlayerController.generated.h" @@ -23,8 +23,14 @@ public: virtual void SetupInputComponent() override; + void SetTrooperIsMoving(bool isMoving); + private: - bool isMyTurn; + bool IsMyTurn; + + bool IsThereTrooperMoving = false; + + ATrooper* SelectedTrooper; void OnLeftMouseClick(); diff --git a/Source/TurnBasedTutorial/Trooper.cpp b/Source/TurnBasedTutorial/Trooper.cpp index a762cb8..2315b23 100644 --- a/Source/TurnBasedTutorial/Trooper.cpp +++ b/Source/TurnBasedTutorial/Trooper.cpp @@ -1,7 +1,12 @@ #include "Trooper.h" +#include +#include "MyPlayerController.h" // Sets default values ATrooper::ATrooper() { + PrimaryActorTick.bCanEverTick = true; + Tags.Add(FName("Trooper")); + Id = NumberOfTroopersForId++; Position.Set(0, 0, 0); Mesh = CreateDefaultSubobject("Mesh"); RootComponent = Mesh; @@ -18,7 +23,51 @@ ATrooper::ATrooper() { void ATrooper::BeginPlay() { Super::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( + UGameplayStatics::GetPlayerController(GetWorld(), 0) + )->SetTrooperIsMoving(false); + } + else { + Position += vector; + } + SetActorLocation(Position); + } +} + +void ATrooper::MoveTrooper(FVector newPos) { + MoveToVector = newPos; + IsMoving = true; +} + +int ATrooper::NumberOfTroopersForId = 0; + +void ATrooper::InitNumberOfTroopersForId() { + NumberOfTroopersForId = 0; +} +FVector ATrooper::GetPosition() { + return Position; +} + +bool ATrooper::IsOnPlayersSide() { + return OnPlayersSide; +} + +int ATrooper::GetId() { + return Id; +} + +void ATrooper::InitTrooper(FVector position, bool onPlayersSide) { + Position = position; + OnPlayersSide = onPlayersSide; +} diff --git a/Source/TurnBasedTutorial/Trooper.h b/Source/TurnBasedTutorial/Trooper.h index fbfe19d..c6d2b75 100644 --- a/Source/TurnBasedTutorial/Trooper.h +++ b/Source/TurnBasedTutorial/Trooper.h @@ -10,22 +10,47 @@ UCLASS() class TURNBASEDTUTORIAL_API ATrooper : public AActor { GENERATED_BODY() - + public: // Sets default values for this actor's properties ATrooper(); protected: - // Called when the game starts or when spawned + static int NumberOfTroopersForId; + virtual void BeginPlay() override; + virtual void Tick(float deltaTime) override; + UPROPERTY() FVector Position; + UPROPERTY() + bool OnPlayersSide; + + UPROPERTY() + int Id; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UStaticMeshComponent* Mesh; -public: - void MoveTrooper(); + UPROPERTY() + float Speed = 300.0f; + + bool IsMoving = false; + + FVector MoveToVector; + +public: + void MoveTrooper(FVector newPos); + + static void InitNumberOfTroopersForId(); + + FVector GetPosition(); + + bool IsOnPlayersSide(); + + int GetId(); + void InitTrooper(FVector position, bool onPlayersSide); };