diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 9d7116b..50c64f0 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -1,10 +1,19 @@ [/Script/EngineSettings.GameMapsSettings] -GameDefaultMap=/Game/MainMenu/MainMenuLevel - - -EditorStartupMap=/Game/StarterContent/Maps/Minimal_Default +EditorStartupMap=/Game/BattleField/BattleFieldMap.BattleFieldMap +LocalMapOptions= +TransitionMap=None +bUseSplitscreen=True +TwoPlayerSplitscreenLayout=Horizontal +ThreePlayerSplitscreenLayout=FavorTop +FourPlayerSplitscreenLayout=Grid +bOffsetPlayerGamepadIds=False +GameInstanceClass=/Script/Engine.GameInstance +GameDefaultMap=/Game/MainMenu/MainMenuLevel.MainMenuLevel +ServerDefaultMap=/Engine/Maps/Entry.Entry +GlobalDefaultGameMode=/Script/TurnBasedTutorial.MyGameMode +GlobalDefaultServerGameMode=None [/Script/HardwareTargeting.HardwareTargetingSettings] TargetedHardwareClass=Desktop diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini new file mode 100644 index 0000000..07e992c --- /dev/null +++ b/Config/DefaultInput.ini @@ -0,0 +1,86 @@ +[/Script/Engine.InputSettings] +-AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) +-AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) +-AxisConfig=(AxisKeyName="Mouse2D",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) ++AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Mouse2D",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MouseWheelAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_LeftTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_RightTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_Special_Left_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_Special_Left_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Daydream_Left_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Daydream_Left_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Daydream_Right_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Daydream_Right_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Vive_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Vive_Left_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Vive_Left_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Vive_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Vive_Right_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Vive_Right_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Left_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Left_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Right_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MixedReality_Right_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Left_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Right_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="OculusTouch_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Grip_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Trackpad_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Left_Trackpad_Touch",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Grip_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Grip_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Trigger_Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Trackpad_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Trackpad_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="ValveIndex_Right_Trackpad_Force",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) +bAltEnterTogglesFullscreen=True +bF11TogglesFullscreen=True +bUseMouseForTouch=False +bEnableMouseSmoothing=True +bEnableFOVScaling=True +bCaptureMouseOnLaunch=True +bAlwaysShowTouchInterface=False +bShowConsoleOnFourFingerTap=True +bEnableGestureRecognizer=False +bUseAutocorrect=False +DefaultViewportMouseCaptureMode=CapturePermanently_IncludingInitialMouseDown +DefaultViewportMouseLockMode=LockOnCapture +FOVScale=0.011110 +DoubleClickTime=0.200000 ++ActionMappings=(ActionName="MyAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton) +DefaultPlayerInputClass=/Script/Engine.PlayerInput +DefaultInputComponentClass=/Script/Engine.InputComponent +DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks +-ConsoleKeys=Tilde ++ConsoleKeys=Tilde + diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index eb6bb7d..8f7cb0e 100644 Binary files a/Content/BattleField/BattleFieldMap.umap and b/Content/BattleField/BattleFieldMap.umap differ diff --git a/Content/MainMenu/MainMenuLevel.umap b/Content/MainMenu/MainMenuLevel.umap index 70a3634..dbee8ab 100644 Binary files a/Content/MainMenu/MainMenuLevel.umap and b/Content/MainMenu/MainMenuLevel.umap differ diff --git a/Content/StarterContent/Particles/Materials/M_Burst.uasset b/Content/StarterContent/Particles/Materials/M_Burst.uasset index 95fa7fe..1bc05f7 100644 Binary files a/Content/StarterContent/Particles/Materials/M_Burst.uasset and b/Content/StarterContent/Particles/Materials/M_Burst.uasset differ diff --git a/Content/StarterContent/Particles/Materials/M_Fire_SubUV.uasset b/Content/StarterContent/Particles/Materials/M_Fire_SubUV.uasset index 4b2548d..d0f7225 100644 Binary files a/Content/StarterContent/Particles/Materials/M_Fire_SubUV.uasset and b/Content/StarterContent/Particles/Materials/M_Fire_SubUV.uasset differ diff --git a/Content/StarterContent/Particles/Materials/M_smoke_subUV.uasset b/Content/StarterContent/Particles/Materials/M_smoke_subUV.uasset index 8a89654..d96330b 100644 Binary files a/Content/StarterContent/Particles/Materials/M_smoke_subUV.uasset and b/Content/StarterContent/Particles/Materials/M_smoke_subUV.uasset differ diff --git a/Content/StarterContent/Props/Materials/M_MaterialSphere.uasset b/Content/StarterContent/Props/Materials/M_MaterialSphere.uasset index a370ae8..377dd95 100644 Binary files a/Content/StarterContent/Props/Materials/M_MaterialSphere.uasset and b/Content/StarterContent/Props/Materials/M_MaterialSphere.uasset differ diff --git a/Source/TurnBasedTutorial/MyGameMode.cpp b/Source/TurnBasedTutorial/MyGameMode.cpp index e33132c..d09b49d 100644 --- a/Source/TurnBasedTutorial/MyGameMode.cpp +++ b/Source/TurnBasedTutorial/MyGameMode.cpp @@ -1,5 +1,45 @@ // Fill out your copyright notice in the Description page of Project Settings. - #include "MyGameMode.h" +#include "Kismet/GameplayStatics.h" +#include "Trooper.h" + +AMyGameMode::AMyGameMode() : Super() { + UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor")); + PlayerControllerClass = AMyPlayerController::StaticClass(); +} + +void AMyGameMode::BeginPlay() { + Super::BeginPlay(); + ATrooper::InitNumberOfTroopersForId(); + UE_LOG(LogTemp, Warning, TEXT("GameMode BeginPlay")); + if (GetWorld()->GetMapName().Contains("BattleFieldMap")) { + UE_LOG(LogTemp, Warning, TEXT("Player Logined")); + StartGame(); + } +} + +void AMyGameMode::StartGame() { + FVector Location(2000.0f, -1000.0f, 0.0f); + FRotator Rotation(0.0f, 180.0f, 0.0f); + FActorSpawnParameters 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(); +} +AMyPlayerController *AMyGameMode::GetPlayerController() { + return dynamic_cast( + UGameplayStatics::GetPlayerController(GetWorld(), 0) + ); +} diff --git a/Source/TurnBasedTutorial/MyGameMode.h b/Source/TurnBasedTutorial/MyGameMode.h index 8993397..f7cccbe 100644 --- a/Source/TurnBasedTutorial/MyGameMode.h +++ b/Source/TurnBasedTutorial/MyGameMode.h @@ -3,15 +3,24 @@ #pragma once #include "CoreMinimal.h" +#include "MyPlayerController.h" #include "GameFramework/GameMode.h" #include "MyGameMode.generated.h" -/** - * - */ + + UCLASS() class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode { GENERATED_BODY() - + +public: + AMyGameMode(); + + void BeginPlay() override; + +private: + void StartGame(); + + AMyPlayerController *GetPlayerController(); }; diff --git a/Source/TurnBasedTutorial/MyPlayerController.cpp b/Source/TurnBasedTutorial/MyPlayerController.cpp new file mode 100644 index 0000000..f069d84 --- /dev/null +++ b/Source/TurnBasedTutorial/MyPlayerController.cpp @@ -0,0 +1,63 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#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(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 new file mode 100644 index 0000000..90fb98a --- /dev/null +++ b/Source/TurnBasedTutorial/MyPlayerController.h @@ -0,0 +1,37 @@ +// 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" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API AMyPlayerController : public APlayerController +{ + GENERATED_BODY() + +public: + AMyPlayerController(); + + void StartTurn(); + + void EndTurn(); + + virtual void SetupInputComponent() override; + + void SetTrooperIsMoving(bool isMoving); + +private: + bool IsMyTurn; + + bool IsThereTrooperMoving = false; + + ATrooper* SelectedTrooper; + + void OnLeftMouseClick(); + +}; diff --git a/Source/TurnBasedTutorial/MyPlayerState.cpp b/Source/TurnBasedTutorial/MyPlayerState.cpp new file mode 100644 index 0000000..00bda13 --- /dev/null +++ b/Source/TurnBasedTutorial/MyPlayerState.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "MyPlayerState.h" + diff --git a/Source/TurnBasedTutorial/MyPlayerState.h b/Source/TurnBasedTutorial/MyPlayerState.h new file mode 100644 index 0000000..991a5cb --- /dev/null +++ b/Source/TurnBasedTutorial/MyPlayerState.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerState.h" +#include "MyPlayerState.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API AMyPlayerState : public APlayerState +{ + GENERATED_BODY() + +}; diff --git a/Source/TurnBasedTutorial/Trooper.cpp b/Source/TurnBasedTutorial/Trooper.cpp new file mode 100644 index 0000000..2315b23 --- /dev/null +++ b/Source/TurnBasedTutorial/Trooper.cpp @@ -0,0 +1,73 @@ +#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; + static ConstructorHelpers::FObjectFinder MeshToUse(TEXT( + "StaticMesh'/Game/StarterContent/Props/SM_Chair.SM_Chair'" + )); + if (MeshToUse.Object) + { + Mesh->SetStaticMesh(MeshToUse.Object); + } +} + +// Called when the game starts or when spawned +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 new file mode 100644 index 0000000..c6d2b75 --- /dev/null +++ b/Source/TurnBasedTutorial/Trooper.h @@ -0,0 +1,56 @@ + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "Components/StaticMeshComponent.h" +#include "Trooper.generated.h" + +UCLASS() +class TURNBASEDTUTORIAL_API ATrooper : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + ATrooper(); + +protected: + 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; + + 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); +}; diff --git a/Source/TurnBasedTutorial/TurnBasedTutorialGameModeBase.cpp b/Source/TurnBasedTutorial/TurnBasedTutorialGameModeBase.cpp deleted file mode 100644 index 67d5b7f..0000000 --- a/Source/TurnBasedTutorial/TurnBasedTutorialGameModeBase.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - - -#include "TurnBasedTutorialGameModeBase.h" - diff --git a/Source/TurnBasedTutorial/TurnBasedTutorialGameModeBase.h b/Source/TurnBasedTutorial/TurnBasedTutorialGameModeBase.h deleted file mode 100644 index 50946a2..0000000 --- a/Source/TurnBasedTutorial/TurnBasedTutorialGameModeBase.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "GameFramework/GameModeBase.h" -#include "TurnBasedTutorialGameModeBase.generated.h" - -/** - * - */ -UCLASS() -class TURNBASEDTUTORIAL_API ATurnBasedTutorialGameModeBase : public AGameModeBase -{ - GENERATED_BODY() - -};