def startEngine(options): """Start the main engine""" engine = serge.engine.Engine(width=G('screen-width'), height=G('screen-height'), title=G('screen-title'), fullscreen=options.fullscreen) serge.blocks.utils.createVirtualLayersForEngine(engine, ['background', 'foreground', 'foam', 'main', 'ropes', 'smoke', 'actors', 'trees', 'light', 'ui-back', 'ui-highlight', 'ui', 'overlay']) serge.blocks.utils.createWorldsForEngine(engine, ['start-screen', 'name-screen', 'main-screen', 'credits-screen', 'help-screen', 'collection-screen']) # if options.engine_profile: engine.profilingOn() # # The layers which don't move with the camera for layer in ('ui', 'ui-back', 'ui-highlight'): engine.getRenderer().getLayer(layer).setStatic(True) # # For the start screen we want to isolate the rope from the cave since they move independently so # we create two zones. world = engine.getWorld('start-screen') rope_zone = serge.zone.TagIncludeZone(['player', 'rope', 'rope-anchor', 'rope-link']) none_rope_zone = serge.zone.TagExcludeZone(['player', 'rope', 'rope-anchor', 'rope-link']) rope_zone.active = none_rope_zone.active = True rope_zone.physics_stepsize = 1.0 world.clearZones() world.addZone(rope_zone) world.addZone(none_rope_zone) # engine.setCurrentWorldByName('start-screen' if not options.skip else 'main-screen') return engine
def __init__(self, tag, name='', width=None, height=None, background_colour=None, background_layer=None, background_sprite=None, item_width=None, item_height=None): """Initialise the Bar""" super(Container, self).__init__(tag, name) # # Item widths and heights - you cannot specify these and the overall # dimension if (item_width and width) or (item_height and height): raise ValueError('Cannot specify both item height/width and overall height/width') # self.item_height = item_height self.item_width = item_width # # Default sizes are the extent of the screen engine = serge.engine.CurrentEngine() if width is None: width = engine.getRenderer().getScreenSize()[0] if height is None: height = engine.getRenderer().getScreenSize()[1] # # Set our size self.resizeTo(width, height) # # Set background if needed if background_colour: self.setBackgroundColour(background_colour) if background_sprite: self.setBackgroundSprite(background_sprite) self.background_layer = background_layer if background_layer else None
def __init__(self, tag, name='', width=None, height=None, background_colour=None, background_layer=None, background_sprite=None): """Initialise the Bar""" super(Container, self).__init__(tag, name) # # Default sizes are the extent of the screen engine = serge.engine.CurrentEngine() if width is None: width = engine.getRenderer().getScreenSize()[0] if height is None: height = engine.getRenderer().getScreenSize()[1] # # Set our size self.resizeTo(width, height) # # Set background if needed if background_colour: self.setBackgroundColour(background_colour) if background_sprite: self.setBackgroundSprite(background_sprite) self.background_layer = background_layer if background_layer else None
def __init__(self, tag, name='', width=None, height=None): """Initialise the Bar""" super(Container, self).__init__(tag, name) # # Default sizes are the extent of the screen engine = serge.engine.CurrentEngine() if width is None: width = engine.getRenderer().getScreenSize()[0] if height is None: height = engine.getRenderer().getScreenSize()[1] # # Set our size self.resizeTo(width, height) # Stored changes that we need to send to the world self._changes = []
def createLayers(engine, layers, cls): """Create a number of layers in the engine using the given class of layer""" renderer = engine.getRenderer() # # Find the right number of layers so that we can set the order correctly n = len(renderer.getLayers()) for name in layers: layer = cls(name, n) renderer.addLayer(layer) n += 1
def __init__(self, tag, name='', width=None, height=None, background_colour=None, background_layer=None, background_sprite=None, item_width=None, item_height=None): """Initialise the Bar""" super(Container, self).__init__(tag, name) # # Item widths and heights - you cannot specify these and the overall # dimension if (item_width and width) or (item_height and height): raise ValueError( 'Cannot specify both item height/width and overall height/width' ) # self.item_height = item_height self.item_width = item_width # # Default sizes are the extent of the screen engine = serge.engine.CurrentEngine() if width is None: width = engine.getRenderer().getScreenSize()[0] if height is None: height = engine.getRenderer().getScreenSize()[1] # # Set our size self.resizeTo(width, height) # # Set background if needed if background_colour: self.setBackgroundColour(background_colour) if background_sprite: self.setBackgroundSprite(background_sprite) self.background_layer = background_layer if background_layer else None
def startEngine(options): """Start the main engine""" engine = serge.engine.Engine(width=G('screen-width'), height=G('screen-height'), title=G('screen-title'), icon=G('screen-icon')) engine.getRenderer().addLayer(serge.blocks.visualeffects.FadingLayer('background', 0)) serge.blocks.utils.createVirtualLayersForEngine(engine, ['foreground', 'main', 'player', 'overlay']) engine.getRenderer().addLayer(serge.render.Layer('ui', 5)) engine.getRenderer().addLayer(serge.render.VirtualLayer('messages', 6)) serge.blocks.utils.createWorldsForEngine(engine, ['start-screen', 'main-screen', 'credit-screen', 'resume-screen', 'tutorial-screen', 'level-screen']) # engine.setCurrentWorldByName('start-screen') return engine
def main(options, args): """Run the game""" # # Debug options if options.any: game.Game.check_spelling = False if options.suggest: keypad.KeyPad.can_suggest = True gamestart.Start.possible_holes = map(int, options.holes.split(',')) ### Sounds ### serge.sound.Register.setPath('sound') r = serge.sound.Register.registerItem r('start', 'start.wav') r('begin', 'begin.wav') r('letter', 'letter.wav') r('word', 'word.wav') r('hole', 'hole.wav') r('good-hole', 'good_hole.wav') r('poor-hole', 'poor_hole.wav') r('unletter', 'unletter.wav') r('error', 'error.wav') r('bad-letter', 'badletter.wav') r('end-game', 'end_game.wav') r('sand', 'sand.wav') r('water', 'water.wav') ### Graphics ### serge.visual.Register.setPath('graphics') r = serge.visual.Register.registerItem rf = serge.visual.Register.registerFromFiles r('start-bg', 'start_bg.png') r('course', 'course1.png') r('hole2', 'hole1.png') r('hole1', 'hole1.png') r('logo', 'logo.png') rf('game1', 'game1_%d.png', 2) rf('game2', 'game2_%d.png', 2) rf('game3', 'game3_%d.png', 2) rf('button', 'button%d.png', 2) r('button_back', 'button_back.png') r('big_button_back', 'big_button.png') rf('letter', 'letter_%d.png', 2) r('help-page', 'helppage.png') r('escape-page', 'helppage.png') r('scores-page', 'scorespage.png') r('end-game-page', 'endgamepage.png') r('grass', 'grass.png') r('sand', 'sand.png') r('water', 'water.png') r('hole', 'hole.png') r('past', 'past.png') r('icon', 'wordgolf.ico') # thegame = game.Game(game.holes[0], 1, 3) engine = serge.engine.Engine(title='Word Golf', icon='icon') renderer = engine.getRenderer() course = serge.render.VirtualLayer('course', 0) renderer.addLayer(course) keys = serge.render.VirtualLayer('keys', 1) renderer.addLayer(keys) ui = serge.render.VirtualLayer('ui', 2) renderer.addLayer(ui) result = serge.render.VirtualLayer('results', 3) renderer.addLayer(result) camera = renderer.getCamera() camera.setSpatial(0, 0, 640, 480) ### The main world for the game ### game_world = serge.world.World('game') main = serge.zone.Zone() main.active = True game_world.addZone(main) pad = keypad.KeyPad(game_world, thegame) game_world.addActor(pad) ### The world for the end of game display ### end_world = serge.world.World('end') main = serge.zone.Zone() main.active = True end_world.addZone(main) game_over = gameover.Results(thegame, end_world) end_world.addActor(game_over) ### The world for the start of game display ### start_world = serge.world.World('start') main = serge.zone.Zone() main.active = True start_world.addZone(main) start = gamestart.Start(thegame, start_world) start_world.addActor(start) ### The world for help ### help_world = serge.world.World('help') z = serge.zone.Zone() z.active = True help_world.addZone(z) help = helppage.HelpPage(thegame, help_world) help_world.addActor(help) ### The world for escape ### escape_world = serge.world.World('escape') z = serge.zone.Zone() z.active = True escape_world.addZone(z) escape = escapepage.EscapePage(thegame, escape_world) escape_world.addActor(escape) ### The world for high scores ### scores_world = serge.world.World('scores') z = serge.zone.Zone() z.active = True scores_world.addZone(z) scores = scorespage.ScoresPage(thegame, scores_world) scores_world.addActor(escape) scores_world.activateWorld = scores.activateWorld # Tell the keypad about the high scores table pad.score = scores pad.gamestart = start scores.gamestart = start scores.pad = pad scores.updateTable() game_over.pad = pad game_over.results.visual.pad = pad engine.addWorld(start_world) engine.addWorld(end_world) engine.addWorld(game_world) engine.addWorld(help_world) engine.addWorld(escape_world) engine.addWorld(scores_world) engine.setCurrentWorld(start_world) thegame.tryHole() #serge.builder.builder.main(engine) engine.run(options.framerate)
self.zoom = 1.0 self.blue = blue def renderTo(self, interval, surface, (x, y)): """Render to the layer""" colour_index = min(int(self.growth), len(self.colours)-1) colour = list(self.colours[colour_index]) colour[2] = self.blue pygame.draw.circle(surface, tuple(colour), (x, y), self.size*self.zoom) def scaleBy(self, factor): """Scale the image by a factor""" self.zoom *= factor engine = serge.engine.Engine() renderer = engine.getRenderer() layer = serge.render.Layer('base', 0) renderer.addLayer(layer) camera = renderer.getCamera() camera.setSpatial(0, 0, 600, 600) world = serge.world.World('surface') main = serge.zone.Zone() main.setSpatial(-6000, -6000, 12000, 12000) main.active = True world.addZone(main) engine.addWorld(world) engine.setCurrentWorld(world) gc = [(0, i, 0, i) for i in range(255)] + \
def main(options, args): """Start the engine and the game""" # # For ropes and things we typically need a higher number of iterations serge.zone.PHYSICS_ITERATIONS = 100 # # Create the engine engine = startEngine(options) engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow) # registerSounds() registerMusic() registerGraphics() registerEvents() # # Change theme settings if options.theme: theme.updateFromString(options.theme) # # Muting mute = serge.blocks.actors.MuteButton('mute-button', 'ui', alpha=G('mute-button-alpha')) serge.blocks.utils.addMuteButtonToWorlds(mute, center_position=G('mute-button-position')) # if options.musicoff: mute.toggleSound() # # Initialise the main logic globals = serge.blocks.singletons.Store.registerItem('globals') globals.history = history.History('history', 'history') globals.last_cave_name = 'RANDOM-CAVE' # registerAchievements(options) if options.skip: mainscreen.main(options) else: startscreen.main(options) # # Force a rendering of the overlay - this puts # up the "loading ..." screen so the user has something # to see while we create the cave and trees etc w = engine.getWorld('start-screen') w.log.info('Rendering overlay') w.renderTo(engine.getRenderer(), 1000) engine.getRenderer().render() pygame.display.flip() # helpscreen.main(options) creditsscreen.main(options) namescreen.main(options) collectionscreen.main(options) # # if options.movie: serge.blocks.utils.RecordDesktop(options.movie) if options.debug: serge.builder.builder.main(engine, options.framerate) else: try: engine.run(options.framerate) except: # Make sure this event is raised so that any workers can be killed engine.processEvent((serge.events.E_BEFORE_STOP, None)) raise # # Display profile statistic if needed if options.engine_profile: prof = engine.getProfiler() data = [(prof.byTag(n).get('renderActor', (0,0))[1], n) for n in prof.getTags()] data.sort() data.reverse() print '\n\nEngine profiling\n\nTag\tTime(s)' for tme, tag in data: print '%s\t%s' % (tag, tme) print '\n\n'