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:
@@ -103,6 +103,7 @@ ManualIPAddress=
|
|||||||
|
|
||||||
[CoreRedirects]
|
[CoreRedirects]
|
||||||
+ClassRedirects=(OldName="/Script/M4_CPP.M4_CentipedeController",NewName="/Script/M4_CPP.M4_CentipedeController")
|
+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]
|
[/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)
|
-Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision",bCanModify=False)
|
||||||
|
|||||||
@@ -90,11 +90,11 @@ TStatId UM4_CentipedeController::GetStatId() const
|
|||||||
|
|
||||||
void UM4_CentipedeController::SpawnCentipede()
|
void UM4_CentipedeController::SpawnCentipede()
|
||||||
{
|
{
|
||||||
AM4_Gamemode* GM = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
|
GM_REF_PTR = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
|
||||||
if (!GM) return;
|
if (!GM_REF_PTR) return;
|
||||||
|
|
||||||
FVector SpawnLocation = FVector(
|
FVector SpawnLocation = FVector(
|
||||||
GM->MushroomSpawnBounds.Max.X,
|
GM_REF_PTR->MushroomSpawnBounds.Max.X,
|
||||||
0.f,
|
0.f,
|
||||||
0.f
|
0.f
|
||||||
);
|
);
|
||||||
@@ -201,13 +201,16 @@ bool UM4_CentipedeController::CheckCollision(AM4_CentipedeBody* Segment, FVector
|
|||||||
FVector CurrentPos = Segment->GetActorLocation();
|
FVector CurrentPos = Segment->GetActorLocation();
|
||||||
FVector NextPos = CurrentPos + FVector(0.f, Direction.Y * CellSize, 0.f);
|
FVector NextPos = CurrentPos + FVector(0.f, Direction.Y * CellSize, 0.f);
|
||||||
|
|
||||||
AM4_Gamemode* GM = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
|
if (!GM_REF_PTR)
|
||||||
if (!GM) return false;
|
{
|
||||||
|
GM_REF_PTR = Cast<AM4_Gamemode>(GetWorld()->GetAuthGameMode());
|
||||||
|
if (!GM_REF_PTR) return false;
|
||||||
|
}
|
||||||
|
|
||||||
const float LeftBound = GM->MushroomSpawnBounds.Min.Y;
|
const float LeftBound = GM_REF_PTR->MushroomSpawnBounds.Min.Y;
|
||||||
const float RightBound = GM->MushroomSpawnBounds.Max.Y;
|
const float RightBound = GM_REF_PTR->MushroomSpawnBounds.Max.Y;
|
||||||
const float MinRows = GM->MushroomSpawnBounds.Min.X;
|
const float MinRows = GM_REF_PTR->MushroomSpawnBounds.Min.X;
|
||||||
const float MaxRows = GM->MushroomSpawnBounds.Max.X;
|
const float MaxRows = GM_REF_PTR->MushroomSpawnBounds.Max.X;
|
||||||
|
|
||||||
if (NextPos.Y <= LeftBound || NextPos.Y >= RightBound)
|
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;
|
if (!DestroyedSegment) return;
|
||||||
|
|
||||||
@@ -312,7 +315,26 @@ void UM4_CentipedeController::OnSegmentDestroyed(AM4_CentipedeBody* DestroyedSeg
|
|||||||
BodySegments[SegmentIndex - 1]->NextBody = nullptr;
|
BodySegments[SegmentIndex - 1]->NextBody = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
BodySegments.RemoveAt(SegmentIndex);
|
// disable collision and hide the destroyed segment
|
||||||
SegmentHistory.RemoveAt(SegmentIndex);
|
DestroyedSegment->GetStaticMeshComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
SegmentDirections.Remove(DestroyedSegment);
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -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)
|
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());
|
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);
|
return;
|
||||||
if (Mushroom)
|
|
||||||
{
|
|
||||||
UE_LOG(LogTemp, Warning, TEXT("OVERLAP MUSHROOM!"));
|
|
||||||
|
|
||||||
FVector NormalImpulse = FVector::ZeroVector;
|
|
||||||
Mushroom->OnHit(OverlappedComponent, this, OtherComp, NormalImpulse, SweepResult);
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
void AM4_Projectile::FireInDir(const FVector& ShootDir)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
float MoveInterval = 0.1f;
|
float MoveInterval = 0.1f;
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Centipede")
|
UFUNCTION(BlueprintCallable, Category = "Centipede")
|
||||||
void OnSegmentDestroyed(AM4_CentipedeBody* DestroyedSegment);
|
void OnSegmentHit(AM4_CentipedeBody* DestroyedSegment);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
@@ -52,9 +52,13 @@ private:
|
|||||||
|
|
||||||
void SpawnCentipede();
|
void SpawnCentipede();
|
||||||
void UpdateHeadStatus();
|
void UpdateHeadStatus();
|
||||||
|
void SpawnMushroomsAtSegmentDeathPos(FVector Location);
|
||||||
|
|
||||||
bool CheckCollision(AM4_CentipedeBody* Segment, FVector2D Direction);
|
bool CheckCollision(AM4_CentipedeBody* Segment, FVector2D Direction);
|
||||||
|
|
||||||
FVector2D GetSegmentDirection(AM4_CentipedeBody* Segment);
|
FVector2D GetSegmentDirection(AM4_CentipedeBody* Segment);
|
||||||
void SetSegmentDirection(AM4_CentipedeBody* Segment, FVector2D Direction);
|
void SetSegmentDirection(AM4_CentipedeBody* Segment, FVector2D Direction);
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
class AM4_Gamemode* GM_REF_PTR;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user