Skip to content

Commit 2287a9b

Browse files
committed
Pickup collection progress
1 parent cba48bf commit 2287a9b

6 files changed

Lines changed: 36 additions & 1 deletion

File tree

Source/BatteryCollector/BatteryCollectorCharacter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ ABatteryCollectorCharacter::ABatteryCollectorCharacter()
3737
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
3838
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
3939

40+
// Create the collection sphere
41+
CollectionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("CollectionSphere"));
42+
CollectionSphere->AttachTo(RootComponent);
43+
CollectionSphere->SetSphereRadius(200.f);
44+
4045
// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
4146
// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
4247
}

Source/BatteryCollector/BatteryCollectorCharacter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class ABatteryCollectorCharacter : public ACharacter
1515
/** Follow camera */
1616
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
1717
class UCameraComponent* FollowCamera;
18+
19+
/** Collection sphere */
20+
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
21+
class USphereComponent* CollectionSphere;
1822
public:
1923
ABatteryCollectorCharacter();
2024

@@ -62,5 +66,7 @@ class ABatteryCollectorCharacter : public ACharacter
6266
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
6367
/** Returns FollowCamera subobject **/
6468
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
69+
/** Returns CollectionSphere subobject **/
70+
FORCEINLINE class USphereComponent* GetCollectionSphere() const { return CollectionSphere; }
6571
};
6672

Source/BatteryCollector/BatteryPickup.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
#include "BatteryCollector.h"
44
#include "BatteryPickup.h"
55

6+
67
//Set default values
78
ABatteryPickup::ABatteryPickup()
89
{
910
GetMesh()->SetSimulatePhysics(true);
1011
}
1112

1213

14+
void ABatteryPickup::WasCollected_Implementation()
15+
{
16+
// Use the base pickup behavior
17+
Super::WasCollected_Implementation();
18+
// Destroy the battery
19+
Destroy();
20+
}

Source/BatteryCollector/BatteryPickup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ class BATTERYCOLLECTOR_API ABatteryPickup : public APickup
1717
// Sets default values for this actor's properties
1818
ABatteryPickup();
1919

20+
/** Override the WasCollected function - use Implementation because it's a Blueprint Native Event */
21+
void WasCollected_Implementation() override;
2022
};

Source/BatteryCollector/Pickup.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ APickup::APickup()
1010
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
1111
PrimaryActorTick.bCanEverTick = false;
1212

13-
// All pickup start active
13+
// All pickups start active
1414
bIsActive = true;
1515

1616
// Create the static mesh component
1717
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
1818
RootComponent = PickupMesh;
19+
1920
}
2021

2122
// Called when the game starts or when spawned
@@ -42,4 +43,12 @@ bool APickup::IsActive()
4243
void APickup::SetActive(bool NewPickupState)
4344
{
4445
bIsActive = NewPickupState;
46+
}
47+
48+
void APickup::WasCollected_Implementation()
49+
{
50+
// Log a debug message
51+
FString PickupDebugString = GetName();
52+
UE_LOG(LogClass, Log, TEXT("You have collected %s"), *PickupDebugString);
53+
4554
}

Source/BatteryCollector/Pickup.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class BATTERYCOLLECTOR_API APickup : public AActor
3131
UFUNCTION(BlueprintCallable, Category = "Pickup")
3232
void SetActive(bool NewPickupState);
3333

34+
/** Function to call when the pickup is collected */
35+
UFUNCTION(BlueprintNativeEvent)
36+
void WasCollected();
37+
virtual void WasCollected_Implementation();
38+
3439

3540
protected:
3641
/**True when the pickup can be used, and false when pickup is deactivated */

0 commit comments

Comments
 (0)