Classes

sge.Game

class sge.Game(width=640, height=480, fullscreen=False, scale=None, scale_proportional=True, scale_smooth=False, fps=60, delta=False, delta_min=15, grab_input=False, window_text=None, window_icon=None, collision_events_enabled=True)

Class which handles the game.

This class handles most parts of the game which operate on a global scale, such as global game events. Before anything else is done with the SGE, an object either of this class or of a class derived from it must be created.

When an object of this class is created, it is automatically assigned to sge.game.

Note: Do not create multiple sge.Game objects. Doing so may cause errors.

width

The width of the game’s display.

height

The height of the game’s display.

fullscreen

Whether or not the game should be in fullscreen.

scale

A number indicating a fixed scale factor (e.g. 1 for no scaling, 2 for doubled size). If set to None or 0, scaling is automatic (causes the game to fit the window or screen).

scale_proportional

If set to True, scaling is always proportional. If set to False, the image will be distorted to completely fill the game window or screen. This has no effect unless scale is None or 0.

scale_smooth

Whether or not a smooth scaling algorithm (as opposed to a simple scaling algorithm such as nearest-neighbor) should be used.

fps

The rate the game should run in frames per second.

Note

This is only the maximum; if the computer is not fast enough, the game may run more slowly.

delta

Whether or not delta timing should be used. Delta timing affects object speeds, animation rates, and alarms.

delta_min

Delta timing can cause the game to be choppy. This attribute limits this by pretending that the frame rate is never lower than this amount, resulting in the game slowing down like normal if it is.

grab_input

Whether or not all input should be forcibly grabbed by the game. If this is True and the mouse cursor is invisible, the mouse will enter relative mode.

window_text

The text for the OS to display as the window title, e.g. in the frame of the window. If set to None, the SGE chooses the text.

window_icon

The name of the image file located in one of the directories specified in sge.image_directories to use as the window icon. If set to None, the SGE chooses the icon.

collision_events_enabled

Whether or not collision events should be executed. Setting this to False will improve performence if collision events are not needed.

input_events

A list containing all input event objects which have not yet been handled, in the order in which they occurred.

Note

If you handle input events manually, be sure to delete them from this list, preferably by getting them with list.pop(). Otherwise, the event will be handled more than once, which is usually not what you want.

registered_classes

A list containing all classes which have been registered with sge.Game.register_class(). (Read-only)

sprites

A dictionary containing all loaded sprites, indexed by the sprites’ sge.Sprite.id attributes. (Read-only)

background_layers

A dictionary containing all loaded background layers, indexed by the layers’ sge.BackgroundLayer.id attributes. (Read-only)

backgrounds

A dictionary containing all loaded backgrounds, indexed by the backgrounds’ sge.Background.id attributes. (Read-only)

fonts

A dictionary containing all loaded fonts, indexed by the fonts’ sge.Font.id attributes. (Read-only)

sounds

A dictionary containing all loaded sounds, indexed by the sounds’ sge.Sound.id attributes. (Read-only)

music

A dictionary containing all loaded music, indexed by the music objects’ sge.Music.id attributes. (Read-only)

objects

A dictionary containing all sge.StellarClass objects in the game, indexed by the objects’ sge.StellarClass.id attributes. (Read-only)

rooms

A list containing all rooms in order of their creation. (Read-only)

current_room

The room which is currently active. (Read-only)

mouse

A sge.StellarClass object which represents the mouse cursor. Its sge.StellarClass.id attribute is "mouse" and its bounding box is a one-pixel square. Speed variables are determined by averaging all mouse movement during the last quarter of a second. Assigning to its sge.StellarClass.visible attribute controls whether or not the mouse cursor is shown. Setting its sprite sets the mouse cursor to that sprite.

sge.Game Methods

Game.__init__(width=640, height=480, fullscreen=False, scale=None, scale_proportional=True, scale_smooth=False, fps=60, delta=False, delta_min=15, grab_input=False, window_text=None, window_icon=None, collision_events_enabled=True)

Constructor method.

Arguments set the respective initial attributes of the game. See the documentation for sge.Game for more information.

The created sge.Game object is automatically assigned to sge.game.

Game.start()

Start the game at the first room.

Can be called in the middle of a game to start the game over. If you do this, everything will be reset to its original state.

Game.end()

Properly end the game.

Game.pause(sprite=None)

Pause the game.

Arguments:

  • sprite – The sprite to show in the center of the screen while the game is paused. If set to None, the SGE chooses the image.

Normal events are not executed while the game is paused. Instead, events with the same name, but prefixed with event_paused_ instead of event_ are executed. Note that not all events have these alternative “paused” events associated with them.

Game.unpause()

Unpause the game.

Game.pump_input()

Cause the SGE to recieve input from the OS.

This method needs to be called periodically for the SGE to recieve events from the OS, such as key presses and mouse movement, as well as to assure the OS that the program is not locked up.

Upon calling this, each event is translated into the appropriate class in sge.input and the resulting object is appended to input_events.

You normally don’t need to use this function directly. It is called automatically in each frame of the SGE’s main loop. You only need to use this function directly if you take control away from the SGE’s main loop, e.g. to create your own loop.

Game.regulate_speed(fps=None)

Regulate the SGE’s running speed and return the time passed.

Arguments:

  • fps – The target frame rate in frames per second. Set to None to target the current value of fps.

When this method is called, the program will sleep long enough so that the game runs at fps frames per second, then return the number of milliseconds that passed between the previous call and the current call of this method.

You normally don’t need to use this function directly. It is called automatically in each frame of the SGE’s main loop. You only need to use this function directly if you want to create your own loop.

Game.refresh()

Refresh the screen.

This method needs to be called for changes to the screen to be seen by the user. It should be called every frame.

You normally don’t need to use this function directly. It is called automatically in each frame of the SGE’s main loop. You only need to use this function directly if you take control away from the SGE’s main loop, e.g. to create your own loop.

Game.register_class(cls)

Register a class with the SGE.

Registered classes can be used to index objects by, e.g. for sge.Room.objects_by_class. A list of all currently registered classes can be found in registered_classes.

Game.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.Game.event_alarm() will be executed with alarm_id.

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

Game.project_dot(x, y, color)

Project a single-pixel dot onto the game window.

Arguments:

  • x – The horizontal location relative to the window to project the dot.
  • y – The vertical location relative to the window to project the dot.

See the documentation for sge.Sprite.draw_dot() for more information.

Game.project_line(x1, y1, x2, y2, color, thickness=1, anti_alias=False)

Project a line segment onto the game window.

Arguments:

  • x1 – The horizontal location relative to the window of the first endpoint of the projected line segment.
  • y1 – The vertical location relative to the window of the first endpoint of the projected line segment.
  • x2 – The horizontal location relative to the window of the second endpoint of the projected line segment.
  • y2 – The vertical location relative to the window of the second endpoint of the projected line segment.

See the documentation for sge.Sprite.draw_line() for more information.

Game.project_rectangle(x, y, width, height, fill=None, outline=None, outline_thickness=1)

Project a rectangle onto the game window.

Arguments:

  • x – The horizontal location relative to the window to project the rectangle.
  • y – The vertical location relative to the window to project the rectangle.

See the documentation for sge.Sprite.draw_rectangle() for more information.

Game.project_ellipse(x, y, width, height, fill=None, outline=None, outline_thickness=1, anti_alias=False)

Project an ellipse onto the game window.

Arguments:

  • x – The horizontal location relative to the window to position the imaginary rectangle containing the ellipse.
  • y – The vertical location relative to the window to position the imaginary rectangle containing the ellipse.
  • width – The width of the ellipse.
  • height – The height of the ellipse.
  • fill – The color of the fill of the ellipse.
  • outline – The color of the outline of the ellipse.
  • outline_thickness – The thickness of the outline of the ellipse.
  • anti_alias – Whether or not anti-aliasing should be used.

See the documentation for sge.Sprite.draw_ellipse() for more information.

Game.project_circle(x, y, radius, fill=None, outline=None, outline_thickness=1, anti_alias=False)

Project a circle onto the game window.

Arguments:

  • x – The horizontal location relative to the window to position the center of the circle.
  • y – The vertical location relative to the window to position the center of the circle.

See the documentation for sge.Sprite.draw_circle() for more information.

Game.project_sprite(sprite, image, x, y, blend_mode=None)

Project a sprite onto the game window.

Arguments:

  • x – The horizontal location relative to the window to project sprite.
  • y – The vertical location relative to the window to project sprite.

See the documentation for sge.Sprite.draw_sprite() for more information.

Game.project_text(font, text, x, y, width=None, height=None, color='black', halign=2, valign=8, anti_alias=True)

Project text onto the game window.

Arguments:

  • x – The horizontal location relative to the window to project the text.
  • y – The vertical location relative to the window to project the text.

See the documentation for sge.Sprite.draw_text() for more information.

sge.Game Event Methods

Game.event_game_start()

Game start event.

Called when the game starts. This is only called once (it is not called again when the game restarts) and it is always the very first event method called.

Game.event_game_end()

Game end event.

Called when the game ends. This is only called once and it is always the very last event method called.

Game.event_step(time_passed, delta_mult)

Global step event.

Called once each frame.

Arguments:

  • time_passed – The number of milliseconds that have passed during the last frame.
  • delta_mult – What speed and movement should be multiplied by this frame due to delta timing. If delta is False, this is always 1.
Game.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.
Game.event_key_press(key, char)

Key press event.

See the documentation for sge.input.KeyPress for more information.

Game.event_key_release(key)

Key release event.

See the documentation for sge.input.KeyRelease for more information.

Game.event_mouse_move(x, y)

Mouse move event.

See the documentation for sge.input.MouseMove for more information.

Game.event_mouse_button_press(button)

Mouse button press event.

See the documentation for sge.input.MouseButtonPress for more information.

Game.event_mouse_button_release(button)

Mouse button release event.

See the documentation for sge.input.MouseButtonRelease for more information.

Game.event_joystick_axis_move(js_name, js_id, axis, value)

Joystick axis move event.

See the documentation for sge.input.JoystickAxisMove for more information.

Game.event_joystick_hat_move(js_name, js_id, hat, x, y)

Joystick hat move event.

See the documentation for sge.input.JoystickHatMove for more information.

Game.event_joystick_trackball_move(js_name, js_id, ball, x, y)

Joystick trackball move event.

See the documentation for sge.input.JoystickTrackballMove for more information.

Game.event_joystick_button_press(js_name, js_id, button)

Joystick button press event.

See the documentation for sge.input.JoystickButtonPress for more information.

Game.event_joystick_button_release(js_name, js_id, button)

Joystick button release event.

See the documentation for sge.input.JoystickButtonRelease for more information.

Game.event_gain_keyboard_focus()

Gain keyboard focus event.

See the documentation for sge.input.KeyboardFocusGain for more information.

Game.event_lose_keyboard_focus()

Lose keyboard focus event.

See the documentation for sge.input.KeyboardFocusLose for more information.

Game.event_gain_mouse_focus()

Gain mouse focus event.

See the documentation for sge.input.MouseFocusGain for more information.

Game.event_lose_mouse_focus()

Lose mouse focus event.

See the documentation for sge.input.MouseFocusLose for more information.

Game.event_close()

Close event.

This is always called after any sge.Room.event_close() occurring at the same time.

See the documentation for sge.input.QuitRequest for more information.

Game.event_mouse_collision(other)

Default mouse collision event.

Proxy for sge.game.mouse.event_collision(). See the documentation for sge.StellarClass.event_collision() for more information.

Game.event_mouse_collision_left(other)

Left mouse collision event.

Proxy for sge.game.mouse.event_collision_left(). See the documentation for sge.StellarClass.event_collision_left() for more information.

Game.event_mouse_collision_right(other)

Right mouse collision event.

Proxy for sge.game.mouse.event_collision_right(). See the documentation for sge.StellarClass.event_collision_right() for more information.

Game.event_mouse_collision_top(other)

Top mouse collision event.

Proxy for sge.game.mouse.event_collision_top(). See the documentation for sge.StellarClass.event_collision_top() for more information.

Game.event_mouse_collision_bottom(other)

Bottom mouse collision event.

Proxy for sge.game.mouse.event_collision_bottom(). See the documentation for sge.StellarClass.event_collision_bottom() for more information.

Game.event_paused_key_press(key, char)

Key press event when paused.

See the documentation for sge.input.KeyPress for more information.

Game.event_paused_key_release(key)

Key release event when paused.

See the documentation for sge.input.KeyRelease for more information.

Game.event_paused_mouse_move(x, y)

Mouse move event when paused.

See the documentation for sge.input.MouseMove for more information.

Game.event_paused_mouse_button_press(button)

Mouse button press event when paused.

See the documentation for sge.input.MouseButtonPress for more information.

Game.event_paused_mouse_button_release(button)

Mouse button release event when paused.

See the documentation for sge.input.MouseButtonRelease for more information.

Game.event_paused_joystick_axis_move(js_name, js_id, axis, value)

Joystick axis move event when paused.

See the documentation for sge.input.JoystickAxisMove for more information.

Game.event_paused_joystick_hat_move(js_name, js_id, hat, x, y)

Joystick hat move event when paused.

See the documentation for sge.input.JoystickHatMove for more information.

Game.event_paused_joystick_trackball_move(js_name, js_id, ball, x, y)

Joystick trackball move event when paused.

See the documentation for sge.input.JoystickTrackballMove for more information.

Game.event_paused_joystick_button_press(js_name, js_id, button)

Joystick button press event when paused.

See the documentation for sge.input.JoystickButtonPress for more information.

Game.event_paused_joystick_button_release(js_name, js_id, button)

Joystick button release event when paused.

See the documentation for sge.input.JoystickButtonRelease for more information.

Game.event_paused_gain_keyboard_focus()

Gain keyboard focus event when paused.

See the documentation for sge.input.KeyboardFocusGain for more information.

Game.event_paused_lose_keyboard_focus()

Lose keyboard focus event when paused.

See the documentation for sge.input.KeyboardFocusLose for more information.

Game.event_paused_gain_mouse_focus()

Gain mouse focus event when paused.

See the documentation for sge.input.MouseFocusGain for more information.

Game.event_paused_lose_mouse_focus()

Lose mouse focus event when paused.

See the documentation for sge.input.MouseFocusLose for more information.

Game.event_paused_close()

Close event when paused.

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

sge.Sprite

class sge.Sprite(name=None, ID=None, width=None, height=None, transparent=True, origin_x=0, origin_y=0, fps=60, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None)

Class which holds information for images and animations.

This class stores images and information about how the SGE is to use those images.

What image formats are supported depends on the implementation of the SGE, but image formats that are generally a good choice are PNG and JPEG. See the implementation-specific information for a full list of supported formats.

width

The width of the sprite.

Note

Changing this attribute is a destructive transformation: it can result in loss of pixel information, especially if it is done repeatedly. Because of this, it is advised that you do not adjust this value for routine scaling. Use the image_xscale attribute of a sge.StellarClass object instead.

height

The height of the sprite.

Note

Changing this attribute is a destructive transformation: it can result in loss of pixel information, especially if it is done repeatedly. Because of this, it is advised that you do not adjust this value for routine scaling. Use the image_yscale attribute of a sge.StellarClass object instead.

transparent

Whether or not the image should be partially transparent. If an image does not have an alpha channel, a colorkey will be used, with the transparent color being the color of the top-rightmost pixel.

origin_x

The suggested horizontal location of the origin relative to the left edge of the images.

origin_y

The suggested vertical location of the origin relative to the top edge of the images.

fps

The suggested rate in frames per second to animate the image at.

speed

The suggested rate to animate the image at as a factor of sge.game.fps.

bbox_x

The horizontal location relative to the sprite of the suggested bounding box to use with it. If set to None, it will become equal to -origin_x (which is always the left edge of the image).

bbox_y

The vertical location relative to the sprite of the suggested bounding box to use with it. If set to None, it will become equal to -origin_y (which is always the top edge of the image).

bbox_width

The width of the suggested bounding box.

bbox_height

The height of the suggested bounding box.

name

The name of the sprite given when it was created. (Read-only)

id

The unique identifier of the sprite. (Read-only)

frames

The number of animation frames in the sprite. (Read-only)

sge.Sprite Methods

Sprite.__init__(name=None, ID=None, width=None, height=None, transparent=True, origin_x=0, origin_y=0, fps=60, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None)

Constructor method.

Arguments:

  • name – The base name of the image files, used to find all individual image files that make up the sprite’s animation in the paths specified in sge.image_directories. One of the following rules will be used to find the images:

    • The base name plus a valid image extension. If this rule is used, the image will be loaded as a single-frame sprite.
    • The base name and an integer separated by either a hyphen (-) or an underscore (_) and followed by a valid image extension. If this rule is used, all images with names like this are loaded and treated as an animation, with the lower-numbered images being earlier frames.
    • The base name and an integer separated by either -strip or _strip and followed by a valid image extension. If this rule is used, the image will be treated as an animation read as a horizontal reel from left to right, split into the number of frames indicated by the integer.
    • If the base name is None, the sprite will be a fully transparent rectangle at the specified size (with both width and height defaulting to 32 if they are set to None). The SGE decides what to assign to the sprite’s name attribute in this case, but it will always be a string.

    If none of the above rules can be used, IOError is raised.

  • ID – The value to assign id to. If set to None, name will be used, modified by the SGE if it is already the unique identifier of another sprite.

All other arguments set the respective initial attributes of the sprite. See the documentation for Sprite for more information.

Sprite.append_frame()

Append a new blank frame to the end of the sprite.

Sprite.insert_frame(frame)

Insert a new blank frame into the sprite.

Arguments:

  • frame – The frame of the sprite to insert the new frame in front of, where 0 is the first frame.
Sprite.delete_frame(frame)

Delete a frame from the sprite.

Arguments:

  • frame – The frame of the sprite to delete, where 0 is the first frame.
Sprite.draw_dot(x, y, color, frame=None)

Draw a single-pixel dot on the sprite.

Arguments:

  • x – The horizontal location relative to the sprite to draw the dot.
  • y – The vertical location relative to the sprite to draw the dot.
  • color – The color of the dot.
  • frame – The frame of the sprite to draw on, where 0 is the first frame; set to None to draw on all frames.
Sprite.draw_line(x1, y1, x2, y2, color, thickness=1, anti_alias=False, frame=None)

Draw a line segment on the sprite.

Arguments:

  • x1 – The horizontal location relative to the sprite of the first end point of the line segment.
  • y1 – The vertical location relative to the sprite of the first end point of the line segment.
  • x2 – The horizontal location relative to the sprite of the second end point of the line segment.
  • y2 – The vertical location relative to the sprite of the second end point of the line segment.
  • color – The color of the line segment.
  • thickness – The thickness of the line segment.
  • anti_alias – Whether or not anti-aliasing should be used.
  • frame – The frame of the sprite to draw on, where 0 is the first frame; set to None to draw on all frames.
Sprite.draw_rectangle(x, y, width, height, fill=None, outline=None, outline_thickness=1, frame=None)

Draw a rectangle on the sprite.

Arguments:

  • x – The horizontal location relative to the sprite to draw the rectangle.
  • y – The vertical location relative to the sprite to draw the rectangle.
  • width – The width of the rectangle.
  • height – The height of the rectangle.
  • fill – The color of the fill of the rectangle.
  • outline – The color of the outline of the rectangle.
  • outline_thickness – The thickness of the outline of the rectangle.
  • frame – The frame of the sprite to draw on, where 0 is the first frame; set to None to draw on all frames.
Sprite.draw_ellipse(x, y, width, height, fill=None, outline=None, outline_thickness=1, anti_alias=False, frame=None)

Draw an ellipse on the sprite.

Arguments:

  • x – The horizontal location relative to the sprite to position the imaginary rectangle containing the ellipse.
  • y – The vertical location relative to the sprite to position the imaginary rectangle containing the ellipse.
  • width – The width of the ellipse.
  • height – The height of the ellipse.
  • fill – The color of the fill of the ellipse.
  • outline – The color of the outline of the ellipse.
  • outline_thickness – The thickness of the outline of the ellipse.
  • anti_alias – Whether or not anti-aliasing should be used.
  • frame – The frame of the sprite to draw on, where 0 is the first frame; set to None to draw on all frames.
Sprite.draw_circle(x, y, radius, fill=None, outline=None, outline_thickness=1, anti_alias=False, frame=None)

Draw a circle on the sprite.

Arguments:

  • x – The horizontal location relative to the sprite to position the center of the circle.
  • y – The vertical location relative to the sprite to position the center of the circle.
  • radius – The radius of the circle.
  • fill – The color of the fill of the circle.
  • outline – The color of the outline of the circle.
  • outline_thickness – The thickness of the outline of the circle.
  • anti_alias – Whether or not anti-aliasing should be used.
  • frame – The frame of the sprite to draw on, where 0 is the first frame; set to None to draw on all frames.
Sprite.draw_sprite(sprite, image, x, y, frame=None, blend_mode=None)

Draw another sprite on the sprite.

Arguments:

  • sprite – The sprite to draw with.

  • image – The frame of sprite to draw with, where 0 is the first frame.

  • x – The horizontal location relative to self to position the origin of sprite.

  • y – The vertical location relative to self to position the origin of sprite.

  • frame – The frame of the sprite to draw on, where 0 is the first frame; set to None to draw on all frames.

  • blend_mode – The blend mode to use. Possible blend modes are:

    • sge.BLEND_NORMAL
    • sge.BLEND_RGBA_ADD
    • sge.BLEND_RGBA_SUBTRACT
    • sge.BLEND_RGBA_MULTIPLY
    • sge.BLEND_RGBA_SCREEN
    • sge.BLEND_RGBA_MINIMUM
    • sge.BLEND_RGBA_MAXIMUM
    • sge.BLEND_RGB_ADD
    • sge.BLEND_RGB_SUBTRACT
    • sge.BLEND_RGB_MULTIPLY
    • sge.BLEND_RGB_SCREEN
    • sge.BLEND_RGB_MINIMUM
    • sge.BLEND_RGB_MAXIMUM

    None is treated as sge.BLEND_NORMAL.

Sprite.draw_text(font, text, x, y, width=None, height=None, color='black', halign=2, valign=8, anti_alias=True, frame=None)

Draw text on the sprite.

Arguments:

  • font – The font to use to draw the text.
  • text – The text (as a string) to draw.
  • x – The horizontal location relative to the sprite to draw the text.
  • y – The vertical location relative to the sprite to draw the text.
  • width – The width of the imaginary rectangle the text is drawn in; set to None to make the rectangle as wide as needed to contain the text without additional line breaks. If set to something other than None, a line which does not fit will be automatically split into multiple lines that do fit.
  • height – The height of the imaginary rectangle the text is drawn in; set to None to make the rectangle as tall as needed to contain the text.
  • color – The color of the text.
  • halign – The horizontal alignment of the text and the horizontal location of the origin of the imaginary rectangle the text is drawn in. Can be set to one of the following:
    • sge.ALIGN_LEFT – Align the text to the left of the imaginary rectangle the text is drawn in. Set the origin of the imaginary rectangle to its left edge.
    • sge.ALIGN_CENTER – Align the text to the center of the imaginary rectangle the text is drawn in. Set the origin of the imaginary rectangle to its center.
    • sge.ALIGN_RIGHT – Align the text to the right of the imaginary rectangle the text is drawn in. Set the origin of the imaginary rectangle to its right edge.
  • valign – The vertical alignment of the text and the vertical location of the origin of the imaginary rectangle the text is drawn in. Can be set to one of the following:
    • sge.ALIGN_TOP – Align the text to the top of the imaginary rectangle the text is drawn in. Set the origin of the imaginary rectangle to its top edge. If the imaginary rectangle is not tall enough to contain all of the text, cut text off from the bottom.
    • sge.ALIGN_MIDDLE – Align the the text to the middle of the imaginary rectangle the text is drawn in. Set the origin of the imaginary rectangle to its middle. If the imaginary rectangle is not tall enough to contain all of the text, cut text off equally from the top and bottom.
    • sge.ALIGN_BOTTOM – Align the text to the bottom of the imaginary rectangle the text is drawn in. Set the origin of the imaginary rectangle to its top edge. If the imaginary rectangle is not tall enough to contain all of the text, cut text off from the top.
  • anti_alias – Whether or not anti-aliasing should be used.
  • frame – The frame of the sprite to draw on, where 0 is the first frame; set to None to draw on all frames.
Sprite.draw_erase(x, y, width, height, frame=None)

Erase part of the sprite.

Arguments:

  • x – The horizontal location relative to the sprite of the area to erase.
  • y – The vertical location relative to the sprite of the area to erase.
  • width – The width of the area to erase.
  • height – The height of the area to erase.
  • frame – The frame of the sprite to erase from, where 0 is the first frame; set to None to erase from all frames.
Sprite.draw_clear(frame=None)

Erase everything from the sprite.

Arguments:

  • frame – The frame of the sprite to clear, where 0 is the first frame; set to None to clear all frames.
Sprite.draw_lock()

Lock the sprite for continuous drawing.

Use this method to “lock” the sprite for being drawn on several times in a row. What exactly this does depends on the implementation and it may even do nothing at all, but calling this method before doing several draw actions on the sprite in a row gives the SGE a chance to make the drawing more efficient.

After you are done with continuous drawing, call sge.Sprite.draw_unlock() to let the SGE know that you are done drawing.

Warning

Do not cause a sprite to be used while it’s locked. For example, don’t leave it locked for the duration of a frame, and don’t draw it or project it on anything. The effect of using a locked sprite could be as minor as graphical errors and as severe as crashing the program, depending on the SGE implementation. Always call sge.Sprite.draw_unlock() immediately after you’re done drawing for a while.

Sprite.draw_unlock()

Unlock the sprite.

Use this method to “unlock” the sprite after it has been “locked” for continuous drawing by sge.Sprite.draw_lock().

Sprite.save(fname)

Save the sprite to an image file.

Arguments:

  • fname – The path of the file to save the sprite to. If it is not a path that can be saved to, IOError is raised.

If the sprite has multiple frames, the image file saved will be a horizontal reel of each of the frames from left to right with no space in between the frames.

Sprite.destroy()

Destroy the sprite.

Note

If the sprite is being used, for example, by a sge.StellarClass object, it will not be completely destroyed until this use stops.

classmethod Sprite.from_tileset(name, ID=None, x=0, y=0, columns=1, rows=1, xsep=0, ysep=0, width=1, height=1, origin_x=0, origin_y=0, transparent=True, fps=0, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None)

Return a sprite based on the tiles in a tileset.

Arguments:

  • name – The base name of the image file containing the tileset, not including the file extension, to be found in one of the paths specified in sge.image_directories.
  • x – The horizontal location relative to the image of the top-leftmost tile in the tileset.
  • y – The vertical location relative to the image of the top-leftmost tile in the tileset.
  • columns – The number of columns in the tileset.
  • rows – The number of rows in the tileset.
  • xsep – The spacing between columns in the tileset.
  • ysep – The spacing between rows in the tileset.
  • width – The width of the tiles.
  • height – The height of the tiles.

For all other arguments, see the documentation for Sprite.__init__().

Each tile in the tileset becomes a subimage of the returned sprite, ordered first from left to right and then from top to bottom.

classmethod Sprite.from_screenshot(x=0, y=0, width=None, height=None)

Return the current display on the screen as a sprite.

Arguments:

  • x – The horizontal location of the rectangular area to take a screenshot of.
  • y – The vertical location of the rectangular area to take a screenshot of.
  • width – The width of the area to take a screenshot of; set to None for all of the area to the right of x to be included.
  • height – The height of the area to take a screenshot of; set to None for all of the area below y to be included.

If you only wish to save a screenshot (of the entire screen) to a file, the easiest way to do that is:

sge.Sprite.from_screenshot().save("foo.png")

sge.BackgroundLayer

class sge.BackgroundLayer(sprite, x, y, z, ID=None, xscroll_rate=1, yscroll_rate=1, xrepeat=True, yrepeat=True)

Special class used for background layers.

This class stores a sprite and certain information for a layer of a background. In particular, it stores the location of the layer, whether the layer tiles horizontally, vertically, or both, and the rate at which it scrolls.

sprite

The sprite used for this layer. It will be animated normally if it contains multiple frames.

x

The horizontal location of the layer relative to the background.

y

The vertical location of the layer relative to the background.

z

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

xscroll_rate

The horizontal rate that the layer scrolls as a factor of the additive inverse of the horizontal movement of the view.

yscroll_rate

The vertical rate that the layer scrolls as a factor of the additive inverse of the vertical movement of the view.

xrepeat

Whether or not the layer should be repeated (tiled) horizontally.

yrepeat

Whether or not the layer should be repeated (tiled) vertically.

id

The unique identifier of the layer. (Read-only)

sge.BackgroundLayer Methods

BackgroundLayer.__init__(sprite, x, y, z, ID=None, xscroll_rate=1, yscroll_rate=1, xrepeat=True, yrepeat=True)

Constructor method.

Arguments:

  • ID – The value to set id to. If set to None, sprite.id will be used, modified by the SGE if it is already the unique identifier of another background layer.

All other arguments set the respective initial attributes of the layer. See the documentation for sge.BackgroundLayer for more information.

BackgroundLayer.destroy()

Destroy the background layer.

sge.Background

class sge.Background(layers, color, ID=None)

Background class.

This class stores the layers that make up the background (which contain the information about what images to use and where) as well as the color to use where no image is shown.

color

The color used in parts of the background where no layer is shown.

id

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

layers

A list containing all sge.BackgroundLayer objects used in this background. (Read-only)

sge.Background Methods

Background.__init__(layers, color, ID=None)

Constructor method.

Arguments:

  • ID – The value to set id to. If set to None, the SGE chooses the value.

All other arguments set the respective initial attributes of the background. See the documentation for sge.Background for more information.

sge.Sound

class sge.Sound(fname, ID=None, volume=100, max_play=1)

Sound handling class.

This class stores and plays sound effects. Note that this is inefficient for large music files; for those, use sge.Music instead.

What sound formats are supported depends on the implementation of the SGE, but sound formats that are generally a good choice are Ogg Vorbis and uncompressed WAV. See the implementation-specific information for a full list of supported formats.

volume

The volume of the sound in percent from 0 to 100 (0 for no sound, 100 for max sound).

max_play

The maximum number of instances of this sound playing permitted. If a sound is played while this number of the instances of the same sound are already playing, one of the already playing sounds will be stopped before playing the new instance. Set to None or 0 for no limit.

fname

The file name of the sound given when it was created. (Read-only)

length

The length of the sound in milliseconds. (Read-only)

playing

The number of instances of this sound playing. (Read-only)

sge.Sound Methods

Sound.__init__(fname, ID=None, volume=100, max_play=1)

Constructor method.

Arguments:

  • fname – The name of the sound file in one of the paths specified in sge.sound_directories. If set to None, this object will not actually play any sound. If this is neither a valid sound file nor None, IOError is raised.
  • 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 sound object.

All other arguments set the respective initial attributes of the sound. See the documentation for sge.Sound for more information.

Sound.play(loops=1, volume=100, balance=0, maxtime=None, fade_time=None)

Play the sound.

Arguments:

  • loops – The number of times to play the sound; set to None or 0 to loop indefinitely.
  • volume – The volume to play the sound at as a percentage of self.volume from 0 to 100 (0 for no sound, 100 for self.volume).
  • balance – The balance of the sound effect on stereo speakers as a float from -1 to 1, where 0 is centered (full volume in both speakers), 1 is entirely in the right speaker, and -1 is entirely in the left speaker.
  • maxtime – The maximum amount of time to play the sound in milliseconds; set to None or 0 for no limit.
  • fade_time – The time in milliseconds over which to fade the sound in; set to None or 0 to immediately play the sound at full volume.
Sound.stop(fade_time=None)

Stop the sound.

Arguments:

  • fade_time – The time in milliseconds over which to fade the sound out before stopping; set to None or 0 to immediately stop the sound.
Sound.pause()

Pause playback of the sound.

Sound.unpause()

Resume playback of the sound if paused.

Sound.destroy()

Destroy the sound.

static Sound.stop_all()

Stop playback of all sounds.

sge.Music

class sge.Music(fname, ID=None, volume=100)

Music handling class.

This class stores and plays music. Music is very similar to sound effects, but only one music file can be played at a time, and it is more efficient for larger files than sge.Sound.

What music formats are supported depends on the implementation of the SGE, but Ogg Vorbis is generally a good choice. See the implementation-specific information for a full list of supported formats.

Note

You should avoid the temptation to use MP3 files; MP3 is a patent-encumbered format, so many systems do not support it and royalties to the patent holders may be required for commercial use. There are many programs which can convert your MP3 files to the free Ogg Vorbis format.

volume

The volume of the music in percent from 0 to 100 (0 for no sound, 100 for maximum volume).

fname

The file name of the music given when it was created. (Read-only)

id

The unique identifier of the music. (Read-only)

length

The length of the music in milliseconds. (Read-only)

playing

Whether or not the music is playing. (Read-only)

position

The current position (time) playback of the music is at in milliseconds. (Read-only)

sge.Music Methods

Music.__init__(fname, ID=None, volume=100)

Constructor method.

Arguments:

  • fname – The name of the sound file in one of the paths specified in sge.music_directories. If set to None, this object will not actually play any music. If this is neither a valid sound file nor None, IOError is raised.
  • 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 idenfifier of another music object.

All other arguments set the respective initial attributes of the music. See the documentation for sge.Music for more information.

Music.play(start=0, loops=1, maxtime=None, fade_time=None)

Play the music.

Arguments:

  • start – The number of milliseconds from the beginning to start playing at.

See the documentation for sge.Sound.play() for more information.

Music.queue(start=0, loops=1, maxtime=None, fade_time=None)

Queue the music for playback.

This will cause the music to be added to a list of music to play in order, after the previous music has finished playing.

See the documentation for sge.Music.play() for more information.

Music.destroy()

Destroy the music.

static Music.stop(fade_time=None)

Stop the currently playing music.

See the documentation for sge.Sound.stop() for more information.

static Music.pause()

Pause playback of the currently playing music.

static Music.unpause()

Resume playback of the currently playing music if paused.

static Music.clear_queue()

Clear the music queue.

sge.Font

class sge.Font(name=None, ID=None, size=12, underline=False, bold=False, italic=False)

Font handling class.

This class stores a font for use by sge.Sprite.draw_text() and sge.Room.project_text().

Note that bold and italic rendering could be ugly. It is better to choose a bold or italic font rather than enabling bold or italic rendering, if possible.

size

The height of the font in pixels.

underline

Whether or not underlined rendering is enabled.

bold

Whether or not bold rendering is enabled.

Note

Using this option can be ugly. It is better to choose a bold font rather than enabling bold rendering, if possible.

italic

Whether or not italic rendering is enabled.

Note

Using this option can be ugly. It is better to choose an italic font rather than enabling italic rendering, if possible.

name

The name of the font as specified when it was created. (Read-only)

id

The unique identifier of the font. (Read-only)

sge.Font Methods

Font.__init__(name=None, ID=None, size=12, underline=False, bold=False, italic=False)

Constructor method.

Arguments:

  • name – The name of the font. Can be one of the following:

    • A string indicating the name of a font file located in one of the paths specified in sge.font_directories, e.g. "MyFont.ttf".
    • A string indicating the case-insensitive name of a system font, e.g. "Liberation Serif".
    • A list or tuple of strings indicating either a font file or a system font to choose from in order of preference.

    If none of the above methods return a valid font, the SGE will choose the font.

  • ID – The value to set id to. If set to None, name will be used, modified by the SGE if it is already the unique identifier of another font.

All other arguments set the respective initial attributes of the font. See the documentation for sge.Font for more information.

Note

It is generally not a good practice to rely on system fonts. A font which you have on your system is probably not on everyone’s system. For example, most Windows systems have a font called Times New Roman, but this font is not normally found on Debian systems. On the other hand, Debian has the Liberation fonts installed by default, but these fonts are uncommon on Windows systems. Rather than relying on system fonts, choose a font which is under a free license (such as the GNU General Public License or the SIL Open Font License) and distribute it with your game; this will ensure that everyone sees text rendered the same way you do.

Font.get_width(text, width=None, height=None)

Return the width of a certain string of text when rendered.

See the documentation for sge.Sprite.draw_text() for information about the arguments.

Font.get_height(text, width=None, height=None)

Return the height of a certain string of text when rendered.

See the documentation for sge.Sprite.draw_text() for information about the arguments.

classmethod Font.from_sprite(sprite, chars, ID=None, hsep=0, vsep=0, size=12, underline=False, bold=False, italic=False)

Return a font derived from a sprite.

Arguments:

  • sprite – The sge.Sprite object to derive the font from.
  • chars – A list of characters to set the sprite’s frames to. For example, ['A', 'B', 'C'] would assign the first frame to the letter “A”, the second frame to the letter “B”, and the third frame to the letter “C”. Any character not listed here will be rendered as its differently-cased counterpart if possible (e.g. “A” as “a”) or as a blank space otherwise.
  • ID – The value to set id to. If set to None, the name of the sprite will be used, modified by the SGE if it is already the unique identifier of another font.
  • hsep – The amount of horizontal space to place between characters when text is rendered.
  • vsep – The amount of vertical space to place between lines when text is rendered.

All other arguments set the respective initial attributes of the font. See the documentation for sge.Font for more information.

The font’s name attribute will be set to the name of the sprite the font is derived from.

The font’s size attribute will indicate the height of the characters in pixels. The width of the characters will be adjusted proportionally.

sge.StellarClass

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

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 perform collision events, set checks_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).

checks_collisions

Whether or not the object should check for collisions automatically and cause collision events. If an object is not using collision events, setting this to False will give a boost in performance.

Note

This will not prevent automatic collision detection by other objects from detecting this object, and it will also not prevent this object’s collision events from being executed. If you wish to disable collision detection entirely, set tangible to False.

tangible

Whether or not collisions involving the object can be detected. Setting this to False can improve performance if the object doesn’t need to be involved in 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).

Note

If this is False, checks_collisions is implied to be False as well regardless of its actual value. This is because checking for collisions which can’t be detected is meaningless.

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

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.

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.

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

StellarClass.get_alarm(alarm_id)

Return the value of an alarm.

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

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.

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

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.input.KeyPress for more information.

StellarClass.event_key_release(key)

Key release event.

See the documentation for sge.input.KeyRelease for more information.

StellarClass.event_mouse_move(x, y)

Mouse move event.

See the documentation for sge.input.MouseMove for more information.

StellarClass.event_mouse_button_press(button)

Mouse button press event.

See the documentation for sge.input.MouseButtonPress for more information.

StellarClass.event_mouse_button_release(button)

Mouse button release event.

See the documentation for sge.input.MouseButtonRelease for more information.

StellarClass.event_joystick_axis_move(js_name, js_id, axis, value)

Joystick axis move event.

See the documentation for sge.input.JoystickAxisMove for more information.

StellarClass.event_joystick_hat_move(js_name, js_id, hat, x, y)

Joystick hat move event.

See the documentation for sge.input.JoystickHatMove for more information.

StellarClass.event_joystick_trackball_move(js_name, js_id, ball, x, y)

Joystick trackball move event.

See the documentation for sge.input.JoystickTrackballMove for more information.

StellarClass.event_joystick_button_press(js_name, js_id, button)

Joystick button press event.

See the documentation for sge.input.JoystickButtonPress for more information.

StellarClass.event_joystick_button_release(js_name, js_id, button)

Joystick button release event.

See the documentation for sge.input.JoystickButtonRelease 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.

The object is considered to be inactive when active is False.

See the documentation for sge.input.KeyPress for more information.

StellarClass.event_inactive_key_release(key)

Key release event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.KeyRelease for more information.

StellarClass.event_inactive_mouse_move(x, y)

Mouse move event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.MouseMove for more information.

StellarClass.event_inactive_mouse_button_press(button)

Mouse button press event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.MouseButtonPress for more information.

StellarClass.event_inactive_mouse_button_release(button)

Mouse button release event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.MouseButtonRelease for more information.

StellarClass.event_inactive_joystick_axis_move(js_name, js_id, axis, value)

Joystick axis move event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.JoystickAxisMove for more information.

StellarClass.event_inactive_joystick_hat_move(js_name, js_id, hat, x, y)

Joystick hat move event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.JoystickHatMove for more information.

StellarClass.event_inactive_joystick_trackball_move(js_name, js_id, ball, x, y)

Joystick trackball move event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.JoystickTrackballMove for more information.

StellarClass.event_inactive_joystick_button_press(js_name, js_id, button)

Joystick button press event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.JoystickButtonPress for more information.

StellarClass.event_inactive_joystick_button_release(js_name, js_id, button)

Joystick button release event when this object is inactive.

The object is considered to be inactive when active is False.

See the documentation for sge.input.JoystickButtonRelease for more information.

StellarClass.event_paused_key_press(key, char)

Key press event when paused.

See the documentation for sge.input.KeyPress for more information.

StellarClass.event_paused_key_release(key)

Key release event when paused.

See the documentation for sge.input.KeyRelease for more information.

StellarClass.event_paused_mouse_move(x, y)

Mouse move event when paused.

See the documentation for sge.input.MouseMove for more information.

StellarClass.event_paused_mouse_button_press(button)

Mouse button press event when paused.

See the documentation for sge.input.MouseButtonPress for more information.

StellarClass.event_paused_mouse_button_release(button)

Mouse button release event when paused.

See the documentation for sge.input.MouseButtonRelease for more information.

StellarClass.event_paused_joystick_axis_move(js_name, js_id, axis, value)

Joystick axis move event when paused.

See the documentation for sge.input.JoystickAxisMove for more information.

StellarClass.event_paused_joystick_hat_move(js_name, js_id, hat, x, y)

Joystick hat move event when paused.

See the documentation for sge.input.JoystickHatMove for more information.

StellarClass.event_paused_joystick_trackball_move(js_name, js_id, ball, x, y)

Joystick trackball move event when paused.

See the documentation for sge.input.JoystickTrackballMove for more information.

StellarClass.event_paused_joystick_button_press(js_name, js_id, button)

Joystick button press event when paused.

See the documentation for sge.input.JoystickButtonPress for more information.

StellarClass.event_paused_joystick_button_release(js_name, js_id, button)

Joystick button release event when paused.

See the documentation for sge.input.JoystickButtonRelease for more information.

sge.Room

class sge.Room(objects=(), width=None, height=None, views=None, background=None, background_x=0, background_y=0, room_number=None)

Class for rooms.

This class stores the settings and objects found in a room. Rooms are used to create separate parts of the game, such as levels and menu screens.

Every game must have at least one room.

width

The width of the room in pixels. If set to None, sge.game.width is used.

height

The height of the room in pixels. If set to None, sge.game.height is used.

views

A list containing all sge.View objects in the room.

background

The sge.Background object used.

background_x

The horizontal position of the background in the room.

background_y

The vertical position of the background in the room.

objects

A list containing all sge.StellarClass objects in the room. (Read-only)

objects_by_class

A dictionary of lists containing all sge.StellarClass objects in the room, separated by class. The dictionary keys are classes that have been registered with sge.Game.register_class(), and the lists contain only those objects which are instances of the class indicated by the respective key. (Read-only)

room_number

The index of this room in the game, where 0 is the first room. (Read-only)

sge.Room Methods

Room.__init__(objects=(), width=None, height=None, views=None, background=None, background_x=0, background_y=0, room_number=None)

Constructor method.

Arguments:

  • views – A list containing all sge.View objects in the room. If set to None, a new view will be created with x=0, y=0, and all other arguments unspecified, which will become the first view of the room.
  • background – The sge.Background object used. If set to None, a new background will be created with no layers and the color set to "black".
  • room_number – The position in sge.game.rooms to insert this room into. If set to None, it will be appended to the end of the list.

All other arguments set the respective initial attributes of the room. See the documentation for sge.Room for more information.

Room.add(obj)

Add a StellarClass object to the room.

Arguments:

Room.start()

Start the room.

If the room has been changed, reset it to its original state.

Room.resume()

Continue the room from where it left off.

If the room is unchanged (e.g. has not been started yet), this method behaves in the same way that sge.Room.start() does.

Room.set_alarm(alarm_id, value)

Set an 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.Room.event_alarm() will be executed with alarm_id.

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

Room.get_alarm(alarm_id)

Return the value of an alarm.

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

Room.end(next_room=None, resume=True)

End the current room.

Arguments:

  • next_room – The room number of the room to go to next. If set to None, the room after this one is chosen.
  • resume – Whether or not to resume the next room instead of restarting it.

If the room chosen as the next room does not exist, the game is ended.

This triggers this room’s sge.Room.event_room_end() and resets the state of this room.

Room.project_dot(x, y, z, color)

Project a single-pixel dot onto the room.

Arguments:

  • x – The horizontal location relative to the room to project the dot.
  • y – The vertical location relative to the room to project the dot.
  • z – The Z-axis position of the projection in the room.

See the documentation for sge.Sprite.draw_dot() for more information.

Room.project_line(x1, y1, x2, y2, z, color, thickness=1, anti_alias=False)

Project a line segment onto the room.

Arguments:

  • x1 – The horizontal location relative to the room of the first endpoint of the projected line segment.
  • y1 – The vertical location relative to the room of the first endpoint of the projected line segment.
  • x2 – The horizontal location relative to the room of the second endpoint of the projected line segment.
  • y2 – The vertical location relative to the room of the second endpoint of the projected line segment.
  • z – The Z-axis position of the projection in the room.

See the documentation for sge.Sprite.draw_line() for more information.

Room.project_rectangle(x, y, z, width, height, fill=None, outline=None, outline_thickness=1)

Project a rectangle onto the room.

Arguments:

  • x – The horizontal location relative to the room to project the rectangle.
  • y – The vertical location relative to the room to project the rectangle.
  • z – The Z-axis position of the projection in the room.

See the documentation for sge.Sprite.draw_rectangle() for more information.

Room.project_ellipse(x, y, z, width, height, fill=None, outline=None, outline_thickness=1, anti_alias=False)

Project an ellipse onto the room.

Arguments:

  • x – The horizontal location relative to the room to position the imaginary rectangle containing the ellipse.
  • y – The vertical location relative to the room to position the imaginary rectangle containing the ellipse.
  • z – The Z-axis position of the projection in the room.
  • width – The width of the ellipse.
  • height – The height of the ellipse.
  • fill – The color of the fill of the ellipse.
  • outline – The color of the outline of the ellipse.
  • outline_thickness – The thickness of the outline of the ellipse.
  • anti_alias – Whether or not anti-aliasing should be used.

See the documentation for sge.Sprite.draw_ellipse() for more information.

Room.project_circle(x, y, z, radius, fill=None, outline=None, outline_thickness=1, anti_alias=False)

Project a circle onto the room.

Arguments:

  • x – The horizontal location relative to the room to position the center of the circle.
  • y – The vertical location relative to the room to position the center of the circle.
  • z – The Z-axis position of the projection in the room.

See the documentation for sge.Sprite.draw_circle() for more information.

Room.project_sprite(sprite, image, x, y, z, blend_mode=None)

Project a sprite onto the room.

Arguments:

  • x – The horizontal location relative to the room to project sprite.
  • y – The vertical location relative to the room to project sprite.
  • z – The Z-axis position of the projection in the room.

See the documentation for sge.Sprite.draw_sprite() for more information.

Room.project_text(font, text, x, y, z, width=None, height=None, color='black', halign=2, valign=8, anti_alias=True)

Project text onto the room.

Arguments:

  • x – The horizontal location relative to the room to project the text.
  • y – The vertical location relative to the room to project the text.
  • z – The Z-axis position of the projection in the room.

See the documentation for sge.Sprite.draw_text() for more information.

Room.move(room_number)

Move the room.

Arguments:

  • room_number – The new position in sge.game.rooms to insert this room into.
Room.destroy()

Destroy the room.

Note

If the room is being used, it will not be completely destroyed until this use stops.

sge.Room Event Methods

Room.event_room_start()

Room start event.

Called when the room starts. It is always called after any game start events and before any object create events occurring at the same time.

Room.event_room_resume()

Room resume event.

Called when the room resumes without being reset to its original state (i.e. via sge.Room.resume()).

Room.event_room_end()

Room end event.

Called when the room ends. It is always called before any game end events occurring at the same time.

Room.event_step(time_passed, delta_mult)

Room step event.

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

Room.event_alarm(alarm_id)

Alarm event.

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

Room.event_key_press(key, char)

Key press event.

See the documentation for sge.input.KeyPress for more information.

Room.event_key_release(key)

Key release event.

See the documentation for sge.input.KeyRelease for more information.

Room.event_mouse_move(x, y)

Mouse move event.

See the documentation for sge.input.MouseMove for more information.

Room.event_mouse_button_press(button)

Mouse button press event.

See the documentation for sge.input.MouseButtonPress for more information.

Room.event_mouse_button_release(button)

Mouse button release event.

See the documentation for sge.input.MouseButtonRelease for more information.

Room.event_joystick_axis_move(js_name, js_id, axis, value)

Joystick axis move event.

See the documentation for sge.input.JoystickAxisMove for more information.

Room.event_joystick_hat_move(js_name, js_id, hat, x, y)

Joystick hat move event.

See the documentation for sge.input.JoystickHatMove for more information.

Room.event_joystick_trackball_move(js_name, js_id, ball, x, y)

Joystick trackball move event.

See the documentation for sge.input.JoystickTrackballMove for more information.

Room.event_joystick_button_press(js_name, js_id, button)

Joystick button press event.

See the documentation for sge.input.JoystickButtonPress for more information.

Room.event_joystick_button_release(js_name, js_id, button)

Joystick button release event.

See the documentation for sge.input.JoystickButtonRelease for more information.

Room.event_gain_keyboard_focus()

Gain keyboard focus event.

See the documentation for sge.input.KeyboardFocusGain for more information.

Room.event_lose_keyboard_focus()

Lose keyboard focus event.

See the documentation for sge.input.KeyboardFocusLose for more information.

Room.event_gain_mouse_focus()

Gain mouse focus event.

See the documentation for sge.input.MouseFocusGain for more information.

Room.event_lose_mouse_focus()

Lose mouse focus event.

See the documentation for sge.input.MouseFocusLose for more information.

Room.event_close()

Close event.

This is always called before any sge.Game.event_close() occurring at the same time.

See the documentation for sge.input.QuitRequest for more information.

Room.event_paused_key_press(key, char)

Key press event when paused.

See the documentation for sge.input.KeyPress for more information.

Room.event_paused_key_release(key)

Key release event when paused.

See the documentation for sge.input.KeyRelease for more information.

Room.event_paused_mouse_move(x, y)

Mouse move event when paused.

See the documentation for sge.input.MouseMove for more information.

Room.event_paused_mouse_button_press(button)

Mouse button press event when paused.

See the documentation for sge.input.MouseButtonPress for more information.

Room.event_paused_mouse_button_release(button)

Mouse button release event when paused.

See the documentation for sge.input.MouseButtonRelease for more information.

Room.event_paused_joystick_axis_move(js_name, js_id, axis, value)

Joystick axis move event when paused.

See the documentation for sge.input.JoystickAxisMove for more information.

Room.event_paused_joystick_hat_move(js_name, js_id, hat, x, y)

Joystick hat move event when paused.

See the documentation for sge.input.JoystickHatMove for more information.

Room.event_paused_joystick_trackball_move(js_name, js_id, ball, x, y)

Joystick trackball move event when paused.

See the documentation for sge.input.JoystickTrackballMove for more information.

Room.event_paused_joystick_button_press(js_name, js_id, button)

Joystick button press event when paused.

See the documentation for sge.input.JoystickButtonPress for more information.

Room.event_paused_joystick_button_release(js_name, js_id, button)

Joystick button release event when paused.

See the documentation for sge.input.JoystickButtonRelease for more information.

Room.event_paused_gain_keyboard_focus()

Gain keyboard focus event when paused.

See the documentation for sge.input.KeyboardFocusGain for more information.

Room.event_paused_lose_keyboard_focus()

Lose keyboard focus event when paused.

See the documentation for sge.input.KeyboardFocusLose for more information.

Room.event_paused_gain_mouse_focus()

Gain mouse focus event when paused.

See the documentation for sge.input.MouseFocusGain for more information.

Room.event_paused_lose_mouse_focus()

Lose mouse focus event when paused.

See the documentation for sge.input.MouseFocusLose for more information.

Room.event_paused_close()

Close event when paused.

See the documentation for sge.Room.event_close() for more information.

sge.View

class sge.View(x, y, xport=0, yport=0, width=None, height=None)

Class for room views.

This class controls what the player sees in a room at any given time. Multiple views can exist in a room, and this can be used to create a split-screen effect.

x

The horizontal position of the view in the room. When set, if it brings the view outside of the room it is in, it will be re-adjusted so that the view is completely inside the room.

y

The vertical position of the view in the room. When set, if it brings the view outside of the room it is in, it will be re-adjusted so that the view is completely inside the room.

xport

The horizontal position of the view port on the screen.

yport

The vertical position of the view port on the screen.

width

The width of the view. When set, if it results in the view being outside of the room it is in, x will be adjusted so that the view is completely inside the room.

height

The height of the view. When set, if it results in the view being outside the room it is in, y will be adjusted so that the view is completely inside the room.

sge.View Methods

View.__init__(x, y, xport=0, yport=0, width=None, height=None)

Constructor method.

Arguments:

  • width – The width of the view. If set to None, it will be set such that the view port takes up all of the space that it can horizontally (i.e. sge.game.width - xport).
  • height – The height of the view. If set to None, it will be set such that the view port takes up all of the space that it can vertically (i.e. sge.game.height - yport).

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