Package pajammin :: Module physics :: Class PhysicsEngine
[show private | hide private]
[frames | no frames]

Class PhysicsEngine


A physics engine for platform games.

The physics engine manages a collection of bodies. These bodies are moved automatically, based on their velocities, by calling update at regular intervals; and can also be moved explicitly (e.g., with move).
Method Summary
  __init__(self)
  add(self, body)
  bodies(self, include_nonsolids)
Return a list of all bodies managed by the physics engine
  bodies_intersecting_point(self, x, y, include_nonsolids)
Return a list of all bodies intersecting the given point.
  bodies_intersecting_rect(self, rect, include_nonsolids)
Return a list of all bodies intersecting the given rect.
  jump(self, body, dx, dy, check_collisions)
If it is possible to move the given body by the specified distance without causing a collision at the destination, then do so.
  jump_to(self, body, x, y, check_collisions)
  move(self, body, dx, dy, report_collisions)
Move the given body (and any supported bodies) by the specified distance.
  move_to(self, body, x, y, report_collisions)
  remove(self, body)
  set_bbox(self, body, bbox, check_collisions)
Attempt to change the given body's bounding box to bbox.
  update(self, interval, pos)
Update the positions of all bodies in the world.

Class Variable Summary
bool debug = False

Method Details

__init__(self)
(Constructor)

add(self, body)

bodies(self, include_nonsolids=True)

Returns:
A list of all bodies managed by the physics engine

bodies_intersecting_point(self, x, y, include_nonsolids=True)

Returns:
A list of all bodies intersecting the given point.

bodies_intersecting_rect(self, rect, include_nonsolids=True)

Returns:
A list of all bodies intersecting the given rect.

jump(self, body, dx, dy, check_collisions=True)

If it is possible to move the given body by the specified distance without causing a collision at the destination, then do so. Otherwise, just return False. Do not move supported objects.
Parameters:
dx, dy - The distance to move.
Returns:
True if the given body was successfully moved.

jump_to(self, body, x, y, check_collisions=True)

move(self, body, dx, dy, report_collisions=True)

Move the given body (and any supported bodies) by the specified distance. If the movement results in a collision (by this body -- not supported ones), then generate collision messages for both colliding bodies, and return False. Otherwise, return True.
Parameters:
dx, dy - The distance to move.
report_collisions - If False, then collision reporting is supressed.

move_to(self, body, x, y, report_collisions=True)

remove(self, body)

set_bbox(self, body, bbox, check_collisions=True)

Attempt to change the given body's bounding box to bbox. If that would cause a collision, then just return false; do not perform the move or generate any collision messages.

update(self, interval, pos)

Update the positions of all bodies in the world. Bodies that are close to the given pos (within 1000 pixels or so) will be updated at a much higher frequency than bodies that are farther away.

Class Variable Details

debug

Type:
bool
Value:
False