Class for game objects.
This class is used for game objects, such as the player, enemies, bullets, and the HUD. Generally, each type of object has its own subclass of sge.StellarClass.
The horizontal position of the object in the room.
The vertical position of the object in the room.
The Z-axis position of the object in the room.
The sprite currently in use by this object. Set to None for no sprite.
Whether or not the object’s sprite should be projected onto the screen.
Indicates whether the object is active (True) or inactive (False). While the object is active, it will exhibit normal behavior; events will be executed normally as will any other automatic functionality, such as adding xvelocity and yvelocity to x and y. If active is False, automatic functionality and normal events will be disabled and events which have names starting with event_inactive_ will be executed instead of the corresponding normal events.
Note
Inactive sge.StellarClass objects are still visible by default and continue to be involved in collisions. In addition, collision events and destroy events still occur even if the object is inactive. If you wish for the object to not be visible, set visible to False. If you wish for the object to not be involved in collisions, set detects_collisions to False.
Note
Making an object inactive will not likely have a significant effect on performance. For performance enhancement, it is far more effective to exclude objects from collision detection. Object deactivation is meant to be used to easily maintain control over objects that are currently being excluded from collision detection (e.g. to prevent a gravity effect that would otherwise occur, or to prevent the object from moving through walls).
Whether or not the object should be involved in collision detection. Setting this to False can improve performance if the object doesn’t need to detect collisions.
Depending on the game, a useful strategy to boost performance can be to exclude an object from collision detection while it is outside the view. If you do this, you likely also to set active to False as well so that the object doesn’t move in undesireable ways (e.g. through walls).
The horizontal location of the bounding box relative to the object’s position. If set to None, the value recommended by the sprite is used.
The vertical location of the bounding box relative to the object’s position. If set to None, the value recommended by the sprite is used.
The width of the bounding box in pixels. If set to None, the value recommended by the sprite is used.
The height of the bounding box in pixels. If set to None, the value recommended by the sprite is used.
If set to True, the origin is automatically adjusted to be the location of the pixel recommended by the sprite after transformation. This will cause rotation to be about the origin rather than being about the center of the image.
Note
The value of this attribute has no effect on the bounding box. If you wish for the bounding box to be adjusted as well, you must do so manually. As an alternative, you may want to consider using precise collision detection instead.
Whether or not an ellipse (rather than a rectangle) should be used for collision detection.
Whether or not precise (pixel-perfect) collision detection should be used. Note that this can be inefficient and does not work well with animated sprites.
The position of the right side of the bounding box in the room (same as bbox_left + bbox_width).
The position of the bottom side of the bounding box in the room (same as bbox_top + bbox_height).
The velocity of the object toward the right.
The velocity of the object toward the bottom.
The total (directional) speed of the object.
The direction of the object’s movement in degrees, with 0 being directly to the right and rotation in a positive direction being counter-clockwise.
The animation frame currently being displayed, with 0 being the first one.
The horizontal location of the origin relative to the left edge of the images. If set to None, the value recommended by the sprite is used.
The vertical location of the origin relative to the top edge of the images. If set to None, the value recommended by the sprite is used.
The animation rate in frames per second. If set to None, the value recommended by the sprite is used.
The animation rate as a factor of sge.game.fps. If set to None, the value recommended by the sprite is used.
The horizontal scale factor for the sprite.
The vertical scale factor for the sprite.
The rotation of the sprite in degrees, with rotation in a positive direction being counter-clockwise.
If regulate_origin is True, the image is rotated about the origin. Otherwise, the image is rotated about its center.
The alpha value applied to the entire image, where 255 is the original image, 128 is half the opacity of the original image, 0 is fully transparent, etc.
The color to blend with the sprite. Set to None for no color blending.
The unique identifier for this object. (Read-only)
The current mask used for non-rectangular collision detection. See the documentation for sge.collision.masks_collide() for more information. (Read-only)
The horizontal location of the mask in the room. (Read-only)
The vertical location of the mask in the room. (Read-only)
Constructor method.
Arguments:
All other arugments set the respective initial attributes of the object. See the documentation for sge.StellarClass for more information.
Return a list of objects colliding with this object.
Arguments:
Set an alarm.
Arguments:
After this method is called, value will reduce by 1 each frame (adjusted for delta timing if it is enabled) until it reaches 0, at which point sge.StellarClass.event_alarm() will be executed with alarm_id.
Return the value of an alarm.
Arguments:
If the alarm has not been set, None will be returned.
Destroy the object.
Create an object of this class in the current room.
args and kwargs are passed to the constructor method of cls as arguments. Calling obj = cls.create(*args, **kwargs) is the same as:
obj = cls(*args, **kwargs)
sge.game.current_room.add(obj)
Create event.
Called when the object is created. It is always called after any room start events occurring at the same time.
Destroy event.
Step event.
This event is executed each frame after automatic updates to objects (such as the effects of the speed variables), but before collision events.
See the documentation for sge.Game.event_step() for more information.
Alarm event.
Called when the value of an alarm reaches 0.
Arguments:
Animation End event.
Called when an animation cycle ends.
Key press event.
See the documentation for sge.Game.event_key_press() for more information.
Key release event.
See the documentation for sge.Game.event_key_release() for more information.
Mouse move event.
See the documentation for sge.Game.event_mouse_move() for more information.
Mouse button press event.
See the documentation for sge.Game.event_mouse_button_press() for more information.
Mouse button release event.
See the documentation for sge.Game.event_mouse_button_release() for more information.
Joystick axis move event.
See the documentation for sge.Game.event_joystick_axis_move() for more information.
Joystick HAT move event.
See the documentation for sge.Game.event_joystick_hat_move() for more information.
Joystick trackball move event.
See the documentation for sge.Game.event_joystick_trackball_move() for more information.
Joystick button press event.
See the documentation for sge.Game.event_joystick_button_press() for more information.
Joystick button release event.
See the documentation for sge.Game.event_joystick_button_release() for more information.
Update position event.
Called when it’s time to update the position of the object. This method handles this functionality, so defining this will override the default behavior and allow you to handle the speed variables in a special way.
The default behavior of this method is:
self.x += self.xvelocity * delta_mult
self.y += self.yvelocity * delta_mult
See the documentation for sge.Game.event_step() for more information.
Default collision event.
Called when another object collides with this object and none of the directional collision events are appropriate. In particular, this is called if the collision was already happening in the previous frame. This is also the event method called by the directional collision event methods by default.
Arguments:
Left collision event.
Called when another object collides with this object’s left side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Right collision event.
Called when another object collides with this object’s right side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Top collision event.
Called when another object collides with this object’s top side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Bottom collision event.
Called when another object collides with this object’s bottom side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Step event when this object is inactive.
See the documentation for sge.StellarClass.event_step() for more information. The object is considered to be inactive when active is False.
Key press event when this object is inactive.
See the documentation for sge.Game.event_key_press() for more information. The object is considered to be inactive when active is False.
Key release event when this object is inactive.
See the documentation for sge.Game.event_key_release() for more information. The object is considered to be inactive when active is False.
Mouse move event when this object is inactive.
See the documentation for sge.Game.event_mouse_move() for more information. The object is considered to be inactive when active is False.
Mouse button press event when this object is inactive.
See the documentation for sge.Game.event_mouse_button_press() for more information. The object is considered to be inactive when active is False.
Mouse button release event when this object is inactive.
See the documentation for sge.Game.event_mouse_button_release() for more information. The object is considered to be inactive when active is False.
Joystick axis move event when this object is inactive.
See the documentation for sge.Game.event_joystick_axis_move() for more information. The object is considered to be inactive when active is False.
Joystick HAT move event when this object is inactive.
See the documentation for sge.Game.event_joystick_hat_move() for more information. The object is considered to be inactive when active is False.
Joystick trackball move event when this object is inactive.
See the documentation for sge.Game.event_joystick_trackball_move() for more information. The object is considered to be inactive when active is False.
Joystick button press event when this object is inactive.
See the documentation for sge.Game.event_joystick_button_press() for more information. The object is considered to be inactive when active is False.
Joystick button release event when this object is inactive.
See the documentation for sge.Game.event_joystick_button_release() for more information. The object is considered to be inactive when active is False.
Key press event when paused.
See the documentation for sge.Game.event_key_press() for more information.
Key release event when paused.
See the documentation for sge.Game.event_key_release() for more information.
Mouse move event when paused.
See the documentation for sge.Game.event_mouse_move() for more information.
Mouse button press event when paused.
See the documentation for sge.Game.event_mouse_button_press() for more information.
Mouse button release event when paused.
See the documentation for sge.Game.event_mouse_button_release() for more information.
Joystick axis move event when paused.
See the documentation for sge.Game.event_joystick_axis_move() for more information.
Joystick HAT move event when paused.
See the documentation for sge.Game.event_joystick_hat_move() for more information.
Joystick trackball move event when paused.
See the documentation for sge.Game.event_joystick_trackball_move() for more information.
Joystick button press event when paused.
See the documentation for sge.Game.event_joystick_button_press() for more information.
Joystick button release event when paused.
See the documentation for sge.Game.event_joystick_button_release() for more information.