Class PhysicsEngine

java.lang.Object
com.deco2800.game.physics.PhysicsEngine
All Implemented Interfaces:
Disposable

public class PhysicsEngine
extends java.lang.Object
implements Disposable
Process game physics using the Box2D library. See the Box2D documentation for examples or use cases.
  • Constructor Details

  • Method Details

    • update

      public void update()
    • createBody

      public Body createBody​(BodyDef bodyDef)
    • destroyBody

      public void destroyBody​(Body body)
    • createJoint

      public Joint createJoint​(JointDef jointDef)
    • destroyJoint

      public void destroyJoint​(Joint joint)
    • getWorld

      public World getWorld()
    • raycast

      public boolean raycast​(Vector2 from, Vector2 to, RaycastHit hit)
      Cast a ray in a straight line from one point to another, checking for a collision against any colliders.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      hit - The raycast result will be stored in this class
      Returns:
      true if a collider was hit, false otherwise.
    • raycast

      public boolean raycast​(Vector2 from, Vector2 to, short layerMask, RaycastHit hit)
      Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      hit - The hit of the closest collider will be stored in this.
      layerMask - The physics layer mask which specifies layers that can be hit. Other layers will be ignored.
      Returns:
      true if a collider was hit, false otherwise.
    • raycastAll

      public RaycastHit[] raycastAll​(Vector2 from, Vector2 to)
      Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      Returns:
      All hits made by the ray, unordered. Empty if no hits were made.
    • raycastAll

      public RaycastHit[] raycastAll​(Vector2 from, Vector2 to, short layerMask)
      Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      layerMask - The physics layer mask which specifies layers that can be hit. Other layers will be ignored.
      Returns:
      All hits made by the ray, unordered. Empty if no hits were made.
    • dispose

      public void dispose()
      Specified by:
      dispose in interface Disposable