PhysicsEngine

public final class PhysicsEngine

Class for calculating and performing physical operations with entities.

All entities exist on a 2D grid of their units, which represents a single level.

The supported operations are performing movements, detecting collisions, checking if paths are obstructed and so on.

Parameters

w

Width of level.

h

Height of level.

Constructors

Link copied to clipboard
PhysicsEngine PhysicsEngine(Integer w, Integer h)

Creates a PhysicsEngine with no entities on the grid.

Types

Link copied to clipboard
public class Companion

Functions

Link copied to clipboard
final Boolean checkPathAvailability(Paths2D.PathStrategy path, Cell startCell, Integer depth, Function1<GameUnit, Boolean> unitIsOk, Function1<GameUnit, Boolean> unitIsTarget)

Checks if all cells on path are available.

Link copied to clipboard
final Cell generateRandomTarget(GameEntity entity, Random random)

Generate a random cell in bounds of this grid which is not occupied by entity.

Link copied to clipboard
final Unit remove(GameEntity entity)

Removes the entity from this PhysicsEngine grid.

Link copied to clipboard
final Unit removeUnits(Set<GameUnit> units)

Removes the units (of the same entity) from this PhysicsEngine grid.

Link copied to clipboard
final Boolean tryMove(GameEntity entity, Direction dir)

Tries to move an existing GameEntity in the specified Direction by one Cell.

Link copied to clipboard
final Boolean tryPopulate(GameEntity entity)

Tries to add the entity to this PhysicsEngine grid.