Skip to content

Commit 0087e2a

Browse files
committed
Added power when player picks up a battery
1 parent e7b3a83 commit 0087e2a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Source/BatteryCollector/BatteryCollectorCharacter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "BatteryCollector.h"
44
#include "BatteryCollectorCharacter.h"
55
#include "Pickup.h"
6+
#include "BatteryPickup.h"
67

78
//////////////////////////////////////////////////////////////////////////
89
// ABatteryCollectorCharacter
@@ -144,6 +145,9 @@ void ABatteryCollectorCharacter::CollectPickups()
144145
TArray<AActor*> CollectedActors;
145146
CollectionSphere->GetOverlappingActors(CollectedActors);
146147

148+
// keep track of the collected battery power
149+
float CollectedPower = 0;
150+
147151
// For each Actor we collected
148152
for (int32 iCollected = 0; iCollected < CollectedActors.Num(); ++iCollected)
149153
{
@@ -154,10 +158,21 @@ void ABatteryCollectorCharacter::CollectPickups()
154158
{
155159
// Call the pickup's WasCollected function
156160
TestPickup->WasCollected();
161+
// Check to see if the pickup is also a battery
162+
ABatteryPickup* const TestBattery = Cast<ABatteryPickup>(TestPickup);
163+
if (TestBattery)
164+
{
165+
// increase the collected power
166+
CollectedPower += TestBattery->GetPower();
167+
}
157168
// Deactivate the pickup
158169
TestPickup->SetActive(false);
159170
}
160171
}
172+
if (CollectedPower > 0)
173+
{
174+
UpdatePower(CollectedPower);
175+
}
161176
}
162177

163178
// Reports starting power

0 commit comments

Comments
 (0)