diff --git a/Source/FistsOfSnake/FPSCharacter.cpp b/Source/FistsOfSnake/FPSCharacter.cpp index 90d03d8..f6921f3 100644 --- a/Source/FistsOfSnake/FPSCharacter.cpp +++ b/Source/FistsOfSnake/FPSCharacter.cpp @@ -254,6 +254,7 @@ void AFPSCharacter::DamageMe(int damage) if (Health <= 0) { bAlive = false; GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Yellow, TEXT("Im dead")); + MyInventory->DestroyItems(); Destroy(); } diff --git a/Source/FistsOfSnake/FPSProjectileGrenade.cpp b/Source/FistsOfSnake/FPSProjectileGrenade.cpp index 20b6b73..80329dc 100644 --- a/Source/FistsOfSnake/FPSProjectileGrenade.cpp +++ b/Source/FistsOfSnake/FPSProjectileGrenade.cpp @@ -69,25 +69,26 @@ void AFPSProjectileGrenade::OnDetonate() { for (auto& hited : OutHits) { - if (!&hited) - continue; - // Throw away some static mesh - UStaticMeshComponent *SM = Cast(hited.GetActor()->GetRootComponent()); - if (SM) - SM->AddRadialImpulse(GetActorLocation(), 1000.f, 5000.f, ERadialImpulseFalloff::RIF_Linear, true); - - // Crash some destructible mesh - ADestructibleActor *DA = Cast(hited.GetActor()); - if (DA) - DA->GetDestructibleComponent()->ApplyRadiusDamage(10.f, hited.ImpactPoint, 500.f, 3000.f, false); - - AFPSCharacter *Player = Cast(hited.GetActor()); - if (Player) + // Check if Actor has benn destroyed + if (hited.GetActor()) { - UPrimitiveComponent* ActorComponent = hited.GetActor()->FindComponentByClass(); - ActorComponent->AddRadialImpulse(GetActorLocation(), 1000.f, 5000.f, ERadialImpulseFalloff::RIF_Linear, true); - Player->DamageMe(this->Damage); - // notka -> jak gracz spadnie z rowerka to granat, który trzyma w ręku zostaje, bo obiekt gracza nadal istnieje + // Throw away some static mesh + UStaticMeshComponent* SM = Cast(hited.GetActor()->GetRootComponent()); + if (SM) + SM->AddRadialImpulse(GetActorLocation(), 1000.f, 5000.f, ERadialImpulseFalloff::RIF_Linear, true); + + // Crash some destructible mesh + ADestructibleActor* DA = Cast(hited.GetActor()); + if (DA) + DA->GetDestructibleComponent()->ApplyRadiusDamage(10.f, hited.ImpactPoint, 500.f, 3000.f, false); + + AFPSCharacter* Player = Cast(hited.GetActor()); + if (Player) + { + UPrimitiveComponent* ActorComponent = hited.GetActor()->FindComponentByClass(); + ActorComponent->AddRadialImpulse(GetActorLocation(), 1000.f, 5000.f, ERadialImpulseFalloff::RIF_Linear, true); + Player->DamageMe(this->Damage); + } } } } diff --git a/Source/FistsOfSnake/Inventory.cpp b/Source/FistsOfSnake/Inventory.cpp index c97c2f3..b46d387 100644 --- a/Source/FistsOfSnake/Inventory.cpp +++ b/Source/FistsOfSnake/Inventory.cpp @@ -42,6 +42,17 @@ UTexture2D* Inventory::GetItemIcon(int Index) return nullptr; } +void Inventory::DestroyItems() +{ + for (int Index = 0; Index != this->Size; ++Index) + { + if (this->ArrayOfItems[Index]) + { + this->ArrayOfItems[Index]->Destroy(); + } + } +} + Inventory::~Inventory() { } \ No newline at end of file diff --git a/Source/FistsOfSnake/Inventory.h b/Source/FistsOfSnake/Inventory.h index f047ea9..9f9118f 100644 --- a/Source/FistsOfSnake/Inventory.h +++ b/Source/FistsOfSnake/Inventory.h @@ -25,5 +25,7 @@ class FISTSOFSNAKE_API Inventory UTexture2D* GetItemIcon(int Index); + void DestroyItems(); + ~Inventory(); }; \ No newline at end of file diff --git a/Source/FistsOfSnake/Item.cpp b/Source/FistsOfSnake/Item.cpp index cc5c564..8cc19dc 100644 --- a/Source/FistsOfSnake/Item.cpp +++ b/Source/FistsOfSnake/Item.cpp @@ -32,14 +32,19 @@ void AItem::Tick(float DeltaTime) for (auto& Player : this->Players) { - FVector PlayerLocation = Player->GetActorLocation(); - FVector Distance = PlayerLocation - this->GetActorLocation(); - - // When there is collision with someone - if (Distance.Size() < 100) + // Check if Player is dead + if (Player->GetHealth() > 0) { - OnCollision(Player); + FVector PlayerLocation = Player->GetActorLocation(); + FVector Distance = PlayerLocation - this->GetActorLocation(); + + // When there is collision with someone + if (Distance.Size() < 100) + { + OnCollision(Player); + } } + } } @@ -62,6 +67,10 @@ void AItem::PickUp(AFPSCharacter *Player) { HideOrExposeMe(true); } + else + { + GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, TEXT("The inventory is full")); + } } void AItem::HideOrExposeMe(bool bFlag)