Package org.collebol.shared.physics
Class PhysicsManager
java.lang.Object
org.collebol.shared.physics.PhysicsManager
The
PhysicsManager handles registration, movement, and collision
detection for all GameObject instances that contain physics components.
This manager provides a simple, brute-force collision system based on
BoxCollider checks. When an object is moved using tryMove(GameObject, GameLocation),
the system validates that the move does not cause the object to intersect with
any other registered object in the world.
Usage:
// Create a new physics manager
PhysicsManager physicsManager = new PhysicsManager();
// Register game objects
GameObject player = new Player();
player.addPhysicsComponent(new BoxCollider(player, 1, 1));
physicsManager.register(player);
// Attempt to move the player to a new location
GameLocation newLoc = new GameLocation(5, 3);
boolean success = physicsManager.tryMove(player, newLoc);
if (!success) {
System.out.println("Movement blocked by collision!");
}
This class can be extended or replaced with more advanced physics systems if needed, such as those involving velocity, gravity, or spatial partitioning.
- Since:
- 1.0-dev
- Author:
- ColleBol - contact@collebol.org
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newPhysicsManagerwith an empty list of registered objects. -
Method Summary
Modifier and TypeMethodDescriptionvoidregister(GameObject object) Registers aGameObjectfor collision detection and movement handling.booleantryMove(GameObject object, GameLocation newLoc) Attempts to move the specifiedGameObjectto a newGameLocation.
-
Constructor Details
-
PhysicsManager
public PhysicsManager()Constructs a newPhysicsManagerwith an empty list of registered objects.
-
-
Method Details