def main(): # Create Game object game = Game() # Load sprites circle_sprite = sge.Sprite('circle', width=64, height=64, origin_x=32, origin_y=32) circle_pop_sprite = sge.Sprite('circle_pop', width=64, height=64, origin_x=32, origin_y=32, fps=60) fence_sprite = sge.Sprite('fence') # Load backgrounds layers = (sge.BackgroundLayer(fence_sprite, 0, 380, 0, yrepeat=False), ) layers2 = (sge.BackgroundLayer(fence_sprite, 0, 0, 0), ) background = sge.Background(layers, 0xffffff) background2 = sge.Background(layers2, 'white') # Load fonts glob.font = sge.Font('Liberation Serif', 20) # Load sounds glob.pop_sound = sge.Sound('pop.ogg') # Load music glob.music = sge.Music('WhereWasI.ogg') # Create objects circle = Circle(game.width // 2, game.height // 2) circle2 = Circle(22, 48) circle3 = Circle(486, 301) circle4 = Circle(50, 400) circle5 = Circle(game.width // 2, game.height // 2) circle6 = Circle(52, 120) objects = (circle, circle2, circle3, circle4) objects2 = (circle5, circle6) # Create view views = (sge.View(0, 0), ) # Create rooms room1 = Room('I am the first room!', objects, views=views, background=background) room2 = Room('Second room on the house!', objects2, background=background2) game.start()
def main(): # Create Game object Game(width=640, height=480) # Load sprites sge.Sprite('circle', width=32, height=32, origin_x=16, origin_y=16) fence = sge.Sprite('fence') # Load backgrounds layers = (sge.BackgroundLayer(fence, 0, 0, 0), ) background = sge.Background(layers, 'white') # Create objects objects = [] for i in xrange(4): circle = Circle(64, 64, i) objects.append(circle) # Create views views = [] for x in xrange(2): for y in xrange(2): views.append(sge.View(0, 0, 320 * x, 240 * y, 320, 240)) # Create rooms sge.Room(tuple(objects), 1280, 1024, tuple(views), background) sge.game.start()
def main(): # Create Game object game = Game(delta=True) # Load sprites sge.Sprite('rotator') fence_sprite = sge.Sprite('fence') # Load backgrounds layers = (sge.BackgroundLayer(fence_sprite, 0, 380, 0, yrepeat=False),) background = sge.Background(layers, 0xffffff) # Create objects circle = Circle(game.width // 2, game.height // 2) circle2 = Circle(22, 48) circle3 = Circle(486, 301) circle4 = Circle(50, 400) objects = (circle, circle2, circle3, circle4) # Create view views = (sge.View(0, 0),) # Create rooms room1 = sge.Room(objects, views=views, background=background) game.start()
def main(): # Create Game object game = Game() # Load sprites circle_sprite = sge.Sprite('circle', width=64, height=64, origin_x=32, origin_y=32) fence_sprite = sge.Sprite('fence') # Load backgrounds layers = (sge.BackgroundLayer(fence_sprite, 0, 380, 0, yrepeat=False), ) background = sge.Background(layers, 0xffffff) # Create objects circle = Circle(game.width // 2, game.height // 2) objects = [circle] # Create view views = (sge.View(0, 0), ) # Create rooms room1 = sge.Room(tuple(objects), views=views, background=background) game.start()
def load_resources(): """Load or reload the sprites, backgrounds, and objects.""" if glob.game_file is not None: with open(glob.game_file, 'r') as f: config = json.read(f) # Read globals (for purpose of evaluation), using the editors # globals as a base. glob.game_globals = globals() constants = config.setdefault("constants", []) globalvars = config.setdefault("global_variables", []) for var in constants + globalvars: name, value = var.split("=") name = name.strip() game_globals[name] = eval(value, game_globals) # Load sprites glob.sprites = [] sprites = config.setdefault("sprites", []) for sprite in sprites: name = eval(str(sprite.setdefault("name")), glob.game_globals) id_ = eval(str(sprite.setdefault("id")), glob.game_globals) width = eval(str(sprite.setdefault("width")), glob.game_globals) height = eval(str(sprite.setdefault("height")), glob.game_globals) origin_x = eval(str(sprite.setdefault("origin_x", 0)), glob.game_globals) origin_y = eval(str(sprite.setdefault("origin_y", 0)), glob.game_globals) transparent = eval(str(sprite.setdefault("transparent", True)), glob.game_globals) fps = eval(str(sprite.setdefault("fps", 60)), glob.game_globals) bbox_x = eval(str(sprite.setdefault("bbox_x")), glob.game_globals) bbox_y = eval(str(sprite.setdefault("bbox_y")), glob.game_globals) bbox_width = eval(str(sprite.setdefault("bbox_width")), glob.game_globals) bbox_height = eval(str(sprite.setdefault("bbox_height")), glob.game_globals) s = sge.Sprite(name, id_, width, height, origin_x, origin_y, transparent, fps, bbox_x, bbox_y, bbox_width, bbox_height) glob.sprites.append(s) # Load backgrounds background_layers = config.setdefault("background_layers", []) for layer in background_layers: sprite = eval( str( layer.setdefault("sprite", '"stellar_room_editor_no_sprite"')), glob.game_globals) x = eval(str(layer.setdefault("x", 0)), glob.game_globals) y = eval(str(layer.setdefault("y", 0)), glob.game_globals) z = eval(str(layer.setdefault("z", 0)), glob.game_globals) id_ = eval(str(layer.setdefault("id")), glob.game_globals) xscroll_rate = eval(str(layer.setdefault("xscroll_rate", 1)), glob.game_globals) yscroll_rate = eval(str(layer.setdefault("yscroll_rate", 1)), glob.game_globals) xrepeat = eval(str(layer.setdefault("xrepeat", True)), glob.game_globals) yrepeat = eval(str(layer.setdefault("yrepeat", True)), glob.game_globals) sge.BackgroundLayer(sprite, x, y, z, id_, xscroll_rate, yscroll_rate, xrepeat, yrepeat) backgrounds = config.setdefault("backgrounds", []) for background in backgrounds: layers = [] color = eval(str(background.setdefault("color", '"white"')), glob.game_globals) id_ = eval(str(background.setdefault("id")), glob.game_globals) for layer in background.setdefault("layers", []): layers.append(eval(str(layer), glob.game_globals)) sge.Background(layers, color, id_) # Load class defaults glob.defaults = {} classes = config.setdefault("classes", {}) for i in classes: glob.defaults[i] = {} methods = classes[i].setdefault("methods", []) for method in methods: if method.setdefault("name") == "__init__": args = method.setdefault("arguments", []) for arg in args: if "=" in arg: name, value = arg.split("=") name = name.strip() value = value.strip() glob.defaults[i][name] = str(value)
def main(): # Create Game object Game(640, 480, fps=120) # Load sprites paddle_sprite = sge.Sprite(ID="paddle", width=8, height=48, origin_x=4, origin_y=24) paddle_sprite.draw_rectangle(0, 0, paddle_sprite.width, paddle_sprite.height, fill="white") ball_sprite = sge.Sprite(ID="ball", width=8, height=8, origin_x=4, origin_y=4) ball_sprite.draw_rectangle(0, 0, ball_sprite.width, ball_sprite.height, fill="white") glob.hud_sprite = sge.Sprite(width=320, height=160, origin_x=160, origin_y=0) # Load backgrounds layers = (sge.BackgroundLayer("ball", sge.game.width / 2, 0, -10000, xrepeat=False), ) background = sge.Background(layers, "black") # Load fonts sge.Font('Liberation Mono', ID="hud", size=48) # Load sounds glob.bounce_sound = sge.Sound('bounce.wav') glob.bounce_wall_sound = sge.Sound('bounce_wall.wav') glob.score_sound = sge.Sound('score.wav') # Create objects Player(1) Player(2) glob.ball = Ball() hud = sge.StellarClass(sge.game.width / 2, 0, -10, sprite=glob.hud_sprite, detects_collisions=False) objects = (glob.player1, glob.player2, glob.ball, hud) # Create rooms room1 = sge.Room(objects, background=background) sge.game.start()
def main(): # Create Game object Game(480, 800) # Load sprites sge.Sprite('1945_enemybullet', origin_x=3, origin_y=3, transparent=True, bbox_x=-3, bbox_y=-3) sge.Sprite('1945_enemyplane_blue', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_blue_flip', origin_x=16, origin_y=16, transparent=True, fps=6, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_blue_flipped', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_dkgreen', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_dkgreen_flip', origin_x=16, origin_y=16, transparent=True, fps=6, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_dkgreen_flipped', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_green', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_green_flip', origin_x=16, origin_y=16, transparent=True, fps=6, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_green_flipped', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_orange', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_white', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_white_flip', origin_x=16, origin_y=16, transparent=True, fps=6, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_enemyplane_white_flipped', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_explosion_large', origin_x=32, origin_y=23, transparent=True, fps=5) sge.Sprite('1945_explosion_small', origin_x=16, origin_y=16, transparent=True, fps=6) sge.Sprite('1945_friendlyplane', origin_x=16, origin_y=16, transparent=True, fps=4, bbox_x=-16, bbox_y=-16) sge.Sprite('1945_gameover', origin_x=97, origin_y=6, transparent=True, fps=4) sge.Sprite('1945_getready', origin_x=98, origin_y=6, transparent=True, fps=4) sge.Sprite('1945_hud', origin_y=64, transparent=True) sge.Sprite('1945_hud_life', origin_x=13, origin_y=10, transparent=True, bbox_x=-13, bbox_y=-10) sge.Sprite('1945_hud_shieldbar') sge.Sprite('1945_islands', origin_x=32, origin_y=32, transparent=True, fps=0) sge.Sprite('1945_main_menu', transparent=True) sge.Sprite('1945_numbers', transparent=True, fps=0) sge.Sprite('1945_playerbullet', origin_x=3, origin_y=8, transparent=True, bbox_x=-3, bbox_y=-8) sge.Sprite('1945_playerplane', origin_x=29, origin_y=12, transparent=True, fps=4, bbox_x=-29, bbox_y=-12) sge.Sprite('1945_powerup_backguns', origin_x=16, origin_y=10, transparent=True, bbox_x=-16, bbox_y=-10) sge.Sprite('1945_powerup_backup', origin_x=15, origin_y=7, transparent=True, bbox_x=-15, bbox_y=-7) sge.Sprite('1945_powerup_bomb', origin_x=5, origin_y=11, transparent=True, bbox_x=-5, bbox_y=-11) sge.Sprite('1945_powerup_extralife', origin_x=11, origin_y=9, transparent=True, bbox_x=-11, bbox_y=-9) sge.Sprite('1945_powerup_shield', origin_x=10, origin_y=14, transparent=True, bbox_x=-10, bbox_y=-14) sge.Sprite('1945_powerup_sideguns', origin_x=16, origin_y=7, transparent=True, bbox_x=-16, bbox_y=-7) sge.Sprite('1945_powerup_spreadguns', origin_x=16, origin_y=12, transparent=True, bbox_x=-16, bbox_y=-12) sge.Sprite('1945_selection_arrow', origin_x=6, origin_y=6, transparent=True) sge.Sprite('1945_title') sge.Sprite('1945_water', fps=2) # Load backgrounds water_layer = sge.BackgroundLayer('1945_water', 0, 0, -10000) layers = (water_layer, ) background = sge.Background(layers, "#083681") # Load sounds #TODO # Load music glob.music = sge.Music("DST-TowerDefenseTheme.ogg") # Create objects #TODO objects = () # Create rooms sge.Room(objects, background=background) sge.game.start()