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.
The width of the game’s display.
The height of the game’s display.
Whether or not the game should be in fullscreen.
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).
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.
Whether or not a smooth scaling algorithm (as opposed to a simple scaling algorithm such as nearest-neighbor) should be used.
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.
Whether or not delta timing should be used. Delta timing affects object speeds, animation rates, and alarms.
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.
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.
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.
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.
Whether or not collision events should be executed. Setting this to False will improve performence if collision events are not needed.
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.
A list containing all classes which have been registered with sge.Game.register_class(). (Read-only)
A dictionary containing all loaded sprites, indexed by the sprites’ sge.Sprite.id attributes. (Read-only)
A dictionary containing all loaded background layers, indexed by the layers’ sge.BackgroundLayer.id attributes. (Read-only)
A dictionary containing all loaded backgrounds, indexed by the backgrounds’ sge.Background.id attributes. (Read-only)
A dictionary containing all loaded fonts, indexed by the fonts’ sge.Font.id attributes. (Read-only)
A dictionary containing all loaded sounds, indexed by the sounds’ sge.Sound.id attributes. (Read-only)
A dictionary containing all loaded music, indexed by the music objects’ sge.Music.id attributes. (Read-only)
A dictionary containing all sge.StellarClass objects in the game, indexed by the objects’ sge.StellarClass.id attributes. (Read-only)
A list containing all rooms in order of their creation. (Read-only)
The room which is currently active. (Read-only)
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.
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.
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.
Properly end the game.
Pause the game.
Arguments:
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.
Unpause the game.
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.
Regulate the SGE’s running speed and return the time passed.
Arguments:
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.
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.
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.
Set an alarm.
Arguments:
After this method is called, value will reduce by 1 each frame (adjusted for delta timing if it is enabled) until it reaches 0, at which point sge.Game.event_alarm() will be executed with alarm_id.
Return the value of an alarm.
Arguments:
If the alarm has not been set, None will be returned.
Project a single-pixel dot onto the game window.
Arguments:
See the documentation for sge.Sprite.draw_dot() for more information.
Project a line segment onto the game window.
Arguments:
See the documentation for sge.Sprite.draw_line() for more information.
Project a rectangle onto the game window.
Arguments:
See the documentation for sge.Sprite.draw_rectangle() for more information.
Project an ellipse onto the game window.
Arguments:
See the documentation for sge.Sprite.draw_ellipse() for more information.
Project a circle onto the game window.
Arguments:
See the documentation for sge.Sprite.draw_circle() for more information.
Project a sprite onto the game window.
Arguments:
See the documentation for sge.Sprite.draw_sprite() for more information.
Project text onto the game window.
Arguments:
See the documentation for sge.Sprite.draw_text() for more information.
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 end event.
Called when the game ends. This is only called once and it is always the very last event method called.
Global step event.
Called once each frame.
Arguments:
Alarm event.
Called when the value of an alarm reaches 0.
Arguments:
Key press event.
See the documentation for sge.input.KeyPress for more information.
Key release event.
See the documentation for sge.input.KeyRelease for more information.
Mouse move event.
See the documentation for sge.input.MouseMove for more information.
Mouse button press event.
See the documentation for sge.input.MouseButtonPress for more information.
Mouse button release event.
See the documentation for sge.input.MouseButtonRelease for more information.
Joystick axis move event.
See the documentation for sge.input.JoystickAxisMove for more information.
Joystick hat move event.
See the documentation for sge.input.JoystickHatMove for more information.
Joystick trackball move event.
See the documentation for sge.input.JoystickTrackballMove for more information.
Joystick button press event.
See the documentation for sge.input.JoystickButtonPress for more information.
Joystick button release event.
See the documentation for sge.input.JoystickButtonRelease for more information.
Gain keyboard focus event.
See the documentation for sge.input.KeyboardFocusGain for more information.
Lose keyboard focus event.
See the documentation for sge.input.KeyboardFocusLose for more information.
Gain mouse focus event.
See the documentation for sge.input.MouseFocusGain for more information.
Lose mouse focus event.
See the documentation for sge.input.MouseFocusLose for more information.
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.
Default mouse collision event.
Proxy for sge.game.mouse.event_collision(). See the documentation for sge.StellarClass.event_collision() for more information.
Left mouse collision event.
Proxy for sge.game.mouse.event_collision_left(). See the documentation for sge.StellarClass.event_collision_left() for more information.
Right mouse collision event.
Proxy for sge.game.mouse.event_collision_right(). See the documentation for sge.StellarClass.event_collision_right() for more information.
Top mouse collision event.
Proxy for sge.game.mouse.event_collision_top(). See the documentation for sge.StellarClass.event_collision_top() for more information.
Bottom mouse collision event.
Proxy for sge.game.mouse.event_collision_bottom(). See the documentation for sge.StellarClass.event_collision_bottom() for more information.
Key press event when paused.
See the documentation for sge.input.KeyPress for more information.
Key release event when paused.
See the documentation for sge.input.KeyRelease for more information.
Mouse move event when paused.
See the documentation for sge.input.MouseMove for more information.
Mouse button press event when paused.
See the documentation for sge.input.MouseButtonPress for more information.
Mouse button release event when paused.
See the documentation for sge.input.MouseButtonRelease for more information.
Joystick axis move event when paused.
See the documentation for sge.input.JoystickAxisMove for more information.
Joystick hat move event when paused.
See the documentation for sge.input.JoystickHatMove for more information.
Joystick trackball move event when paused.
See the documentation for sge.input.JoystickTrackballMove for more information.
Joystick button press event when paused.
See the documentation for sge.input.JoystickButtonPress for more information.
Joystick button release event when paused.
See the documentation for sge.input.JoystickButtonRelease for more information.
Gain keyboard focus event when paused.
See the documentation for sge.input.KeyboardFocusGain for more information.
Lose keyboard focus event when paused.
See the documentation for sge.input.KeyboardFocusLose for more information.
Gain mouse focus event when paused.
See the documentation for sge.input.MouseFocusGain for more information.
Lose mouse focus event when paused.
See the documentation for sge.input.MouseFocusLose for more information.
Close event when paused.
See the documentation for sge.Game.event_close() for more information.
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.
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.
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.
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.
The suggested horizontal location of the origin relative to the left edge of the images.
The suggested vertical location of the origin relative to the top edge of the images.
The suggested rate in frames per second to animate the image at.
The suggested rate to animate the image at as a factor of sge.game.fps.
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).
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).
The width of the suggested bounding box.
The height of the suggested bounding box.
The name of the sprite given when it was created. (Read-only)
The unique identifier of the sprite. (Read-only)
The number of animation frames in the sprite. (Read-only)
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:
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.
Append a new blank frame to the end of the sprite.
Insert a new blank frame into the sprite.
Arguments:
Delete a frame from the sprite.
Arguments:
Draw a single-pixel dot on the sprite.
Arguments:
Draw a line segment on the sprite.
Arguments:
Draw a rectangle on the sprite.
Arguments:
Draw an ellipse on the sprite.
Arguments:
Draw a circle on the sprite.
Arguments:
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:
None is treated as sge.BLEND_NORMAL.
Draw text on the sprite.
Arguments:
Erase part of the sprite.
Arguments:
Erase everything from the sprite.
Arguments:
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.
Unlock the sprite.
Use this method to “unlock” the sprite after it has been “locked” for continuous drawing by sge.Sprite.draw_lock().
Save the sprite to an image file.
Arguments:
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.
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.
Return a sprite based on the tiles in a tileset.
Arguments:
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.
Return the current display on the screen as a sprite.
Arguments:
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")
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.
The sprite used for this layer. It will be animated normally if it contains multiple frames.
The horizontal location of the layer relative to the background.
The vertical location of the layer relative to the background.
The Z-axis position of the layer in the room.
The horizontal rate that the layer scrolls as a factor of the additive inverse of the horizontal movement of the view.
The vertical rate that the layer scrolls as a factor of the additive inverse of the vertical movement of the view.
Whether or not the layer should be repeated (tiled) horizontally.
Whether or not the layer should be repeated (tiled) vertically.
The unique identifier of the layer. (Read-only)
Constructor method.
Arguments:
All other arguments set the respective initial attributes of the layer. See the documentation for sge.BackgroundLayer for more information.
Destroy the background layer.
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.
The color used in parts of the background where no layer is shown.
The unique identifier for this background. (Read-only)
A list containing all sge.BackgroundLayer objects used in this background. (Read-only)
Constructor method.
Arguments:
All other arguments set the respective initial attributes of the background. See the documentation for sge.Background for more information.
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.
The volume of the sound in percent from 0 to 100 (0 for no sound, 100 for max sound).
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.
The file name of the sound given when it was created. (Read-only)
The length of the sound in milliseconds. (Read-only)
The number of instances of this sound playing. (Read-only)
Constructor method.
Arguments:
All other arguments set the respective initial attributes of the sound. See the documentation for sge.Sound for more information.
Play the sound.
Arguments:
Stop the sound.
Arguments:
Pause playback of the sound.
Resume playback of the sound if paused.
Destroy the sound.
Stop playback of all sounds.
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.
The volume of the music in percent from 0 to 100 (0 for no sound, 100 for maximum volume).
The file name of the music given when it was created. (Read-only)
The unique identifier of the music. (Read-only)
The length of the music in milliseconds. (Read-only)
Whether or not the music is playing. (Read-only)
The current position (time) playback of the music is at in milliseconds. (Read-only)
Constructor method.
Arguments:
All other arguments set the respective initial attributes of the music. See the documentation for sge.Music for more information.
Play the music.
Arguments:
See the documentation for sge.Sound.play() for more information.
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.
Destroy the music.
Stop the currently playing music.
See the documentation for sge.Sound.stop() for more information.
Pause playback of the currently playing music.
Resume playback of the currently playing music if paused.
Clear the music queue.
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.
The height of the font in pixels.
Whether or not underlined rendering is enabled.
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.
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.
The name of the font as specified when it was created. (Read-only)
The unique identifier of the font. (Read-only)
Constructor method.
Arguments:
name – The name of the font. Can be one of the following:
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.
Return the width of a certain string of text when rendered.
See the documentation for sge.Sprite.draw_text() for information about the arguments.
Return the height of a certain string of text when rendered.
See the documentation for sge.Sprite.draw_text() for information about the arguments.
Return a font derived from a sprite.
Arguments:
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.
Class for game objects.
This class is used for game objects, such as the player, enemies, bullets, and the HUD. Generally, each type of object has its own subclass of sge.StellarClass.
The horizontal position of the object in the room.
The vertical position of the object in the room.
The Z-axis position of the object in the room.
The sprite currently in use by this object. Set to None for no sprite.
Whether or not the object’s sprite should be projected onto the screen.
Indicates whether the object is active (True) or inactive (False). While the object is active, it will exhibit normal behavior; events will be executed normally as will any other automatic functionality, such as adding xvelocity and yvelocity to x and y. If active is False, automatic functionality and normal events will be disabled and events which have names starting with event_inactive_ will be executed instead of the corresponding normal events.
Note
Inactive sge.StellarClass objects are still visible by default and continue to be involved in collisions. In addition, collision events and destroy events still occur even if the object is inactive. If you wish for the object to not be visible, set visible to False. If you wish for the object to not 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).
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.
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.
The horizontal location of the bounding box relative to the object’s position. If set to None, the value recommended by the sprite is used.
The vertical location of the bounding box relative to the object’s position. If set to None, the value recommended by the sprite is used.
The width of the bounding box in pixels. If set to None, the value recommended by the sprite is used.
The height of the bounding box in pixels. If set to None, the value recommended by the sprite is used.
If set to True, the origin is automatically adjusted to be the location of the pixel recommended by the sprite after transformation. This will cause rotation to be about the origin rather than being about the center of the image.
Note
The value of this attribute has no effect on the bounding box. If you wish for the bounding box to be adjusted as well, you must do so manually. As an alternative, you may want to consider using precise collision detection instead.
Whether or not an ellipse (rather than a rectangle) should be used for collision detection.
Whether or not precise (pixel-perfect) collision detection should be used. Note that this can be inefficient and does not work well with animated sprites.
The position of the right side of the bounding box in the room (same as bbox_left + bbox_width).
The position of the bottom side of the bounding box in the room (same as bbox_top + bbox_height).
The velocity of the object toward the right.
The velocity of the object toward the bottom.
The total (directional) speed of the object.
The direction of the object’s movement in degrees, with 0 being directly to the right and rotation in a positive direction being counter-clockwise.
The animation frame currently being displayed, with 0 being the first one.
The horizontal location of the origin relative to the left edge of the images. If set to None, the value recommended by the sprite is used.
The vertical location of the origin relative to the top edge of the images. If set to None, the value recommended by the sprite is used.
The animation rate in frames per second. If set to None, the value recommended by the sprite is used.
The animation rate as a factor of sge.game.fps. If set to None, the value recommended by the sprite is used.
The horizontal scale factor for the sprite.
The vertical scale factor for the sprite.
The rotation of the sprite in degrees, with rotation in a positive direction being counter-clockwise.
If regulate_origin is True, the image is rotated about the origin. Otherwise, the image is rotated about its center.
The alpha value applied to the entire image, where 255 is the original image, 128 is half the opacity of the original image, 0 is fully transparent, etc.
The color to blend with the sprite. Set to None for no color blending.
The unique identifier for this object. (Read-only)
The current mask used for non-rectangular collision detection. See the documentation for sge.collision.masks_collide() for more information. (Read-only)
The horizontal location of the mask in the room. (Read-only)
The vertical location of the mask in the room. (Read-only)
Constructor method.
Arguments:
All other arugments set the respective initial attributes of the object. See the documentation for sge.StellarClass for more information.
Return a list of objects colliding with this object.
Arguments:
Set an alarm.
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.
Return the value of an alarm.
See the documentation for sge.Game.get_alarm() for more information.
Destroy the object.
Create an object of this class in the current room.
args and kwargs are passed to the constructor method of cls as arguments. Calling obj = cls.create(*args, **kwargs) is the same as:
obj = cls(*args, **kwargs)
sge.game.current_room.add(obj)
Create event.
Called when the object is created. It is always called after any room start events occurring at the same time.
Destroy event.
Step event.
This event is executed each frame after automatic updates to objects (such as the effects of the speed variables), but before collision events.
See the documentation for sge.Game.event_step() for more information.
Alarm event.
See the documentation for sge.Game.event_alarm() for more information.
Animation End event.
Called when an animation cycle ends.
Key press event.
See the documentation for sge.input.KeyPress for more information.
Key release event.
See the documentation for sge.input.KeyRelease for more information.
Mouse move event.
See the documentation for sge.input.MouseMove for more information.
Mouse button press event.
See the documentation for sge.input.MouseButtonPress for more information.
Mouse button release event.
See the documentation for sge.input.MouseButtonRelease for more information.
Joystick axis move event.
See the documentation for sge.input.JoystickAxisMove for more information.
Joystick hat move event.
See the documentation for sge.input.JoystickHatMove for more information.
Joystick trackball move event.
See the documentation for sge.input.JoystickTrackballMove for more information.
Joystick button press event.
See the documentation for sge.input.JoystickButtonPress for more information.
Joystick button release event.
See the documentation for sge.input.JoystickButtonRelease for more information.
Update position event.
Called when it’s time to update the position of the object. This method handles this functionality, so defining this will override the default behavior and allow you to handle the speed variables in a special way.
The default behavior of this method is:
self.x += self.xvelocity * delta_mult
self.y += self.yvelocity * delta_mult
See the documentation for sge.Game.event_step() for more information.
Default collision event.
Called when another object collides with this object and none of the directional collision events are appropriate. In particular, this is called if the collision was already happening in the previous frame. This is also the event method called by the directional collision event methods by default.
Arguments:
Left collision event.
Called when another object collides with this object’s left side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Right collision event.
Called when another object collides with this object’s right side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Top collision event.
Called when another object collides with this object’s top side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Bottom collision event.
Called when another object collides with this object’s bottom side.
Arguments:
By default, this method simply calls sge.StellarClass.event_collision().
Step event when this object is inactive.
See the documentation for sge.StellarClass.event_step() for more information. The object is considered to be inactive when active is False.
Key press event when this object is inactive.
The object is considered to be inactive when active is False.
See the documentation for sge.input.KeyPress for more information.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Key press event when paused.
See the documentation for sge.input.KeyPress for more information.
Key release event when paused.
See the documentation for sge.input.KeyRelease for more information.
Mouse move event when paused.
See the documentation for sge.input.MouseMove for more information.
Mouse button press event when paused.
See the documentation for sge.input.MouseButtonPress for more information.
Mouse button release event when paused.
See the documentation for sge.input.MouseButtonRelease for more information.
Joystick axis move event when paused.
See the documentation for sge.input.JoystickAxisMove for more information.
Joystick hat move event when paused.
See the documentation for sge.input.JoystickHatMove for more information.
Joystick trackball move event when paused.
See the documentation for sge.input.JoystickTrackballMove for more information.
Joystick button press event when paused.
See the documentation for sge.input.JoystickButtonPress for more information.
Joystick button release event when paused.
See the documentation for sge.input.JoystickButtonRelease for more information.
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.
The width of the room in pixels. If set to None, sge.game.width is used.
The height of the room in pixels. If set to None, sge.game.height is used.
The sge.Background object used.
The horizontal position of the background in the room.
The vertical position of the background in the room.
A list containing all sge.StellarClass objects in the room. (Read-only)
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)
The index of this room in the game, where 0 is the first room. (Read-only)
Constructor method.
Arguments:
All other arguments set the respective initial attributes of the room. See the documentation for sge.Room for more information.
Add a StellarClass object to the room.
Arguments:
Start the room.
If the room has been changed, reset it to its original state.
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.
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.
Return the value of an alarm.
See the documentation for sge.Game.get_alarm() for more information.
End the current room.
Arguments:
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.
Project a single-pixel dot onto the room.
Arguments:
See the documentation for sge.Sprite.draw_dot() for more information.
Project a line segment onto the room.
Arguments:
See the documentation for sge.Sprite.draw_line() for more information.
Project a rectangle onto the room.
Arguments:
See the documentation for sge.Sprite.draw_rectangle() for more information.
Project an ellipse onto the room.
Arguments:
See the documentation for sge.Sprite.draw_ellipse() for more information.
Project a circle onto the room.
Arguments:
See the documentation for sge.Sprite.draw_circle() for more information.
Project a sprite onto the room.
Arguments:
See the documentation for sge.Sprite.draw_sprite() for more information.
Project text onto the room.
Arguments:
See the documentation for sge.Sprite.draw_text() for more information.
Move the room.
Arguments:
Destroy the room.
Note
If the room is being used, it will not be completely destroyed until this use stops.
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 resume event.
Called when the room resumes without being reset to its original state (i.e. via sge.Room.resume()).
Room end event.
Called when the room ends. It is always called before any game end events occurring at the same time.
Room step event.
See the documentation for sge.Game.event_step() for more information.
Alarm event.
See the documentation for sge.Game.event_alarm() for more information.
Key press event.
See the documentation for sge.input.KeyPress for more information.
Key release event.
See the documentation for sge.input.KeyRelease for more information.
Mouse move event.
See the documentation for sge.input.MouseMove for more information.
Mouse button press event.
See the documentation for sge.input.MouseButtonPress for more information.
Mouse button release event.
See the documentation for sge.input.MouseButtonRelease for more information.
Joystick axis move event.
See the documentation for sge.input.JoystickAxisMove for more information.
Joystick hat move event.
See the documentation for sge.input.JoystickHatMove for more information.
Joystick trackball move event.
See the documentation for sge.input.JoystickTrackballMove for more information.
Joystick button press event.
See the documentation for sge.input.JoystickButtonPress for more information.
Joystick button release event.
See the documentation for sge.input.JoystickButtonRelease for more information.
Gain keyboard focus event.
See the documentation for sge.input.KeyboardFocusGain for more information.
Lose keyboard focus event.
See the documentation for sge.input.KeyboardFocusLose for more information.
Gain mouse focus event.
See the documentation for sge.input.MouseFocusGain for more information.
Lose mouse focus event.
See the documentation for sge.input.MouseFocusLose for more information.
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.
Key press event when paused.
See the documentation for sge.input.KeyPress for more information.
Key release event when paused.
See the documentation for sge.input.KeyRelease for more information.
Mouse move event when paused.
See the documentation for sge.input.MouseMove for more information.
Mouse button press event when paused.
See the documentation for sge.input.MouseButtonPress for more information.
Mouse button release event when paused.
See the documentation for sge.input.MouseButtonRelease for more information.
Joystick axis move event when paused.
See the documentation for sge.input.JoystickAxisMove for more information.
Joystick hat move event when paused.
See the documentation for sge.input.JoystickHatMove for more information.
Joystick trackball move event when paused.
See the documentation for sge.input.JoystickTrackballMove for more information.
Joystick button press event when paused.
See the documentation for sge.input.JoystickButtonPress for more information.
Joystick button release event when paused.
See the documentation for sge.input.JoystickButtonRelease for more information.
Gain keyboard focus event when paused.
See the documentation for sge.input.KeyboardFocusGain for more information.
Lose keyboard focus event when paused.
See the documentation for sge.input.KeyboardFocusLose for more information.
Gain mouse focus event when paused.
See the documentation for sge.input.MouseFocusGain for more information.
Lose mouse focus event when paused.
See the documentation for sge.input.MouseFocusLose for more information.
Close event when paused.
See the documentation for sge.Room.event_close() for more information.
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.
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.
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.
The horizontal position of the view port on the screen.
The vertical position of the view port on the screen.
Constructor method.
Arguments:
All other arugments set the respective initial attributes of the view. See the documentation for sge.View for more information.