Skip to content
wynand1004 edited this page Jun 27, 2017 · 29 revisions

Welcome to the SGE wiki!

A simple Python game engine used for creating simple 2D games. It is built on the Python Turtle module. It is compatible with Python 2.x and 3.x.

Overview:

The purpose of the Simple Game Engine is to give beginning Python coders a simple framework to make basic 2D games. It is intended as an alternative to Pygame. As it is built on the Turtle module, it has the same features and limitations of that module. It does not require any external libraries to be added.

Documentation:

SGE Class

Initial Game Setup:

from SGE import *
# WINDOW_WIDTH, WINDOW_HEIGHT, Background Color, and Window Title
game = SGE(800, 600, "blue", "SGE Game Demo") 

SGE Attributes

title # Window title text (string)
gravity # Game gravity constanst (float)
state # Game state (string) or None
FPS # Game FPS - default is 30 FPS (float)
SCREEN_WIDTH # Width of the screen in pixels (int)
SCREEN_HEIGHT # Height of the screen in pixels (int)
time # Time in seconds (float)

SGE Methods

Keyboard Bindings

game.set_keyboard_binding(key, function)

Built-in Key Definitions

SGE.KEY_UP = "Up"
SGE.KEY_DOWN = "Down"
SGE.KEY_LEFT = "Left"
SGE.KEY_RIGHT = "Right"
SGE.KEY_SPACE = "space"

set_title(title) game.set_title("My Game Title")

set_score(score) game.set_score(100)

update_screen() game.update_screen()

play_sound(soundfile) #.wav file game.play_sound("explosion.wav")

stop_all_sounds() game.stop_all_sounds()

clear_terminal_screen() game.clear_terminal_screen()

print_game_info() game.print_game_info()

is_collision(sprite_1, sprite_2) game.is_collision(player, enemy)

###SGE.Sprite Class

####Create a Sprite It is recommended to create child class first

class Player(SGE.Sprite):
    def __init__(self, shape, color, x, y):
        SGE.Sprite.__init__(self, shape, color, x, y)

Shape, Color, starting x coordinate, starting y coordinate

player = Player("triangle", "red", -400, 100)

####Sprite Attributes

dx # x velocity (float)
dy # y velocity (float)
speed # speed (float)
acceleration # acceleration (float)
width # width in pixels (float)
height # height in pixels (float)
state # object state - default is "active" (string) or None
friction # friction (float)
solid # (bool)

####Sprite Methods

Move

sprite.move()

Destroy

sprite.destroy()

Set Image

sprite.set_image("image.gif", width, height)

Follow me on Twitter @tokyoedtech

Various tutorials available on my YouTube Channel at https://www.youtube.com/channel/UC2vm-0XX5RkWCXWwtBZGOXg

Clone this wiki locally