initial commit

This commit is contained in:
Maximilian Fajnberg 2022-01-11 11:07:17 +01:00
commit 7f4fd950df
21 changed files with 771 additions and 0 deletions

150
AdventureCameraPawn.cpp Normal file
View File

@ -0,0 +1,150 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AdventureCameraPawn.h"
#include "AdventureMap.h"
#include "AdventurePlayerController.h"
#include "AdventureCharacter.h"
#include "GameFramework/PlayerController.h"
#include "Kismet/GameplayStatics.h"
#include "math.h"
// Sets default values
AAdventureCameraPawn::AAdventureCameraPawn()
{
// 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;
ESASize = .01;
BaseScrollSpeed = 15;
ScrollAccelleration = BaseScrollSpeed * 2;
ESAMaxBoundSlope = 1 / (1 - (1-ESASize));
ESAMaxBoundIntercept = 1 - ESAMaxBoundSlope;
ESAMinBoundSlope = -1 / ESASize;
ESAMinBoundIntercept = 0 - (ESAMinBoundSlope * ESASize);
}
// Called when the game starts or when spawned
void AAdventureCameraPawn::BeginPlay()
{
Super::BeginPlay();
ControllerRef = (AAdventurePlayerController*)UGameplayStatics::GetPlayerController(GetWorld(), 0);
Viewport = GetWorld()->GetGameViewport();
ViewSize = Viewport->Viewport->GetSizeXY();
}
// Called every frame
void AAdventureCameraPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AAdventureCameraPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
if (PlayerInputComponent)
{
PlayerInputComponent->BindAxis("Mouse X", this, &AAdventureCameraPawn::EdgeScrollSide);
PlayerInputComponent->BindAxis("Mouse Y", this, &AAdventureCameraPawn::EdgeScrollVert);
}
}
void AAdventureCameraPawn::EdgeScrollSide(float AxisValue)
{
float mouseX;
float mouseY;
ControllerRef->GetMousePosition(mouseX, mouseY);
float mousePosX = mouseX / ViewSize.X;
float VertAccelleration = GetInputAxisValue("Mouse Y") * (ScrollAccelleration * .75);
if (mousePosX <= ESASize) // if in LEFT area
{
////// Scroll LEFT with Vert Accelleration
float SpeedX = (mousePosX * ESAMinBoundSlope + ESAMinBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(VertAccelleration, -SpeedX, 0));
if (AxisValue < .0 && mousePosX <= .005) // if mouse moving LEFT and touching EDGE
{
////// Add LEFT accelleration
SpeedX = AxisValue * ScrollAccelleration;
AddActorLocalOffset(FVector(0, SpeedX, 0));
}
}
if (mousePosX >= 1-ESASize) // if in RIGHT area
{
////// Scroll RIGHT
float SpeedX = (mousePosX * ESAMaxBoundSlope + ESAMaxBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(VertAccelleration, SpeedX, 0));
if (AxisValue > .0 && mousePosX >= .995) // if mouse moving RIGHT and touching EDGE
{
////// Add RIGHT accelleration
SpeedX = AxisValue * ScrollAccelleration;
AddActorLocalOffset(FVector(0, SpeedX, 0));
}
}
}
void AAdventureCameraPawn::EdgeScrollVert(float AxisValue)
{
float mouseX;
float mouseY;
ControllerRef->GetMousePosition(mouseX, mouseY);
float mousePosY = mouseY / ViewSize.Y;
float SideAccelleration = GetInputAxisValue("Mouse X") * (ScrollAccelleration * .75);
if (mousePosY <= ESASize) // if in TOP area
{
////// Scroll TOP
float SpeedY = (mousePosY * ESAMinBoundSlope + ESAMinBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(SpeedY, SideAccelleration, 0));
if (AxisValue > .0 && mousePosY <= .005) // if mouse moving TOP and touching EDGE
{
////// Add TOP accelleration
SpeedY = AxisValue * ScrollAccelleration;
AddActorLocalOffset(FVector(SpeedY, 0, 0));
}
}
if (mousePosY >= 1-ESASize) // if in BOTTOM area
{
////// Scroll BOTTOM
float SpeedY = (mousePosY * ESAMaxBoundSlope + ESAMaxBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(-SpeedY, SideAccelleration, 0));
if (AxisValue < .0 && mousePosY >= .995) // if mouse moving BOTTOM and touching EDGE
{
////// add BOTTOM accelleration
SpeedY = AxisValue * ScrollAccelleration;
AddActorLocalOffset(FVector(SpeedY, 0, 0));
}
}
}
void AAdventureCameraPawn::FollowAdvPawn()
{
UE_LOG(LogTemp, Warning, TEXT("following..."));
AdvPawnLocationCurrent = AdvPawnRef->GetActorLocation();
AdvPawnLocationDelta = AdvPawnLocationCurrent - AdvPawnLocationPrevious;
UE_LOG(LogTemp, Warning, TEXT("%s"), *AdvPawnLocationDelta.ToString());
AddActorLocalOffset(AdvPawnLocationDelta);
AdvPawnLocationPrevious = AdvPawnLocationCurrent;
}

75
AdventureCameraPawn.h Normal file
View File

@ -0,0 +1,75 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "AdventureCameraPawn.generated.h"
UCLASS()
class FRAY_API AAdventureCameraPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AAdventureCameraPawn();
UPROPERTY()
UGameViewportClient* Viewport;
UPROPERTY()
FIntPoint ViewSize;
UPROPERTY(BlueprintReadWrite, Category = "Config")
class AAdventureMap* AdvMapRef;
UPROPERTY(BlueprintReadWrite, Category = "Config")
class AAdventurePlayerController* ControllerRef;
UPROPERTY(BlueprintReadWrite, Category = "Config")
class AAdventureCharacter* AdvPawnRef;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
float ESASize;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
float ScrollAccelleration;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
float BaseScrollSpeed;
UPROPERTY()
FVector AdvPawnLocationPrevious;
UPROPERTY()
FVector AdvPawnLocationCurrent;
UPROPERTY()
FVector AdvPawnLocationDelta;
UPROPERTY(BlueprintReadWrite, Category = "Runtime")
bool bAdvPawnIsMoving;
UPROPERTY(BlueprintReadWrite, Category = "Runtime")
class AHexTile* SelectedHex;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
float ESAMaxBoundSlope;
float ESAMaxBoundIntercept;
float ESAMinBoundSlope;
float ESAMinBoundIntercept;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION(BlueprintCallable)
void EdgeScrollSide(float AxisValue);
UFUNCTION(BlueprintCallable)
void EdgeScrollVert(float AxisValue);
UFUNCTION(BlueprintCallable)
void FollowAdvPawn();
};

34
AdventureCharacter.cpp Normal file
View File

@ -0,0 +1,34 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AdventureCharacter.h"
// Sets default values
AAdventureCharacter::AAdventureCharacter()
{
// Set this character 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 AAdventureCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AAdventureCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AAdventureCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}

29
AdventureCharacter.h Normal file
View File

@ -0,0 +1,29 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "AdventureCharacter.generated.h"
UCLASS()
class FRAY_API AAdventureCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AAdventureCharacter();
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;
};

88
AdventureMap.cpp Normal file
View File

@ -0,0 +1,88 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AdventureMap.h"
#include "HexTile.h"
#include "AdventureCameraPawn.h"
#include "AdventureCharacter.h"
#include "Kismet/GameplayStatics.h"
// Sets default values
AAdventureMap::AAdventureMap()
{
}
// Called when the game starts or when spawned
void AAdventureMap::BeginPlay()
{
Super::BeginPlay();
UWorld* World = GetWorld();
if (IsValid(BaseTileClass))
{
MakeGrid();
}
}
// Every Hex Tile's index within the Grid Array can be derived from its Q and R coordinates
int32 AAdventureMap::GridIndex(int32 qAxial, int32 rAxial)
{
/*
* The Q axis is (i.e. columns are) oriented diagonally.
* The Hex Grid has a rough square shape, hence the Q coordinates must be offset by -1 every other row.
*/
int32 column = qAxial + FMath::FloorToInt(rAxial / 2);
return (rAxial * GridSize) + column;
}
// Called once on Begin Play
void AAdventureMap::MakeGrid()
{
UWorld* World = GetWorld();
FVector NextHexAt = FVector();
float HexWidth = sqrt(3) * TileSize;
int QOffset = 0;
for (int r = 1; r <= GridSize; r++)
{
float XOffset = 0.f;
if (r % 2 != 0)
{
if (r > 1)
{
QOffset--; // The Q axis is (i.e. columns are) oriented diagonally.
}
}
else
{
XOffset = HexWidth / 2;
}
for (int q = 1; q <= GridSize; q++)
{
NextHexAt.X = XOffset + (HexWidth * q);
NextHexAt.Y = TileSize * 1.5f * r;
NextHexAt.Z = 0.f;
FTransform SpawnTransform = FTransform(NextHexAt);
AHexTile* Tile = World->SpawnActor<AHexTile>(BaseTileClass, SpawnTransform);
Tile->Q = q - 1 + QOffset;
Tile->R = r - 1;
Grid.Add(Tile);
}
}
for (auto& tile : Grid)
{
tile->Index = GridIndex(tile->Q, tile->R);
}
}
AHexTile* AAdventureMap::RandomHex()
{
int32 SpawnHex = GridIndex(FMath::RandRange(0, GridSize), FMath::RandRange(0, GridSize));
return Grid[SpawnHex];
}

51
AdventureMap.h Normal file
View File

@ -0,0 +1,51 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "AdventureMap.generated.h"
class AHexTile;
class AAdventureCharacter;
UCLASS()
class FRAY_API AAdventureMap : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AAdventureMap();
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
TSubclassOf<AHexTile> BaseTileClass;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
TSubclassOf<ACharacter> BasePartyCharacterClass;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Config")
int32 GridSize = 100; // squared is the number of Tiles
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Config")
int32 TileSize = 100;
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "MapData")
TArray<AHexTile*> Grid;
UFUNCTION(BlueprintCallable)
int32 GridIndex(int32 q, int32 r);
// Player spawn section
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
APawn* CameraPawn;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
AAdventureCharacter* PlayerCharacter;
UFUNCTION(BlueprintCallable)
void MakeGrid();
UFUNCTION(BlueprintCallable)
AHexTile* RandomHex();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};

View File

@ -0,0 +1,16 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AdventurePlayerController.h"
#include "AdventureMap.h"
#include "HexTile.h"
#include "AdventureCameraPawn.h"
#include "AdventureCharacter.h"
AAdventurePlayerController::AAdventurePlayerController()
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
}

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "AdventurePlayerController.generated.h"
class AAdventureMap;
class AHexTile;
class AAdventureCameraPawn;
class AAdventureCharacter;
/**
*
*/
UCLASS()
class FRAY_API AAdventurePlayerController : public APlayerController
{
GENERATED_BODY()
public:
AAdventurePlayerController();
public:
};

34
Clickable.cpp Normal file
View File

@ -0,0 +1,34 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Clickable.h"
// Sets default values for this component's properties
UClickable::UClickable()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UClickable::BeginPlay()
{
Super::BeginPlay();
// ...
}
// Called every frame
void UClickable::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}

28
Clickable.h Normal file
View File

@ -0,0 +1,28 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Clickable.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class FRAY_API UClickable : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UClickable();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};

23
FRAY.Build.cs Normal file
View File

@ -0,0 +1,23 @@
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class FRAY : ModuleRules
{
public FRAY(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}

14
FRAY.Target.cs Normal file
View File

@ -0,0 +1,14 @@
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System.Collections.Generic;
public class FRAYTarget : TargetRules
{
public FRAYTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "FRAY" } );
}
}

6
FRAY.cpp Normal file
View File

@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "FRAY.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, FRAY, "FRAY" );

6
FRAY.h Normal file
View File

@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"

14
FRAYEditor.Target.cs Normal file
View File

@ -0,0 +1,14 @@
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System.Collections.Generic;
public class FRAYEditorTarget : TargetRules
{
public FRAYEditorTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "FRAY" } );
}
}

5
FRAYGameModeBase.cpp Normal file
View File

@ -0,0 +1,5 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "FRAYGameModeBase.h"

17
FRAYGameModeBase.h Normal file
View File

@ -0,0 +1,17 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "FRAYGameModeBase.generated.h"
/**
*
*/
UCLASS()
class FRAY_API AFRAYGameModeBase : public AGameModeBase
{
GENERATED_BODY()
};

44
HexTile.cpp Normal file
View File

@ -0,0 +1,44 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "HexTile.h"
#include "AdventurePlayerController.h"
#include "Kismet/KismetMathLibrary.h"
// Sets default values
AHexTile::AHexTile()
{
TileSize = 100.f;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Scene"));
this->FillCornersArray();
// OnClicked.AddDynamic(this, )
}
void AHexTile::BeginPlay()
{
Super::BeginPlay();
}
FVector AHexTile::Corner(int32 i)
{
FVector TileCenter = this->GetActorTransform().GetLocation();
int32 Angle_Deg = 60 * i - 30;
float Angle_Rad = UKismetMathLibrary::GetPI()/180 * Angle_Deg;
float X = TileCenter.X + TileSize * cos(Angle_Rad);
float Y = TileCenter.Y + TileSize * sin(Angle_Rad);
return FVector(X, Y, 0.f);
}
void AHexTile::FillCornersArray()
{
for (int32 i = 0 ; i < 6; i++)
{
Corners.Emplace(Corner(i + 1));
}
}

48
HexTile.h Normal file
View File

@ -0,0 +1,48 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "HexTile.generated.h"
class USceneComponent;
class UStaticMeshComponent;
class AAdventurePlayerController;
UCLASS()
class FRAY_API AHexTile : public AActor
{
GENERATED_BODY()
public:
// Sets default value for this actor's properties
AHexTile();
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
float TileSize;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
USceneComponent* SceneComponent;
UFUNCTION(BlueprintCallable)
FVector Corner(int32 i);
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
TArray<FVector> Corners;
UFUNCTION()
void FillCornersArray();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
int32 Q;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
int32 R;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
int32 Index;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};

28
WalkAnimInstance.cpp Normal file
View File

@ -0,0 +1,28 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "WalkAnimInstance.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/PawnMovementComponent.h"
void UWalkAnimInstance::NativeInitializeAnimation()
{
if (Pawn == nullptr)
{
Pawn = TryGetPawnOwner();
}
if (IsValid(Pawn))
{
MovementComponent = Pawn->GetMovementComponent();
}
}
void UWalkAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
if (Pawn && MovementComponent)
{
Speed = Pawn->GetVelocity().Size();
}
}

34
WalkAnimInstance.h Normal file
View File

@ -0,0 +1,34 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Animation/AnimInstance.h"
#include "WalkAnimInstance.generated.h"
class APawn;
class UPawnMovementComponent;
/**
*
*/
UCLASS()
class FRAY_API UWalkAnimInstance : public UAnimInstance
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Movement")
float Speed;
UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = "Movement")
APawn* Pawn;
UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = "Movement")
UPawnMovementComponent* MovementComponent;
virtual void NativeInitializeAnimation() override;
virtual void NativeUpdateAnimation(float DeltaSeconds) override;
};