Package com.csse3200.game.components
Class TouchAttackComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.TouchAttackComponent
When this entity touches a valid enemy's hitbox, deal damage to them and
apply a knockback.
Has an optional disposeOnHit property that disposes projectile upon
collision.
Requires CombatStatsComponent, HitboxComponent on this entity.
Damage is only applied if target entity has a CombatStatsComponent. Knockback is only applied if target entity has a PhysicsComponent.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTouchAttackComponent
(short targetLayer) Create a component which attacks entities on collision, without knockback.TouchAttackComponent
(short targetLayer, float knockback) Create a component which attacks entities on collision, with knockback.TouchAttackComponent
(short targetLayer, float knockback, boolean disposeOnHit) Create a component which attacks entities on collision, with knockback and self-dispose. -
Method Summary
Modifier and TypeMethodDescriptionchooseWeapon
(com.badlogic.gdx.physics.box2d.Fixture other) Choose the weapon to use against the given fixture.void
create()
Called when the entity is created and registered.void
onCollisionStart
(com.badlogic.gdx.physics.box2d.Fixture me, com.badlogic.gdx.physics.box2d.Fixture other) void
setDisposeOnHit
(boolean disposeOnHit) void
setKnockBack
(float knockback) void
setTargetLayer
(short targetLayer) Sets the target layer of this component, changing which entity to "attack" and/or apply knockback to.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
TouchAttackComponent
public TouchAttackComponent(short targetLayer) Create a component which attacks entities on collision, without knockback.- Parameters:
targetLayer
- The physics layer of the target's collider.
-
TouchAttackComponent
public TouchAttackComponent(short targetLayer, float knockback) Create a component which attacks entities on collision, with knockback.- Parameters:
targetLayer
- The physics layer of the target's collider.knockback
- The magnitude of the knockback applied to the entity.
-
TouchAttackComponent
public TouchAttackComponent(short targetLayer, float knockback, boolean disposeOnHit) Create a component which attacks entities on collision, with knockback and self-dispose.- Parameters:
targetLayer
- The physics layer of the target's collider.knockback
- The magnitude of the knockback applied to the entity.disposeOnHit
- Whether this entity should be disposed on hit.
-
-
Method Details
-
create
public void create()Description copied from class:Component
Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished. -
onCollisionStart
public void onCollisionStart(com.badlogic.gdx.physics.box2d.Fixture me, com.badlogic.gdx.physics.box2d.Fixture other) -
setDisposeOnHit
public void setDisposeOnHit(boolean disposeOnHit) -
setKnockBack
public void setKnockBack(float knockback) -
chooseWeapon
Choose the weapon to use against the given fixture. If the fixture has been removed (died) return null, else return the weapon to use. -
setTargetLayer
public void setTargetLayer(short targetLayer) Sets the target layer of this component, changing which entity to "attack" and/or apply knockback to.- Parameters:
targetLayer
-
-