Minor - Gère la mort des segments - V3.4.0

Modifie la logique de destruction des segments de centipède.

Au lieu de détruire immédiatement le segment, désactive la collision et le rend invisible. Des champignons sont générés à l'endroit de sa mort et le score du joueur est augmenté.

L'événement OnSegmentDestroyed est renommé en OnSegmentHit pour refléter la nouvelle logique.
This commit is contained in:
2025-11-05 14:19:08 +01:00
parent 469451e491
commit 0da3851dde
4 changed files with 68 additions and 25 deletions

View File

@@ -103,6 +103,7 @@ ManualIPAddress=
[CoreRedirects]
+ClassRedirects=(OldName="/Script/M4_CPP.M4_CentipedeController",NewName="/Script/M4_CPP.M4_CentipedeController")
+FunctionRedirects=(OldName="/Script/M4_CPP.M4_CentipedeController.OnSegmentDestroyed",NewName="/Script/M4_CPP.M4_CentipedeController.OnSegmentHit")
[/Script/Engine.CollisionProfile]
-Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision",bCanModify=False)

View File

@@ -90,11 +90,11 @@ TStatId UM4_CentipedeController::GetStatId() const
void UM4_CentipedeController::SpawnCentipede()
{
AM4_Gamemode* GM = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
if (!GM) return;
GM_REF_PTR = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
if (!GM_REF_PTR) return;
FVector SpawnLocation = FVector(
GM->MushroomSpawnBounds.Max.X,
GM_REF_PTR->MushroomSpawnBounds.Max.X,
0.f,
0.f
);
@@ -201,13 +201,16 @@ bool UM4_CentipedeController::CheckCollision(AM4_CentipedeBody* Segment, FVector
FVector CurrentPos = Segment->GetActorLocation();
FVector NextPos = CurrentPos + FVector(0.f, Direction.Y * CellSize, 0.f);
AM4_Gamemode* GM = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
if (!GM) return false;
if (!GM_REF_PTR)
{
GM_REF_PTR = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
if (!GM_REF_PTR) return false;
}
const float LeftBound = GM->MushroomSpawnBounds.Min.Y;
const float RightBound = GM->MushroomSpawnBounds.Max.Y;
const float MinRows = GM->MushroomSpawnBounds.Min.X;
const float MaxRows = GM->MushroomSpawnBounds.Max.X;
const float LeftBound = GM_REF_PTR->MushroomSpawnBounds.Min.Y;
const float RightBound = GM_REF_PTR->MushroomSpawnBounds.Max.Y;
const float MinRows = GM_REF_PTR->MushroomSpawnBounds.Min.X;
const float MaxRows = GM_REF_PTR->MushroomSpawnBounds.Max.X;
if (NextPos.Y <= LeftBound || NextPos.Y >= RightBound)
{
@@ -290,7 +293,7 @@ void UM4_CentipedeController::UpdateHeadStatus()
}
}
void UM4_CentipedeController::OnSegmentDestroyed(AM4_CentipedeBody* DestroyedSegment)
void UM4_CentipedeController::OnSegmentHit(AM4_CentipedeBody* DestroyedSegment)
{
if (!DestroyedSegment) return;
@@ -312,7 +315,26 @@ void UM4_CentipedeController::OnSegmentDestroyed(AM4_CentipedeBody* DestroyedSeg
BodySegments[SegmentIndex - 1]->NextBody = nullptr;
}
BodySegments.RemoveAt(SegmentIndex);
SegmentHistory.RemoveAt(SegmentIndex);
SegmentDirections.Remove(DestroyedSegment);
// disable collision and hide the destroyed segment
DestroyedSegment->GetStaticMeshComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
DestroyedSegment->SetActorHiddenInGame(true);
// Increase player score
if (!GM_REF_PTR)
{
GM_REF_PTR = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
if (!GM_REF_PTR) return;
}
GM_REF_PTR->AddScore(100);
SpawnMushroomsAtSegmentDeathPos(DestroyedSegment->GetActorLocation());
}
void UM4_CentipedeController::SpawnMushroomsAtSegmentDeathPos(FVector Location)
{
FVector Offset = FVector(0.f, FMath::RandRange(-CellSize, CellSize), 0.f);
FVector SpawnLocation = Location + Offset;
GetWorld()->SpawnActor<AM4_Mushroom>(
AM4_Mushroom::StaticClass(),
SpawnLocation,
FRotator::ZeroRotator
);
}

View File

@@ -63,19 +63,35 @@ void AM4_Projectile::BeginPlay()
void AM4_Projectile::OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("Projectile OVERLAP: %s"), *OtherActor->GetName());
if (OtherActor && OtherActor != this && OtherComp != nullptr)
if (!OtherActor || OtherActor == this || !OtherComp)
{
AM4_Mushroom* Mushroom = Cast<AM4_Mushroom>(OtherActor);
if (Mushroom)
{
UE_LOG(LogTemp, Warning, TEXT("OVERLAP MUSHROOM!"));
FVector NormalImpulse = FVector::ZeroVector;
Mushroom->OnHit(OverlappedComponent, this, OtherComp, NormalImpulse, SweepResult);
Destroy();
}
return;
}
AM4_Mushroom* Mushroom = Cast<AM4_Mushroom>(OtherActor);
if (Mushroom)
{
UE_LOG(LogTemp, Warning, TEXT("OVERLAP MUSHROOM!"));
FVector NormalImpulse = FVector::ZeroVector;
Mushroom->OnHit(OverlappedComponent, this, OtherComp, NormalImpulse, SweepResult);
Destroy();
return;
}
AM4_CentipedeBody* CentipedeBody = Cast<AM4_CentipedeBody>(OtherActor);
if (CentipedeBody)
{
UE_LOG(LogTemp, Warning, TEXT("OVERLAP CENTIPEDE BODY!"));
UM4_CentipedeController* CentipedeController = GetWorld()->GetSubsystem<UM4_CentipedeController>();
if (CentipedeController)
{
CentipedeController->OnSegmentHit(CentipedeBody);
}
Destroy();
}
}
void AM4_Projectile::FireInDir(const FVector& ShootDir)

View File

@@ -31,7 +31,7 @@ public:
float MoveInterval = 0.1f;
UFUNCTION(BlueprintCallable, Category = "Centipede")
void OnSegmentDestroyed(AM4_CentipedeBody* DestroyedSegment);
void OnSegmentHit(AM4_CentipedeBody* DestroyedSegment);
private:
UPROPERTY()
@@ -52,9 +52,13 @@ private:
void SpawnCentipede();
void UpdateHeadStatus();
void SpawnMushroomsAtSegmentDeathPos(FVector Location);
bool CheckCollision(AM4_CentipedeBody* Segment, FVector2D Direction);
FVector2D GetSegmentDirection(AM4_CentipedeBody* Segment);
void SetSegmentDirection(AM4_CentipedeBody* Segment, FVector2D Direction);
UPROPERTY()
class AM4_Gamemode* GM_REF_PTR;
};