Minor - Change le comportement du mille-pattes - V2.2.0
Améliore la logique de collision du mille-pattes avec les bords et les champignons. Le mille-pattes change de direction lorsqu'il atteint les limites de la zone de jeu ou rencontre un champignon.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#include "M4_CentipedeController.h"
|
#include "M4_CentipedeController.h"
|
||||||
#include "M4_LOG.h"
|
#include "M4_LOG.h"
|
||||||
#include "M4_Gamemode.h"
|
#include "M4_Gamemode.h"
|
||||||
|
#include "M4_Mushroom.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
UM4_CentipedeController::UM4_CentipedeController()
|
UM4_CentipedeController::UM4_CentipedeController()
|
||||||
{
|
{
|
||||||
@@ -143,9 +145,9 @@ void UM4_CentipedeController::Tick(float DeltaTime)
|
|||||||
FVector CurrentPos = Head->GetActorLocation();
|
FVector CurrentPos = Head->GetActorLocation();
|
||||||
FVector2D SegmentDirection = GetSegmentDirection(Head);
|
FVector2D SegmentDirection = GetSegmentDirection(Head);
|
||||||
|
|
||||||
bool bShouldDescend = CheckCollision(Head, SegmentDirection);
|
bool bRowChanged = CheckCollision(Head, SegmentDirection);
|
||||||
|
|
||||||
if (bShouldDescend)
|
if (bRowChanged)
|
||||||
{
|
{
|
||||||
FVector NewPos = CurrentPos - FVector(0.f, 0.f, CellSize);
|
FVector NewPos = CurrentPos - FVector(0.f, 0.f, CellSize);
|
||||||
Head->SetActorLocation(NewPos);
|
Head->SetActorLocation(NewPos);
|
||||||
@@ -204,11 +206,53 @@ bool UM4_CentipedeController::CheckCollision(AM4_CentipedeBody* Segment, FVector
|
|||||||
|
|
||||||
const float LeftBound = GM->MushroomSpawnBounds.Min.Y;
|
const float LeftBound = GM->MushroomSpawnBounds.Min.Y;
|
||||||
const float RightBound = GM->MushroomSpawnBounds.Max.Y;
|
const float RightBound = GM->MushroomSpawnBounds.Max.Y;
|
||||||
|
const float MinRows = GM->MushroomSpawnBounds.Min.X;
|
||||||
|
const float MaxRows = GM->MushroomSpawnBounds.Max.X;
|
||||||
|
|
||||||
if (NextPos.Y <= LeftBound || NextPos.Y >= RightBound)
|
if (NextPos.Y <= LeftBound || NextPos.Y >= RightBound)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CurrentPos.Z > MinRows && NextPos.Z <= MinRows)
|
||||||
|
{
|
||||||
|
// On inverse la direction de descente pour remonter
|
||||||
|
FVector2D CurrentDirection = GetSegmentDirection(Segment);
|
||||||
|
CurrentDirection.Y *= -1.f;
|
||||||
|
SetSegmentDirection(Segment, CurrentDirection);
|
||||||
|
return true; // Collision détectée, le centipede descendra à la prochaine itération
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérification si on atteint la limite haute
|
||||||
|
if (CurrentPos.Z < MaxRows && NextPos.Z >= MaxRows)
|
||||||
|
{
|
||||||
|
// On inverse la direction de montée pour descendre
|
||||||
|
FVector2D CurrentDirection = GetSegmentDirection(Segment);
|
||||||
|
CurrentDirection.Y *= -1.f;
|
||||||
|
SetSegmentDirection(Segment, CurrentDirection);
|
||||||
|
return true; // Collision détectée, le centipede remontera à la prochaine itération
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 NextGridZ = FMath::RoundToInt(NextPos.Z / CellSize);
|
||||||
|
int32 NextGridY = FMath::RoundToInt(NextPos.Y / CellSize);
|
||||||
|
|
||||||
|
TArray<AActor*> FoundMushrooms;
|
||||||
|
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AM4_Mushroom::StaticClass(), FoundMushrooms);
|
||||||
|
|
||||||
|
for (AActor* Actor : FoundMushrooms)
|
||||||
|
{
|
||||||
|
FVector MushroomPos = Actor->GetActorLocation();
|
||||||
|
|
||||||
|
// Conversion de la position du mushroom en coordonnées de grille (Z, Y)
|
||||||
|
int32 MushroomGridZ = FMath::RoundToInt(MushroomPos.Z / CellSize);
|
||||||
|
int32 MushroomGridY = FMath::RoundToInt(MushroomPos.Y / CellSize);
|
||||||
|
|
||||||
|
// Vérification si c'est la même cellule de grille
|
||||||
|
if (NextGridZ == MushroomGridZ && NextGridY == MushroomGridY)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user