Merge branch 'main' into Bullet

This commit is contained in:
NisemonoQ
2025-10-17 00:17:22 +02:00
6 changed files with 156 additions and 1 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
UnrealToolbox.exe filter=lfs diff=lfs merge=lfs -text

Binary file not shown.

View File

@@ -1,6 +1,7 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "M4_Gamemode.h"
#include "M4_Mushroom.h"
#include "M4_PlayerController.h"
#include "M4_PlayerPawn.h"
@@ -11,10 +12,53 @@ AM4_Gamemode::AM4_Gamemode()
PlayerControllerClass = AM4_PlayerController::StaticClass();
DefaultPawnClass = AM4_PlayerPawn::StaticClass();
MushroomCount = FMath::RandRange(20, 25);
}
void AM4_Gamemode::BeginPlay()
{
Super::BeginPlay();
}
Score = 0;
Lives = 3;
// Get mushroom size from the class
AM4_Mushroom* TempMushroom = GetWorld()->SpawnActor<AM4_Mushroom>(AM4_Mushroom::StaticClass());
if (TempMushroom)
{
FVector MushroomSize = TempMushroom->GetStaticMeshComponent()->Bounds.BoxExtent * 2.0f;
CellSize = FMath::Max(MushroomSize.Y, MushroomSize.Z); // Use largest dimension
TempMushroom->Destroy();
}
// Calculate grid dimensions based on cell size
const int32 GridRows = FMath::FloorToInt(MushroomSpawnBounds.GetSize().X / CellSize);
const int32 GridCols = FMath::FloorToInt(MushroomSpawnBounds.GetSize().Y / CellSize);
// spawn mushrooms in a grid inside the spawn bounds and in random cell
if (MushroomCount > 0)
{
TSet<FIntPoint> OccupiedCells;
for (int32 i = 0; i < MushroomCount; ++i)
{
FIntPoint Cell;
do
{
Cell.X = FMath::RandRange(0, GridRows - 1);
Cell.Y = FMath::RandRange(0, GridCols - 1);
} while (OccupiedCells.Contains(Cell));
OccupiedCells.Add(Cell);
FVector SpawnLocation;
SpawnLocation.Z = MushroomSpawnBounds.Min.X + Cell.X * CellSize + CellSize / 2.0f;
SpawnLocation.Y = MushroomSpawnBounds.Min.Y + Cell.Y * CellSize + CellSize / 2.0f;
SpawnLocation.X = -400.0f;
GetWorld()->SpawnActor<AM4_Mushroom>(AM4_Mushroom::StaticClass(), SpawnLocation, FRotator::ZeroRotator);
}
}
}

View File

@@ -0,0 +1,42 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "M4_Mushroom.h"
#include "M4_CTP_Macros.h"
#include "Kismet/GameplayStatics.h"
#include "M4_Gamemode.h"
// Sets default values
AM4_Mushroom::AM4_Mushroom()
{
// 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;
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshRef(TEXT("/Game/CTP/04_Mesh/SM_Cube.SM_Cube"));
if (StaticMeshRef.Succeeded())
{
GetStaticMeshComponent()->SetStaticMesh(StaticMeshRef.Object);
}
GetStaticMeshComponent()->SetDefaultCustomPrimitiveDataVector4(0, FVector4(0.0, 0.2, 0.2, 1.0));
GetStaticMeshComponent()->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
GetStaticMeshComponent()->SetGenerateOverlapEvents(true);
// Set as static object
GetStaticMeshComponent()->SetMobility(EComponentMobility::Static);
// Set scale
const FVector2D MushroomScale = FVector2D(0.3f, 0.25f);
GetStaticMeshComponent()->SetRelativeScale3D(FVector(1.f, 0.45f, 0.20f));
// Custom preset for more advanced collision configuration
GetStaticMeshComponent()->SetCollisionProfileName(UCollisionProfile::CustomCollisionProfileName);
GetStaticMeshComponent()->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
}
void AM4_Mushroom::BeginPlay()
{
Super::BeginPlay();
}

View File

@@ -20,6 +20,53 @@ public:
virtual void BeginPlay() override;
/**
* The movement bounds for the player pawn
*/
UPROPERTY(EditAnywhere)
FBox2D Bounds = FBox2D(FVector2D(-400.0f, -750.0f), FVector2D(-200.0f, 750.0f));
/**
* Bounds for spawning mushrooms
*/
UPROPERTY(EditAnywhere)
FBox2D MushroomSpawnBounds = FBox2D(FVector2D(-300.0f, -750.0f), FVector2D(550.0f, 750.0f));
/**
* Add to the player's score
* @param Amount
*/
UFUNCTION(BlueprintCallable)
void AddScore(int Amount) { Score += Amount; }
/**
* Get the player's current score
* @return Current score
*/
UFUNCTION(BlueprintCallable)
int GetScore() const { return Score; }
/**
* Decrease the player's lives by 1, but not below 0
*/
UFUNCTION(BlueprintCallable)
void LoseLife() { Lives = FMath::Max(0, Lives - 1); }
/**
* Get the player's current lives
* @return Current lives
*/
UFUNCTION(BlueprintCallable)
int GetLives() const { return Lives; }
private:
int Score = 0;
int Lives = 3;
// default mushroom count
int MushroomCount;
float CellSize = 50.f;
};

View File

@@ -0,0 +1,21 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/StaticMeshActor.h"
#include "GameFramework/Pawn.h"
#include "M4_Mushroom.generated.h"
UCLASS()
class M4_CPP_API AM4_Mushroom : public AStaticMeshActor
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AM4_Mushroom();
protected:
virtual void BeginPlay() override;
};