-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from UQcsse3200/Team-2--Alasdair-Branch
Team 2 alasdair branch
- Loading branch information
Showing
23 changed files
with
706 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
source/core/src/main/com/csse3200/game/components/AoeComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.csse3200.game.components; | ||
|
||
import com.badlogic.gdx.physics.box2d.Fixture; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.physics.BodyUserData; | ||
import com.csse3200.game.physics.components.HitboxComponent; | ||
import com.csse3200.game.services.ServiceLocator; | ||
|
||
import com.badlogic.gdx.utils.Array; | ||
|
||
public class AoeComponent extends Component { | ||
private final float radius; | ||
private HitboxComponent hitboxComponent; | ||
|
||
/** | ||
* Constructor for the AoEComponent. | ||
* | ||
* @param radius The radius of the area-of-effect. | ||
*/ | ||
public AoeComponent(float radius) { | ||
this.radius = radius; | ||
} | ||
|
||
@Override | ||
public void create() { | ||
entity.getEvents().addListener("collisionStart", this::onCollisionStart); | ||
entity.getEvents().addListener("collisionEnd", this::onCollisionEnd); | ||
hitboxComponent = entity.getComponent(HitboxComponent.class); | ||
} | ||
|
||
private void onCollisionStart(Fixture me, Fixture other) { | ||
// Nothing to do on collision start | ||
} | ||
|
||
private void onCollisionEnd(Fixture me, Fixture other) { | ||
if (hitboxComponent.getFixture() != me) { | ||
// Not triggered by hitbox, ignore | ||
return; | ||
} | ||
applyAoeDamage(); | ||
} | ||
/** | ||
* Apply damage to all entities within the area of effect (radius). | ||
*/ | ||
public void applyAoeDamage() { | ||
Entity hostEntity = getEntity(); | ||
CombatStatsComponent hostCombatStats = hostEntity.getComponent(CombatStatsComponent.class); | ||
|
||
if (hostCombatStats == null) { | ||
// The host entity does not have a CombatStatsComponent to deal damage | ||
return; | ||
} | ||
|
||
Array<Entity> nearbyEntities = ServiceLocator.getEntityService().getNearbyEntities(hostEntity, radius); | ||
|
||
for (Entity targetEntity : nearbyEntities) { | ||
CombatStatsComponent targetCombatStats = targetEntity.getComponent(CombatStatsComponent.class); | ||
if (targetCombatStats != null) { | ||
targetCombatStats.hit(hostCombatStats); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.