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.
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 animation rate in frames per second. 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.
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)
Constructor method.
Arguments:
All other arugments set the respective initial attributes of the object. See the documentation for sge.StellarClass for more information.
Return whether or not this object collides with another.
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 it.
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.
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.
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.Game.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.