diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index 8f7cb0e..a9d9ff1 100644 Binary files a/Content/BattleField/BattleFieldMap.umap and b/Content/BattleField/BattleFieldMap.umap differ diff --git a/Content/StarterContent/Props/Materials/M_MaterialSphere_Plain.uasset b/Content/StarterContent/Props/Materials/M_MaterialSphere_Plain.uasset index cfbfba2..5a88d52 100644 Binary files a/Content/StarterContent/Props/Materials/M_MaterialSphere_Plain.uasset and b/Content/StarterContent/Props/Materials/M_MaterialSphere_Plain.uasset differ diff --git a/Source/TurnBasedTutorial/MyGameMode.cpp b/Source/TurnBasedTutorial/MyGameMode.cpp index d09b49d..ae6b98e 100644 --- a/Source/TurnBasedTutorial/MyGameMode.cpp +++ b/Source/TurnBasedTutorial/MyGameMode.cpp @@ -2,44 +2,39 @@ #include "MyGameMode.h" #include "Kismet/GameplayStatics.h" -#include "Trooper.h" + AMyGameMode::AMyGameMode() : Super() { - UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor")); - PlayerControllerClass = AMyPlayerController::StaticClass(); + UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor")); + GameStateClass = AMyGameState::StaticClass(); + PlayerControllerClass = AMyPlayerController::StaticClass(); + DefaultPawnClass = AMyPawn::StaticClass(); +} + +AActor *AMyGameMode::ChoosePlayerStart(AController *Player) { + InitializeSpawnPointsIfNeeded(); + return *SpawnPoints.Find(GetNumPlayers()); +} + +void AMyGameMode::InitializeSpawnPointsIfNeeded() { + if (SpawnPoints.Num() != 0) { + return; + } + for (TActorIterator PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) { + SpawnPoints[PlayerStartIterator->GetPlayerIndex()] = *PlayerStartIterator; + } } 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(); - } + Super::BeginPlay(); } 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(); + GetPlayerController()->StartTurn(); } AMyPlayerController *AMyGameMode::GetPlayerController() { - return dynamic_cast( - UGameplayStatics::GetPlayerController(GetWorld(), 0) - ); + return dynamic_cast( + UGameplayStatics::GetPlayerController(GetWorld(), 0) + ); } diff --git a/Source/TurnBasedTutorial/MyGameMode.h b/Source/TurnBasedTutorial/MyGameMode.h index f7cccbe..b7ba335 100644 --- a/Source/TurnBasedTutorial/MyGameMode.h +++ b/Source/TurnBasedTutorial/MyGameMode.h @@ -3,7 +3,11 @@ #pragma once #include "CoreMinimal.h" +#include "EngineUtils.h" #include "MyPlayerController.h" +#include "MyGameState.h" +#include "MyPawn.h" +#include "MyPlayerStart.h" #include "GameFramework/GameMode.h" #include "MyGameMode.generated.h" @@ -13,14 +17,19 @@ UCLASS() class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode { GENERATED_BODY() - + public: AMyGameMode(); void BeginPlay() override; + AActor *ChoosePlayerStart(AController * Player); private: void StartGame(); + void InitializeSpawnPointsIfNeeded(); + AMyPlayerController *GetPlayerController(); + + TMap SpawnPoints; }; diff --git a/Source/TurnBasedTutorial/MyGameState.cpp b/Source/TurnBasedTutorial/MyGameState.cpp new file mode 100644 index 0000000..83327fd --- /dev/null +++ b/Source/TurnBasedTutorial/MyGameState.cpp @@ -0,0 +1,8 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "MyGameState.h" + + + + diff --git a/Source/TurnBasedTutorial/MyGameState.h b/Source/TurnBasedTutorial/MyGameState.h new file mode 100644 index 0000000..20280f0 --- /dev/null +++ b/Source/TurnBasedTutorial/MyGameState.h @@ -0,0 +1,20 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameState.h" +#include "MyGameState.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API AMyGameState : public AGameState +{ + GENERATED_BODY() + + + + +}; diff --git a/Source/TurnBasedTutorial/MyPawn.cpp b/Source/TurnBasedTutorial/MyPawn.cpp new file mode 100644 index 0000000..640053e --- /dev/null +++ b/Source/TurnBasedTutorial/MyPawn.cpp @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "MyPawn.h" + + +// Sets default values +AMyPawn::AMyPawn() +{ + // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; + +} + +// Called when the game starts or when spawned +void AMyPawn::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AMyPawn::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +// Called to bind functionality to input +void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + +} + diff --git a/Source/TurnBasedTutorial/MyPawn.h b/Source/TurnBasedTutorial/MyPawn.h new file mode 100644 index 0000000..40953df --- /dev/null +++ b/Source/TurnBasedTutorial/MyPawn.h @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Pawn.h" +#include "MyPawn.generated.h" + +UCLASS() +class TURNBASEDTUTORIAL_API AMyPawn : public APawn +{ + GENERATED_BODY() + +public: + // Sets default values for this pawn's properties + AMyPawn(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + // Called to bind functionality to input + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + + + +}; diff --git a/Source/TurnBasedTutorial/MyPlayerStart.cpp b/Source/TurnBasedTutorial/MyPlayerStart.cpp new file mode 100644 index 0000000..1d6c5c8 --- /dev/null +++ b/Source/TurnBasedTutorial/MyPlayerStart.cpp @@ -0,0 +1,10 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "MyPlayerStart.h" + +uint8 AMyPlayerStart::GetPlayerIndex() const { + return PlayerIndex; +} + + diff --git a/Source/TurnBasedTutorial/MyPlayerStart.h b/Source/TurnBasedTutorial/MyPlayerStart.h new file mode 100644 index 0000000..297594a --- /dev/null +++ b/Source/TurnBasedTutorial/MyPlayerStart.h @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerStart.h" +#include "MyPlayerStart.generated.h" + +/** + * + */ +UCLASS() +class TURNBASEDTUTORIAL_API AMyPlayerStart : public APlayerStart +{ + GENERATED_BODY() +public: + + uint8 GetPlayerIndex() const; + +protected: +private: + UPROPERTY(EditAnywhere, Category="Spawn Info") + uint8 PlayerIndex=0; +};