def selectLevel(self, obj, level_number): """Select a level number""" self.log.info('Selected level %d' % level_number) serge.sound.Sounds.play('click') world = self.engine.getWorld('main-screen') controller = world.findActorByName('main-screen') controller.current_level = level_number controller.restartGame() common.tweenWorlds('main-screen')() common.LEVEL_IN_PROGRESS = True
def addedToWorld(self, world): """The level screen was added to the world""" super(LevelScreen, self).addedToWorld(world) # # Logo the_theme = theme.getTheme('level-screen') L = the_theme.getProperty logo = serge.blocks.utils.addSpriteActorToWorld(world, 'logo', 'logo', 'logo', 'foreground', center_position=L('logo-position')) title = serge.blocks.utils.addSpriteActorToWorld(world, 'logo', 'title', 'title', 'foreground', center_position=L('title-position')) bg = serge.blocks.utils.addSpriteActorToWorld( world, 'bg', 'bg', 'dark-background', layer_name='background', center_position=(G('screen-width') / 2, G('screen-height') / 2), ) # # Find all the levels levels = common.levels.LEVEL_FILES[:-1] self.level_grid = serge.blocks.utils.addActorToWorld( world, serge.blocks.layout.MultiGrid('grid', 'grid', size=L('grid-size'), width=L('grid-width'), height=L('grid-height')), center_position=L('grid-position'), layer_name='ui', ) w, h = self.level_grid.getSize() for idx in range(1, len(levels) + 1): x, y = ((idx - 1) % w, (idx - 1) // w) tile = self.level_grid.addActor( (x, y), serge.actor.Actor('tile', 'tile-%s' % idx), ) if self.options.test: tile.setSpriteName('general-board') else: tile.setSpriteName('level-%d' % idx) tile.linkEvent(serge.events.E_LEFT_CLICK, self.selectLevel, idx) title = self.level_grid.addActor( (x, y), serge.blocks.actors.StringText( 'title', 'title-%s' % idx, common.levels.LEVELS[idx - 1][0], colour=L('title-colour'), font_name=L('title-font'), font_size=int(L('title-font-size') * (0.5 if self.options.test else 1.0))), ) title.y += L('title-offset-y') # # Random level button random_level = serge.blocks.utils.addSpriteActorToWorld( world, 'random-level', 'random-level', 'random-level', layer_name='ui', center_position=L('random-level-position'), actor_class=serge.actor.MountableActor, ) random_level.linkEvent(serge.events.E_LEFT_CLICK, common.tweenWorlds('random-level-screen')) # random_title = random_level.mountActor( serge.blocks.actors.StringText( 'title', 'title-random', 'Random Generated Maze', colour=L('title-colour'), font_name=L('title-font'), font_size=int(L('title-font-size') * (0.5 if self.options.test else 1.0))), (0, L('title-offset-y')) ) random_title.setLayerName('ui') # Back button back = serge.blocks.utils.addSpriteActorToWorld( world, 'back', 'back', 'back', layer_name='ui', center_position=L('back-position'), ) back.linkEvent(serge.events.E_LEFT_CLICK, common.tweenBackWorlds('start-screen')) # # Resume button self.resume = serge.blocks.utils.addSpriteActorToWorld( world, 'resume', 'resume', 'resume', layer_name='ui', center_position=L('resume-position'), ) self.resume.linkEvent(serge.events.E_LEFT_CLICK, common.tweenWorlds('main-screen')) # # Events world.linkEvent(serge.events.E_ACTIVATE_WORLD, self.activatedWorld) world.linkEvent(serge.events.E_DEACTIVATE_WORLD, self.deactivatedWorld)
def addedToWorld(self, world): """The level screen was added to the world""" super(RandomLevelScreen, self).addedToWorld(world) # # Logo the_theme = theme.getTheme('random-level-screen') L = the_theme.getProperty logo = serge.blocks.utils.addSpriteActorToWorld(world, 'logo', 'logo', 'logo', 'foreground', center_position=L('logo-position')) title = serge.blocks.utils.addSpriteActorToWorld(world, 'logo', 'title', 'title', 'foreground', center_position=L('title-position')) bg = serge.blocks.utils.addSpriteActorToWorld( world, 'bg', 'bg', 'dark-background', layer_name='background', center_position=(G('screen-width') / 2, G('screen-height') / 2), ) # Preview of level self.level_preview = serge.blocks.utils.addVisualActorToWorld( world, 'level-preview', 'level-preview', serge.visual.SurfaceDrawing( L('level-preview-width'), L('level-preview-height'), ), layer_name='ui', center_position=L('level-preview-position'), ) # # Size menu self.size_options = L('size-options') self.size_menu = serge.blocks.utils.addActorToWorld( world, serge.blocks.actors.ToggledMenu( 'size-menu', 'size-menu', ['Small', 'Medium', 'Large'], serge.blocks.layout.VerticalBar( 'bar', 'bar', L('size-width'), L('size-height'), ), default='Medium', on_colour=L('menu-on-colour'), off_colour=L('menu-off-colour'), callback=self.sizeSelected, font_colour=L('menu-font-colour'), mouse_over_colour=L('menu-mouse-over-colour'), font_size=L('size-font-size'), font_name=L('menu-font'), width=L('size-item-width'), height=L('size-item-height'), ), center_position=L('size-position'), layer_name='ui' ) # # Amount of open space menu self.space_options = L('space-options') self.space_menu = serge.blocks.utils.addActorToWorld( world, serge.blocks.actors.ToggledMenu( 'space-menu', 'space-menu', ['Open', 'Blocked'], serge.blocks.layout.VerticalBar( 'bar', 'bar', L('space-width'), L('space-height'), ), default='Open', on_colour=L('menu-on-colour'), off_colour=L('menu-off-colour'), callback=self.spaceSelected, font_colour=L('menu-font-colour'), mouse_over_colour=L('menu-mouse-over-colour'), font_size=L('space-font-size'), height=L('space-item-height'), font_name=L('menu-font'), width=L('space-item-width'), ), center_position=L('space-position'), layer_name='ui' ) # Generate button generate = serge.blocks.utils.addSpriteActorToWorld( world, 'generate', 'generate', 'generate', layer_name='ui', center_position=L('generate-position'), ) generate.linkEvent(serge.events.E_LEFT_CLICK, self.generateLevel) # Select button select = serge.blocks.utils.addSpriteActorToWorld( world, 'select', 'select', 'select', layer_name='ui', center_position=L('select-position'), ) select.linkEvent(serge.events.E_LEFT_CLICK, self.selectLevel) # # Resume button self.resume = serge.blocks.utils.addSpriteActorToWorld( world, 'resume', 'resume', 'resume', layer_name='ui', center_position=L('resume-position'), ) self.resume.linkEvent(serge.events.E_LEFT_CLICK, common.tweenWorlds('main-screen')) # Back button back = serge.blocks.utils.addSpriteActorToWorld( world, 'back', 'back', 'back', layer_name='ui', center_position=L('back-position'), ) back.linkEvent(serge.events.E_LEFT_CLICK, common.tweenBackWorlds('level-screen')) # # Smack talking self.smack = smacktalker.RandomlyAppearingSmacker('smack', 'smack', 'random-level-screen', 'waiting-for-random-level') world.addActor(self.smack) self.smack.visible = False # self.initialised = True self.generateLevel() # # Events world.linkEvent(serge.events.E_ACTIVATE_WORLD, self.activatedWorld)
def addedToWorld(self, world): """The level screen was added to the world""" super(LevelScreen, self).addedToWorld(world) # # Logo the_theme = theme.getTheme('level-screen') L = the_theme.getProperty logo = serge.blocks.utils.addSpriteActorToWorld( world, 'logo', 'logo', 'logo', 'foreground', center_position=L('logo-position')) title = serge.blocks.utils.addSpriteActorToWorld( world, 'logo', 'title', 'title', 'foreground', center_position=L('title-position')) bg = serge.blocks.utils.addSpriteActorToWorld( world, 'bg', 'bg', 'dark-background', layer_name='background', center_position=(G('screen-width') / 2, G('screen-height') / 2), ) # # Find all the levels levels = common.levels.LEVEL_FILES[:-1] self.level_grid = serge.blocks.utils.addActorToWorld( world, serge.blocks.layout.MultiGrid('grid', 'grid', size=L('grid-size'), width=L('grid-width'), height=L('grid-height')), center_position=L('grid-position'), layer_name='ui', ) w, h = self.level_grid.getSize() for idx in range(1, len(levels) + 1): x, y = ((idx - 1) % w, (idx - 1) // w) tile = self.level_grid.addActor( (x, y), serge.actor.Actor('tile', 'tile-%s' % idx), ) if self.options.test: tile.setSpriteName('general-board') else: tile.setSpriteName('level-%d' % idx) tile.linkEvent(serge.events.E_LEFT_CLICK, self.selectLevel, idx) title = self.level_grid.addActor( (x, y), serge.blocks.actors.StringText( 'title', 'title-%s' % idx, common.levels.LEVELS[idx - 1][0], colour=L('title-colour'), font_name=L('title-font'), font_size=int( L('title-font-size') * (0.5 if self.options.test else 1.0))), ) title.y += L('title-offset-y') # # Random level button random_level = serge.blocks.utils.addSpriteActorToWorld( world, 'random-level', 'random-level', 'random-level', layer_name='ui', center_position=L('random-level-position'), actor_class=serge.actor.MountableActor, ) random_level.linkEvent(serge.events.E_LEFT_CLICK, common.tweenWorlds('random-level-screen')) # random_title = random_level.mountActor( serge.blocks.actors.StringText( 'title', 'title-random', 'Random Generated Maze', colour=L('title-colour'), font_name=L('title-font'), font_size=int( L('title-font-size') * (0.5 if self.options.test else 1.0))), (0, L('title-offset-y'))) random_title.setLayerName('ui') # Back button back = serge.blocks.utils.addSpriteActorToWorld( world, 'back', 'back', 'back', layer_name='ui', center_position=L('back-position'), ) back.linkEvent(serge.events.E_LEFT_CLICK, common.tweenBackWorlds('start-screen')) # # Resume button self.resume = serge.blocks.utils.addSpriteActorToWorld( world, 'resume', 'resume', 'resume', layer_name='ui', center_position=L('resume-position'), ) self.resume.linkEvent(serge.events.E_LEFT_CLICK, common.tweenWorlds('main-screen')) # # Events world.linkEvent(serge.events.E_ACTIVATE_WORLD, self.activatedWorld) world.linkEvent(serge.events.E_DEACTIVATE_WORLD, self.deactivatedWorld)
def addedToWorld(self, world): """The level screen was added to the world""" super(RandomLevelScreen, self).addedToWorld(world) # # Logo the_theme = theme.getTheme('random-level-screen') L = the_theme.getProperty logo = serge.blocks.utils.addSpriteActorToWorld( world, 'logo', 'logo', 'logo', 'foreground', center_position=L('logo-position')) title = serge.blocks.utils.addSpriteActorToWorld( world, 'logo', 'title', 'title', 'foreground', center_position=L('title-position')) bg = serge.blocks.utils.addSpriteActorToWorld( world, 'bg', 'bg', 'dark-background', layer_name='background', center_position=(G('screen-width') / 2, G('screen-height') / 2), ) # Preview of level self.level_preview = serge.blocks.utils.addVisualActorToWorld( world, 'level-preview', 'level-preview', serge.visual.SurfaceDrawing( L('level-preview-width'), L('level-preview-height'), ), layer_name='ui', center_position=L('level-preview-position'), ) # # Size menu self.size_options = L('size-options') self.size_menu = serge.blocks.utils.addActorToWorld( world, serge.blocks.actors.ToggledMenu( 'size-menu', 'size-menu', ['Small', 'Medium', 'Large'], serge.blocks.layout.VerticalBar( 'bar', 'bar', L('size-width'), L('size-height'), ), default='Medium', on_colour=L('menu-on-colour'), off_colour=L('menu-off-colour'), callback=self.sizeSelected, font_colour=L('menu-font-colour'), mouse_over_colour=L('menu-mouse-over-colour'), font_size=L('size-font-size'), font_name=L('menu-font'), width=L('size-item-width'), height=L('size-item-height'), ), center_position=L('size-position'), layer_name='ui') # # Amount of open space menu self.space_options = L('space-options') self.space_menu = serge.blocks.utils.addActorToWorld( world, serge.blocks.actors.ToggledMenu( 'space-menu', 'space-menu', ['Open', 'Blocked'], serge.blocks.layout.VerticalBar( 'bar', 'bar', L('space-width'), L('space-height'), ), default='Open', on_colour=L('menu-on-colour'), off_colour=L('menu-off-colour'), callback=self.spaceSelected, font_colour=L('menu-font-colour'), mouse_over_colour=L('menu-mouse-over-colour'), font_size=L('space-font-size'), height=L('space-item-height'), font_name=L('menu-font'), width=L('space-item-width'), ), center_position=L('space-position'), layer_name='ui') # Generate button generate = serge.blocks.utils.addSpriteActorToWorld( world, 'generate', 'generate', 'generate', layer_name='ui', center_position=L('generate-position'), ) generate.linkEvent(serge.events.E_LEFT_CLICK, self.generateLevel) # Select button select = serge.blocks.utils.addSpriteActorToWorld( world, 'select', 'select', 'select', layer_name='ui', center_position=L('select-position'), ) select.linkEvent(serge.events.E_LEFT_CLICK, self.selectLevel) # # Resume button self.resume = serge.blocks.utils.addSpriteActorToWorld( world, 'resume', 'resume', 'resume', layer_name='ui', center_position=L('resume-position'), ) self.resume.linkEvent(serge.events.E_LEFT_CLICK, common.tweenWorlds('main-screen')) # Back button back = serge.blocks.utils.addSpriteActorToWorld( world, 'back', 'back', 'back', layer_name='ui', center_position=L('back-position'), ) back.linkEvent(serge.events.E_LEFT_CLICK, common.tweenBackWorlds('level-screen')) # # Smack talking self.smack = smacktalker.RandomlyAppearingSmacker( 'smack', 'smack', 'random-level-screen', 'waiting-for-random-level') world.addActor(self.smack) self.smack.visible = False # self.initialised = True self.generateLevel() # # Events world.linkEvent(serge.events.E_ACTIVATE_WORLD, self.activatedWorld)