Skip to content

Commit

Permalink
[Add] Take damage on touching hazard ( campfire placeholder)
Browse files Browse the repository at this point in the history
  • Loading branch information
iJotape4 committed Oct 20, 2024
1 parent 4a5a0c4 commit ab9c80d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
Binary file modified BP_Pics/Hazards/CampfireDetails.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "EventsManager.h"
#include "PaperFlipbookComponent.h"
#include "GameJamPlus2024/GameJamPlus2024Character.h"
#include "Hazards/HazardBase.h"

APaperCharacterBase::APaperCharacterBase()
{
Expand Down Expand Up @@ -125,4 +126,17 @@ void APaperCharacterBase::TakeDamage(int Damage)
void APaperCharacterBase::BeginPlay()
{
Super::BeginPlay();
OnActorBeginOverlap.AddDynamic(this, &APaperCharacterBase::OnBeginOverlap);
}

void APaperCharacterBase::OnBeginOverlap(AActor* OverlappedActor, AActor* OtherActor)
{
if (OtherActor && OtherActor != this) // Ensure it's a valid actor and not self
{
AHazardBase* Hazard = Cast<AHazardBase>(OtherActor);
if(Hazard != nullptr)
{
TakeDamage(Hazard->Damage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class GAMEJAMPLUS2024_API AHazardBase : public AActor
// Called when the game starts or when spawned
virtual void BeginPlay() override;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Upgrades", meta = (AllowPrivate))
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivate))
UBoxComponent* CollisionBox;


public:
// Called every frame
virtual void Tick(float DeltaTime) override;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HazardValues", meta = (AllowPrivate))
int Damage = 10;
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ class GAMEJAMPLUS2024_API APaperCharacterBase : public APaperCharacter

// To add mapping context
virtual void BeginPlay() override;
private:

UFUNCTION()
void OnBeginOverlap(AActor* OverlappedActor, AActor* OtherActor);
};

0 comments on commit ab9c80d

Please sign in to comment.