Initial UE commit

This commit is contained in:
abouteiller
2025-07-15 16:48:22 +02:00
parent 89fdd9f0cc
commit 1e157b6876
199 changed files with 806 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "LevelManager.h"
// Sets default values
ALevelManager::ALevelManager()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
}
// Called when the game starts or when spawned
void ALevelManager::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ALevelManager::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "LevelManager.generated.h"
class AActor;
UCLASS()
class TUTOBEGGINER_API ALevelManager : public AActor
{
GENERATED_BODY()
public:
UPROPERTY( EditAnywhere, BlueprintReadWrite )
AActor* Spline;
// Sets default values for this actor's properties
ALevelManager();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};

View File

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyGameModeBase.h"
AMyGameModeBase::AMyGameModeBase()
{
PrimaryActorTick.bCanEverTick = true;
}
void AMyGameModeBase::Tick( float DeltaTime )
{
TotalTime += DeltaTime;
}
void AMyGameModeBase::GameOver()
{
UE_LOG( LogTemp, Warning, TEXT( "Death" ) );
}

View File

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "Components/TextBlock.h"
#include "Blueprint/UserWidget.h"
#include "MyGameModeBase.generated.h"
class UTextBlock;
/**
*
*/
UCLASS()
class TUTOBEGGINER_API AMyGameModeBase : public AGameModeBase
{
GENERATED_BODY()
AMyGameModeBase();
virtual void Tick( float DeltaTime ) override;
public:
void GameOver();
float GetTimer(){ return TotalTime; };
private:
float TotalTime = 0.f;
};

View File

@ -0,0 +1,24 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Plate.h"
// Sets default values
APlate::APlate()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>( "Mesh" );
RootComponent = Mesh;
Mesh->SetSimulatePhysics( true );
}
// Called when the game starts or when spawned
void APlate::BeginPlay()
{
Super::BeginPlay();
}

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/Actor.h"
#include "Plate.generated.h"
UCLASS()
class TUTOBEGGINER_API APlate : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
APlate();
protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
UStaticMeshComponent* Mesh;
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
};

View File

@ -0,0 +1,143 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "RollaBallPlayer.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "../../../../Plugins/EnhancedInput/Source/EnhancedInput/Public/EnhancedInputComponent.h"
#include "Delegates/Delegate.h"
#include "Components/SphereComponent.h"
#include "RollaBallWidget.h"
#include "Components/SplineComponent.h"
#include "LevelManager.h"
#include "EngineUtils.h"
// Sets default values
ARollaBallPlayer::ARollaBallPlayer()
{
// 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;
Mesh=CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
SpringArm =CreateDefaultSubobject<USpringArmComponent>("SpringArm");
Camera =CreateDefaultSubobject<UCameraComponent>("Camera");
Sphere = CreateDefaultSubobject<USphereComponent>( "Sphere" );
SphereTrigger = CreateDefaultSubobject<USphereComponent>( "SphereTrigger" );
RootComponent = Sphere;
Mesh->SetupAttachment( Sphere );
SphereTrigger->SetupAttachment( Sphere );
SpringArm->SetupAttachment( Sphere );
Camera->SetupAttachment( SpringArm );
Sphere->SetSimulatePhysics( true );
Sphere->SetNotifyRigidBodyCollision( true );
SphereTrigger->SetSimulatePhysics( false );
SphereTrigger->SetNotifyRigidBodyCollision( false );
SphereTrigger->SetGenerateOverlapEvents( true );
}
// Called when the game starts or when spawned
void ARollaBallPlayer::BeginPlay()
{
Super::BeginPlay();
MoveForce *= Sphere->GetMass();
JumpImpulse *= Sphere->GetMass();
SphereTrigger->SetSphereRadius( Sphere->GetScaledSphereRadius() + 0.05f * Sphere->GetScaledSphereRadius() );
Sphere->OnComponentHit.AddDynamic( this, &ARollaBallPlayer::OnHittt );
SphereTrigger->OnComponentBeginOverlap.AddDynamic( this, &ARollaBallPlayer::OnEnterFloor );
SphereTrigger->OnComponentEndOverlap.AddDynamic( this, &ARollaBallPlayer::OnLeavingFloor );
GameManager = ( AMyGameModeBase* )GetWorld()->GetAuthGameMode();
for( TActorIterator<ALevelManager> It( GetWorld() ); It; ++It )
{
ALevelManager* itLevelManager = *It;
if( itLevelManager )
{
LevelManager = itLevelManager;
}
}
if( LevelManager )
{
Spline = (USplineComponent*) LevelManager->Spline->GetComponentByClass( USplineComponent::StaticClass() );
MaxSplineDistance = Spline->GetSplineLength();
}
// pWidgetRef = CreateWidget<URollaBallWidget>(GetWorld(), pWidget);
if( pWidgetRef )
pWidgetRef->AddToViewport();
}
void ARollaBallPlayer::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
float distance = Spline->GetDistanceAlongSplineAtLocation(this->GetActorLocation(), ESplineCoordinateSpace::World);
if( GameManager )
{
float NewTimer = GameManager->GetTimer();
if( pWidgetRef )
{
pWidgetRef->SetTimerText( NewTimer );
pWidgetRef->SetProgress( distance / MaxSplineDistance );
}
}
}
// Called to bind functionality to input
void ARollaBallPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>( PlayerInputComponent );
Input->BindAction( JumpAction, ETriggerEvent::Triggered, this, &ARollaBallPlayer::JumpFct );
Input->BindAction( MoveAction, ETriggerEvent::Triggered, this, &ARollaBallPlayer::MoveForward );
}
void ARollaBallPlayer::MoveForward( const FInputActionValue& Value )
{
if( bIsOnGround )
{
FVector moveValue = Value.Get<FVector>();
Sphere->AddForce( moveValue * MoveForce );
}
}
void ARollaBallPlayer::JumpFct( const FInputActionValue& Value )
{
if( JumpCount < MaxJumpCount )
{
JumpCount++;
Sphere->AddImpulse( FVector( 0, 0, JumpImpulse ) );
}
}
void ARollaBallPlayer::OnHittt( UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit )
{
JumpCount = 0;
if( OtherActor->ActorHasTag( "Trap" ) )
{
GameManager->GameOver();
}
}
void ARollaBallPlayer::OnLeavingFloor( UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex )
{
bIsOnGround = false;
}
void ARollaBallPlayer::OnEnterFloor( UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult )
{
bIsOnGround = true;
}

View File

@ -0,0 +1,99 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "../../../../Plugins/EnhancedInput/Source/EnhancedInput/Public/InputActionValue.h"
#include "Components/PrimitiveComponent.h"
#include "Engine/HitResult.h"
#include "MyGameModeBase.h"
#include "RollaBallPlayer.generated.h"
class USpringArmComponent;
class UCameraComponent;
class UInputAction;
class AActor;
class USphereComponent;
class URollaBallWidget;
class USplineComponent;
class ALevelManager;
UCLASS()
class TUTOBEGGINER_API ARollaBallPlayer : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ARollaBallPlayer();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
virtual void Tick( float DeltaSeconds ) override;
//Define Components
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
USphereComponent* Sphere;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
USphereComponent* SphereTrigger;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
UStaticMeshComponent* Mesh;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
USpringArmComponent* SpringArm;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
UCameraComponent* Camera;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components")
AMyGameModeBase* GameManager;
//VARIABLES
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float MoveForce= 500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float JumpImpulse = 500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 MaxJumpCount = 1;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 JumpCount = 0;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input)
UInputAction* JumpAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input)
UInputAction* MoveAction;
public:
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION()
void OnHittt( UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit );
UFUNCTION()
void OnLeavingFloor( UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex );
UFUNCTION()
void OnEnterFloor( UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult );
private:
//FUNCTIONS
void MoveRight( float value );
void MoveForward( const FInputActionValue& Value );
void JumpFct( const FInputActionValue& Value );
bool bIsOnGround = false;
UPROPERTY(EditAnywhere)
URollaBallWidget* pWidgetRef;
ALevelManager* LevelManager;
USplineComponent* Spline;
float Progress = 0.5f;
float MaxSplineDistance = 0.f;
};

View File

@ -0,0 +1,5 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "RollaBallWidget.h"

View File

@ -0,0 +1,24 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "RollaBallWidget.generated.h"
/**
*
*/
UCLASS()
class TUTOBEGGINER_API URollaBallWidget : public UUserWidget
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintImplementableEvent)
void SetTimerText( float Timestamp );
UFUNCTION(BlueprintImplementableEvent)
void SetProgress( float Progress );
};

View File

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "SplineNode.h"
// Sets default values
ASplineNode::ASplineNode()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
}
// Called when the game starts or when spawned
void ASplineNode::BeginPlay()
{
Super::BeginPlay();
}

View File

@ -0,0 +1,42 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "SplineNode.generated.h"
class USplineComponent;
const uint8 bClassic = 0b00;
const uint8 bInverted = 0b01;
const uint8 bDualSens = 0b10;
class SplineHolder
{
SplineHolder()
{
Spline = nullptr;
Direction = bDualSens;
}
USplineComponent* Spline;
uint8 Direction : 3;
};
UCLASS()
class TUTOBEGGINER_API ASplineNode : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ASplineNode();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
TArray<SplineHolder> Splines;
};