xsge.physics
This module provides an easy-to-use framework for collision physics.
This is especially useful for platformers, though it can also be useful
for other types of games.
xsge.physics Classes
xsge.physics.Collider
-
class xsge.physics.Collider(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Class for objects which have physics interactions.
Note
This class depends on use of Collider.move_x() and
Collider.move_y() to handle physics interactions.
event_update_position() uses these methods, so speed
attributes will work properly, but changing x and
y manually will not cause any physics to occur.
xsge.physics.Collider methods
-
Collider.move_x(move)[source]
Move the object horizontally, handling physics.
Arguments:
- move – The amount to add to x.
-
Collider.move_y(move)[source]
Move the object vertically, handling physics.
Arguments:
- move – The amount to add to y.
-
Collider.get_left_touching_wall()[source]
Return whether the left side of this object is touching the
right side of a SolidRight object.
-
Collider.get_right_touching_wall()[source]
Return whether the right side of this object is touching the
right side of a SolidLeft object.
-
Collider.get_top_touching_wall()[source]
Return whether the top side of this object is touching the
bottom side of a SolidBottom object.
-
Collider.get_bottom_touching_wall()[source]
Return whether the bottom side of this object is touching the
top side of a SolidTop object.
-
Collider.get_left_touching_slope()[source]
Return whether the left side of this object is touching the
right side of a SlopeTopRight or
SlopeBottomRight object.
-
Collider.get_right_touching_slope()[source]
Return whether the right side of this object is touching the
left side of a SlopeTopLeft or SlopeBottomLeft
object.
-
Collider.get_top_touching_slope()[source]
Return whether the top side of this object is touching the
bottom side of a SlopeBottomLeft or
SlopeBottomRight object.
-
Collider.get_bottom_touching_slope()[source]
Return whether the bottom side of this object is touching the
top side of a SlopeTopLeft or SlopeTopRight
object.
xsge.physics.SolidLeft
-
class xsge.physics.SolidLeft(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Class for walls which stop movement of Collider objects
from the top.
xsge.physics.SolidRight
-
class xsge.physics.SolidRight(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Class for walls which stop movement of Collider objects
from the right.
xsge.physics.SolidTop
-
class xsge.physics.SolidTop(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Class for walls which stop movement of Collider objects
from the top.
xsge.physics.SolidBottom
-
class xsge.physics.SolidBottom(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Class for walls which stop movement of Collider objects
from the bottom.
xsge.physics.Solid
-
class xsge.physics.Solid(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Inherits SolidLeft, SolidRight, SolidTop,
and SolidBottom. Meant to be a convenient parent class for
walls that should stop movement in all directions.
xsge.physics.SlopeTopLeft
-
class xsge.physics.SlopeTopLeft(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
A parent class for slopes which point in some direction upwards and
to the left.
Slopes of this type go from the bottom-left corner to the top-right
corner of the bounding box.
-
xsticky
If set to True, a collider that moves to the left while
touching the top side of the slope will attempt to keep touching
the top side of the slope by moving downward.
-
ysticky
If set to True, a collider that moves upward while
touching the left side of the slope will attempt to keep touching
the left side of the slope by moving to the right.
xsge.physics.SlopeTopRight
-
class xsge.physics.SlopeTopRight(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
A parent class for slopes which point in some direction upwards and
to the right.
Slopes of this type go from the top-left corner to the bottom-right
corner of the bounding box.
-
xsticky
If set to True, a collider that moves to the right while
touching the top side of the slope will attempt to keep touching
the top side of the slope by moving downward.
-
ysticky
If set to True, a collider that moves upward while
touching the right side of the slope will attempt to keep
touching the right side of the slope by moving to the left.
xsge.physics.SlopeBottomLeft
-
class xsge.physics.SlopeBottomLeft(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
A parent class for slopes which point in some direction upwards and
to the left.
Slopes of this type go from the top-left corner to the bottom-right
corner of the bounding box.
-
xsticky
If set to True, a collider that moves to the left while
touching the bottom side of the slope will attempt to keep
touching the bottom side of the slope by moving upward.
-
ysticky
If set to True, a collider that moves downward while
touching the left side of the slope will attempt to keep touching
the left side of the slope by moving to the right.
xsge.physics.SlopeBottomRight
-
class xsge.physics.SlopeBottomRight(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
A parent class for slopes which point in some direction upwards and
to the right.
Slopes of this type go from the bottom-left corner to the top-right
corner of the bounding box.
-
xsticky
If set to True, a collider that moves to the right while
touching the bottom side of the slope will attempt to keep
touching the bottom side of the slope by moving upward.
-
ysticky
If set to True, a collider that moves downward while
touching the left side of the slope will attempt to keep touching
the left side of the slope by moving to the right.