sge.StellarClass

class sge.StellarClass(x, y, z=0, ID=None, sprite=None, visible=True, active=True, detects_collisions=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)

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.

x

The horizontal position of the object in the room.

y

The vertical position of the object in the room.

z

The Z-axis position of the object in the room.

sprite

The sprite currently in use by this object. Set to None for no sprite.

visible

Whether or not the object’s sprite should be projected onto the screen.

active

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).

detects_collisions

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).

bbox_x

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.

bbox_y

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.

bbox_width

The width of the bounding box in pixels. If set to None, the value recommended by the sprite is used.

bbox_height

The height of the bounding box in pixels. If set to None, the value recommended by the sprite is used.

regulate_origin

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.

collision_ellipse

Whether or not an ellipse (rather than a rectangle) should be used for collision detection.

collision_precise

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.

bbox_left

The position of the left side of the bounding box in the room (same as x + bbox_x).

bbox_right

The position of the right side of the bounding box in the room (same as bbox_left + bbox_width).

bbox_top

The position of the top side of the bounding box in the room (same as y + bbox_y).

bbox_bottom

The position of the bottom side of the bounding box in the room (same as bbox_top + bbox_height).

xvelocity

The velocity of the object toward the right.

yvelocity

The velocity of the object toward the bottom.

speed

The total (directional) speed of the object.

move_direction

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.

image_index

The animation frame currently being displayed, with 0 being the first one.

image_origin_x

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.

image_origin_y

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.

image_fps

The animation rate in frames per second. If set to None, the value recommended by the sprite is used.

image_speed

The animation rate as a factor of sge.game.fps. If set to None, the value recommended by the sprite is used.

image_xscale

The horizontal scale factor for the sprite.

image_yscale

The vertical scale factor for the sprite.

image_rotation

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.

image_alpha

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.

image_blend

The color to blend with the sprite. Set to None for no color blending.

id

The unique identifier for this object. (Read-only)

mask

The current mask used for non-rectangular collision detection. See the documentation for sge.collision.masks_collide() for more information. (Read-only)

xstart

The initial value of x when the object was created. (Read-only)

ystart

The initial value of y when the object was created. (Read-only)

xprevious

The value of x at the end of the previous frame. (Read-only)

yprevious

The value of y at the end of the previous frame. (Read-only)

mask_x

The horizontal location of the mask in the room. (Read-only)

mask_y

The vertical location of the mask in the room. (Read-only)

sge.StellarClass Methods

StellarClass.__init__(x, y, z=0, ID=None, sprite=None, visible=True, active=True, detects_collisions=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)

Constructor method.

Arguments:

  • ID – The value to set id to. If set to None, fname minus the extension will be used, modified by the SGE if it is already the unique identifier of another music object.

All other arugments set the respective initial attributes of the object. See the documentation for sge.StellarClass for more information.

StellarClass.collision(other=None, x=None, y=None)

Return a list of objects colliding with this object.

Arguments:

  • other – What to check for collisions with. Can be one of the following:
  • x – The horizontal position to pretend this object is at for the purpose of the collision detection. If set to None, x will be used.
  • y – The vertical position to pretend this object is at for the purpose of the collision detection. If set to None, y will be used.
StellarClass.set_alarm(alarm_id, value)

Set an alarm.

Arguments:

  • alarm_id – The unique identifier of the alarm to set. Any value can be used as a unique identifier for an alarm.
  • value – The value to set the alarm to. Set to None to disable the alarm.

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.

StellarClass.get_alarm(alarm_id)

Return the value of an alarm.

Arguments:

  • alarm_id – The unique identifier of the alarm to check.

If the alarm has not been set, None will be returned.

StellarClass.destroy()

Destroy the object.

classmethod StellarClass.create(*args, **kwargs)

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)

sge.StellarClass Event Methods

StellarClass.event_create()

Create event.

Called when the object is created. It is always called after any room start events occurring at the same time.

StellarClass.event_destroy()

Destroy event.

StellarClass.event_step(time_passed, delta_mult)

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.

StellarClass.event_alarm(alarm_id)

Alarm event.

Called when the value of an alarm reaches 0.

Arguments:

  • alarm_id – The unique identifier of the alarm which was set off.
StellarClass.event_animation_end()

Animation End event.

Called when an animation cycle ends.

StellarClass.event_key_press(key, char)

Key press event.

See the documentation for sge.Game.event_key_press() for more information.

StellarClass.event_key_release(key)

Key release event.

See the documentation for sge.Game.event_key_release() for more information.

StellarClass.event_mouse_move(x, y)

Mouse move event.

See the documentation for sge.Game.event_mouse_move() for more information.

StellarClass.event_mouse_button_press(button)

Mouse button press event.

See the documentation for sge.Game.event_mouse_button_press() for more information.

StellarClass.event_mouse_button_release(button)

Mouse button release event.

See the documentation for sge.Game.event_mouse_button_release() for more information.

StellarClass.event_joystick_axis_move(name, ID, axis, value)

Joystick axis move event.

See the documentation for sge.Game.event_joystick_axis_move() for more information.

StellarClass.event_joystick_hat_move(name, ID, hat, x, y)

Joystick HAT move event.

See the documentation for sge.Game.event_joystick_hat_move() for more information.

StellarClass.event_joystick_trackball_move(name, ID, ball, x, y)

Joystick trackball move event.

See the documentation for sge.Game.event_joystick_trackball_move() for more information.

StellarClass.event_joystick_button_press(name, ID, button)

Joystick button press event.

See the documentation for sge.Game.event_joystick_button_press() for more information.

StellarClass.event_joystick_button_release(name, ID, button)

Joystick button release event.

See the documentation for sge.Game.event_joystick_button_release() for more information.

StellarClass.event_update_position(delta_mult)

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.

StellarClass.event_collision(other)

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:

  • other – The other object which was collided with.
StellarClass.event_collision_left(other)

Left collision event.

Called when another object collides with this object’s left side.

Arguments:

  • other – The other object which was collided with.

By default, this method simply calls sge.StellarClass.event_collision().

StellarClass.event_collision_right(other)

Right collision event.

Called when another object collides with this object’s right side.

Arguments:

  • other – The other object which was collided with.

By default, this method simply calls sge.StellarClass.event_collision().

StellarClass.event_collision_top(other)

Top collision event.

Called when another object collides with this object’s top side.

Arguments:

  • other – The other object which was collided with.

By default, this method simply calls sge.StellarClass.event_collision().

StellarClass.event_collision_bottom(other)

Bottom collision event.

Called when another object collides with this object’s bottom side.

Arguments:

  • other – The other object which was collided with.

By default, this method simply calls sge.StellarClass.event_collision().

StellarClass.event_inactive_step(time_passed, delta_mult)

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.

StellarClass.event_inactive_key_press(key, char)

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.

StellarClass.event_inactive_key_release(key)

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.

StellarClass.event_inactive_mouse_move(x, y)

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.

StellarClass.event_inactive_mouse_button_press(button)

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.

StellarClass.event_inactive_mouse_button_release(button)

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.

StellarClass.event_inactive_joystick_axis_move(name, ID, axis, value)

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.

StellarClass.event_inactive_joystick_hat_move(name, ID, hat, x, y)

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.

StellarClass.event_inactive_joystick_trackball_move(name, ID, ball, x, y)

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.

StellarClass.event_inactive_joystick_button_press(name, ID, button)

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.

StellarClass.event_inactive_joystick_button_release(name, ID, button)

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.

StellarClass.event_paused_key_press(key, char)

Key press event when paused.

See the documentation for sge.Game.event_key_press() for more information.

StellarClass.event_paused_key_release(key)

Key release event when paused.

See the documentation for sge.Game.event_key_release() for more information.

StellarClass.event_paused_mouse_move(x, y)

Mouse move event when paused.

See the documentation for sge.Game.event_mouse_move() for more information.

StellarClass.event_paused_mouse_button_press(button)

Mouse button press event when paused.

See the documentation for sge.Game.event_mouse_button_press() for more information.

StellarClass.event_paused_mouse_button_release(button)

Mouse button release event when paused.

See the documentation for sge.Game.event_mouse_button_release() for more information.

StellarClass.event_paused_joystick_axis_move(name, ID, axis, value)

Joystick axis move event when paused.

See the documentation for sge.Game.event_joystick_axis_move() for more information.

StellarClass.event_paused_joystick_hat_move(name, ID, hat, x, y)

Joystick HAT move event when paused.

See the documentation for sge.Game.event_joystick_hat_move() for more information.

StellarClass.event_paused_joystick_trackball_move(name, ID, ball, x, y)

Joystick trackball move event when paused.

See the documentation for sge.Game.event_joystick_trackball_move() for more information.

StellarClass.event_paused_joystick_button_press(name, ID, button)

Joystick button press event when paused.

See the documentation for sge.Game.event_joystick_button_press() for more information.

StellarClass.event_paused_joystick_button_release(name, ID, button)

Joystick button release event when paused.

See the documentation for sge.Game.event_joystick_button_release() for more information.

Table Of Contents

Previous topic

sge.Font

Next topic

sge.Room

This Page