Ejemplo n.º 1
0
 def updateActor(self, interval, world):
     """Update this actor"""
     super(MainScreen, self).updateActor(interval, world)
     if self.flag_status_panel.currently_carrying == "None":
         self.board.observation[-1]["flag"] = 0
     elif self.flag_status_panel.currently_carrying == "player":
         self.board.observation[-1]["flag"] = 1
     elif self.flag_status_panel.currently_carrying == "ai":
         self.board.observation[-1]["flag"] = 2
     #
     # Watch for restarting game
     if self._game_over:
         if self.keyboard.isClicked(pygame.K_RETURN):
             self.restartGame()
     #
     # Take screenshot if needed
     if self._take_screenshots:
         if time.time() - self._last_screenshot > self._screenshot_interval:
             filename = '%s-%s' % (self.name,
                                   time.strftime('%m-%d %H:%M:%S.png'))
             serge.blocks.utils.takeScreenshot(
                 os.path.join(self._screenshot_path, filename))
             self._last_screenshot = time.time()
             self.log.debug('Taking screenshot - %s', filename)
     #
     # Cheating options
     if self.options.cheat:
         if self.keyboard.isClicked(pygame.K_n):
             self.world.rtf = 1
             self.world.fps = 50
         if self.keyboard.isClicked(pygame.K_f):
             self.world.rtf = G('simulation-rtf')
             self.world.fps = G('simulation-fps')
         if self.keyboard.isClicked(pygame.K_k):
             self.playerDied('blew-up', None)
         if self.keyboard.isClicked(pygame.K_w):
             self.aiDied('no-hearts-left', None)
         if self.keyboard.isClicked(pygame.K_c):
             serge.sound.Sounds.play('hearts')
     #
     # Switch to replay
     if self.keyboard.isClicked(pygame.K_r):
         self.engine.setCurrentWorldByName('action-replay-screen')
     #
     # Escape
     if self.keyboard.isClicked(pygame.K_ESCAPE):
         if self.options.straight or pygame.key.get_mods(
         ) & pygame.KMOD_SHIFT:
             self.engine.stop(process_events=False)
         else:
             common.tweenBackWorlds(
                 'level-screen' if self.current_level != common.levels.
                 RANDOM_LEVEL else 'random-level-screen')(None, None)
Ejemplo n.º 2
0
 def updateActor(self, interval, world):
     """Update this actor"""
     super(MainScreen, self).updateActor(interval, world)
     if self.flag_status_panel.currently_carrying == "None":
         self.board.observation[-1]["flag"] = 0
     elif self.flag_status_panel.currently_carrying == "player":
         self.board.observation[-1]["flag"] = 1
     elif self.flag_status_panel.currently_carrying == "ai":
         self.board.observation[-1]["flag"] = 2
     #
     # Watch for restarting game
     if self._game_over:
         if self.keyboard.isClicked(pygame.K_RETURN):
             self.restartGame()
     #
     # Take screenshot if needed
     if self._take_screenshots:
         if time.time() - self._last_screenshot > self._screenshot_interval:
             filename = '%s-%s' % (self.name, time.strftime('%m-%d %H:%M:%S.png'))
             serge.blocks.utils.takeScreenshot(os.path.join(self._screenshot_path, filename))
             self._last_screenshot = time.time()
             self.log.debug('Taking screenshot - %s', filename)
     #
     # Cheating options
     if self.options.cheat:
         if self.keyboard.isClicked(pygame.K_n):
             self.world.rtf = 1
             self.world.fps = 50
         if self.keyboard.isClicked(pygame.K_f):
             self.world.rtf = G('simulation-rtf')
             self.world.fps = G('simulation-fps')
         if self.keyboard.isClicked(pygame.K_k):
             self.playerDied('blew-up', None)
         if self.keyboard.isClicked(pygame.K_w):
             self.aiDied('no-hearts-left', None)
         if self.keyboard.isClicked(pygame.K_c):
             serge.sound.Sounds.play('hearts')
     #
     # Switch to replay
     if self.keyboard.isClicked(pygame.K_r):
         self.engine.setCurrentWorldByName('action-replay-screen')
     #
     # Escape
     if self.keyboard.isClicked(pygame.K_ESCAPE):
         if self.options.straight or pygame.key.get_mods() & pygame.KMOD_SHIFT:
             self.engine.stop(process_events=False)
         else:
             common.tweenBackWorlds(
                 'level-screen' if self.current_level != common.levels.RANDOM_LEVEL else 'random-level-screen')(None, None)
 def updateActor(self, interval, world):
     """Update this actor"""
     super(LevelScreen, self).updateActor(interval, world)
     #
     # Keypresses
     if self.keyboard.isClicked(pygame.K_RETURN):
         self.selectLevel(None, G('start-level'))
     if self.keyboard.isClicked(pygame.K_ESCAPE):
         common.tweenBackWorlds('start-screen')(None, None)
     #
     if self._take_screenshots:
         if time.time() - self._last_screenshot > self._screenshot_interval:
             filename = '%s-%s' % (self.name, time.strftime('%m-%d %H:%M:%S.png'))
             serge.blocks.utils.takeScreenshot(os.path.join(self._screenshot_path, filename))
             self._last_screenshot = time.time()
             self.log.debug('Taking screenshot - %s', filename)
 def addedToWorld(self, world):
     """The screen was added to the world"""
     super(HelpScreen, self).addedToWorld(world)
     #
     # Logo
     the_theme = theme.getTheme('help-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),
     )
     #
     # Help text
     text = serge.blocks.utils.addSpriteActorToWorld(world, 'text', 'text', 'help-keys', 'foreground',
         center_position=L('text-position'))
     #
     serge.blocks.utils.addTextItemsToWorld(world, [
                 ('Cursor keys to move. SPACE to Bomb.', 'keys-title'),
                 ('Music Volume', 'music-title'),
             ],
             the_theme, 'foreground')
     #
     # Back link
     #
     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'))
     #
     # Volume control
     self.down = serge.blocks.utils.addSpriteActorToWorld(
         world, 'btn', 'vol-down', 'vol-down',
         layer_name='ui',
         center_position=L('vol-down-position')
     )
     self.down.linkEvent(serge.events.E_LEFT_CLICK, self.changeVolume, -L('vol-change-amount'))
     self.up = serge.blocks.utils.addSpriteActorToWorld(
         world, 'btn', 'vol-up', 'vol-up',
         layer_name='ui',
         center_position=L('vol-up-position')
     )
     self.up.linkEvent(serge.events.E_LEFT_CLICK, self.changeVolume, +L('vol-change-amount'))
     #
     self.volume = serge.blocks.utils.addActorToWorld(
         world, serge.blocks.actors.NumericText(
             'text', 'volume', '%d%%', L('volume-colour'),
             font=L('volume-font'), font_size=L('volume-size'),
             value=G('volume', 'start-screen') * 100.0
         ),
         layer_name='ui',
         center_position=L('vol-position')
     )
Ejemplo n.º 5
0
 def updateActor(self, interval, world):
     """Update this actor"""
     super(LevelScreen, self).updateActor(interval, world)
     #
     # Keypresses
     if self.keyboard.isClicked(pygame.K_RETURN):
         self.selectLevel(None, G('start-level'))
     if self.keyboard.isClicked(pygame.K_ESCAPE):
         common.tweenBackWorlds('start-screen')(None, None)
     #
     if self._take_screenshots:
         if time.time() - self._last_screenshot > self._screenshot_interval:
             filename = '%s-%s' % (self.name,
                                   time.strftime('%m-%d %H:%M:%S.png'))
             serge.blocks.utils.takeScreenshot(
                 os.path.join(self._screenshot_path, filename))
             self._last_screenshot = time.time()
             self.log.debug('Taking screenshot - %s', filename)
 def addedToWorld(self, world):
     """The screen was added to the world"""
     super(CreditsScreen, self).addedToWorld(world)
     #
     # Logo
     the_theme = theme.getTheme('credits-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),
     )
     #
     # Text on the page
     serge.blocks.utils.addTextItemsToWorld(world, [
                 ('Game concept, design and coding', 'author-title'),
                 (AUTHOR, 'author'),
                 (URL, 'url', self.launchURL),
                 ('Music', 'music-title1'),
                 ('from the FreeMusicArchive.org', 'music-title2'),
                 ('Sound', 'sound-title1'),
                 ('From FreeSound.org', 'sound-title2'),
                 ('Built using', 'built-title'),
                 (BUILT_USING, 'built'),
                 ('Game engine', 'engine-title'),
                 (GAME_ENGINE, 'engine'),  
                 ('(v' + serge.common.version + ')', 'engine-version'),
                 ('Fonts', 'font-title1'),
                 ('from the OpenFontLibrary.org', 'font-title2'), 
                 ('Back', 'back', common.tweenBackWorlds('start-screen')),
             ],
             the_theme, 'foreground')
     #
     back = serge.blocks.utils.addSpriteActorToWorld(
         world, 'back', 'back', 'back',
         layer_name='ui',
         center_position=L('back-position'),
     )
     #
     x, y = L('music-position')
     for idx, track in enumerate(MUSIC):
         serge.blocks.utils.addVisualActorToWorld(world, 'title', 'music-item', 
             serge.visual.Text(track, L('music-colour'), 
             font_size=L('music-font-size')), 'foreground', 
             center_position=(x, y+idx*20))
     #
     x, y = L('font-position')
     for idx, font in enumerate(FONTS):
         serge.blocks.utils.addVisualActorToWorld(world, 'title', 'font-item', 
             serge.visual.Text(font, L('font-colour'), 
             font_size=L('font-font-size')), 'foreground', 
             center_position=(x, y+idx*20))
 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)
Ejemplo n.º 8
0
 def addedToWorld(self, world):
     """The screen was added to the world"""
     super(CreditsScreen, self).addedToWorld(world)
     #
     # Logo
     the_theme = theme.getTheme('credits-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),
     )
     #
     # Text on the page
     serge.blocks.utils.addTextItemsToWorld(world, [
         ('Game concept, design and coding', 'author-title'),
         (AUTHOR, 'author'),
         (URL, 'url', self.launchURL),
         ('Music', 'music-title1'),
         ('from the FreeMusicArchive.org', 'music-title2'),
         ('Sound', 'sound-title1'),
         ('From FreeSound.org', 'sound-title2'),
         ('Built using', 'built-title'),
         (BUILT_USING, 'built'),
         ('Game engine', 'engine-title'),
         (GAME_ENGINE, 'engine'),
         ('(v' + serge.common.version + ')', 'engine-version'),
         ('Fonts', 'font-title1'),
         ('from the OpenFontLibrary.org', 'font-title2'),
         ('Back', 'back', common.tweenBackWorlds('start-screen')),
     ], the_theme, 'foreground')
     #
     back = serge.blocks.utils.addSpriteActorToWorld(
         world,
         'back',
         'back',
         'back',
         layer_name='ui',
         center_position=L('back-position'),
     )
     #
     x, y = L('music-position')
     for idx, track in enumerate(MUSIC):
         serge.blocks.utils.addVisualActorToWorld(
             world,
             'title',
             'music-item',
             serge.visual.Text(track,
                               L('music-colour'),
                               font_size=L('music-font-size')),
             'foreground',
             center_position=(x, y + idx * 20))
     #
     x, y = L('font-position')
     for idx, font in enumerate(FONTS):
         serge.blocks.utils.addVisualActorToWorld(
             world,
             'title',
             'font-item',
             serge.visual.Text(font,
                               L('font-colour'),
                               font_size=L('font-font-size')),
             'foreground',
             center_position=(x, y + idx * 20))
Ejemplo n.º 9
0
 def addedToWorld(self, world):
     """The screen was added to the world"""
     super(HelpScreen, self).addedToWorld(world)
     #
     # Logo
     the_theme = theme.getTheme('help-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),
     )
     #
     # Help text
     text = serge.blocks.utils.addSpriteActorToWorld(
         world,
         'text',
         'text',
         'help-keys',
         'foreground',
         center_position=L('text-position'))
     #
     serge.blocks.utils.addTextItemsToWorld(world, [
         ('Cursor keys to move. SPACE to Bomb.', 'keys-title'),
         ('Music Volume', 'music-title'),
     ], the_theme, 'foreground')
     #
     # Back link
     #
     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'))
     #
     # Volume control
     self.down = serge.blocks.utils.addSpriteActorToWorld(
         world,
         'btn',
         'vol-down',
         'vol-down',
         layer_name='ui',
         center_position=L('vol-down-position'))
     self.down.linkEvent(serge.events.E_LEFT_CLICK, self.changeVolume,
                         -L('vol-change-amount'))
     self.up = serge.blocks.utils.addSpriteActorToWorld(
         world,
         'btn',
         'vol-up',
         'vol-up',
         layer_name='ui',
         center_position=L('vol-up-position'))
     self.up.linkEvent(serge.events.E_LEFT_CLICK, self.changeVolume,
                       +L('vol-change-amount'))
     #
     self.volume = serge.blocks.utils.addActorToWorld(
         world,
         serge.blocks.actors.NumericText('text',
                                         'volume',
                                         '%d%%',
                                         L('volume-colour'),
                                         font=L('volume-font'),
                                         font_size=L('volume-size'),
                                         value=G('volume', 'start-screen') *
                                         100.0),
         layer_name='ui',
         center_position=L('vol-position'))
 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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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)