Class TouchAttackComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.components.TouchAttackComponent

public class TouchAttackComponent
extends Component
When this entity touches a valid enemy's hitbox, deal damage to them and apply a knockback.

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

    Fields inherited from class com.deco2800.game.components.Component

    enabled, entity
  • Constructor Summary

    Constructors 
    Constructor Description
    TouchAttackComponent​(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.
  • Method Summary

    Modifier and Type Method Description
    void create()
    Called when the entity is created and registered.

    Methods inherited from class com.deco2800.game.components.Component

    dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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.
  • 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.
      Overrides:
      create in class Component