Class LaserShowerComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.lasers.LaserShowerComponent

public class LaserShowerComponent extends Component
This component constructs a list of points where a laser beam would collide with objects. If the "beam" were to collide with a collider that has the PhysicsLayer.LASER_REFLECTOR layer than it calculates the reflected angle based on the normal of the surface and incoming angle.

The laser beam is limited to a max number of rebounds defined by MAX_REBOUNDS as well as a max distance defined by MAX_DISTANCE. If either of these limits are hit than the laser stops prematurely.

Additionally the laser will attempt to deal a set amount of damage to any entity with the PhysicsLayer.PLAYER layer, this can be extended to try to deal damage to other targets with different physics layers too.

The list of points in world space is then exposed globally by a getter method which can be accessed by the dedicated laser renderer to render lines between the points.

  • Constructor Details

    • LaserShowerComponent

      public LaserShowerComponent()
      default constructor
    • LaserShowerComponent

      public LaserShowerComponent(float dir)
      Creates a laser emitter pointing in the specified direction.
      Parameters:
      dir - initial laser angle in degrees
  • 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
    • update

      public void update()
      Description copied from class: Component
      Called once per frame of the game, and should be used for most component logic. Not called if component is disabled.
      Overrides:
      update in class Component
    • fireLaser

      public void fireLaser()
    • getPositions

      public List<com.badlogic.gdx.math.Vector2> getPositions()
      Gets the list of collision positions generated from the laser emitter which can be used to render lines between the points.
      Returns:
      the list of collision points
    • dispose

      public void dispose()
      Description copied from class: Component
      Called when the component is disposed. Dispose of any internal resources here.
      Overrides:
      dispose in class Component