Beispiel #1
0
 def __init__(self, event_manager):
     evtman.SingleListener.__init__(self, event_manager)
     views.setupEntityViewFactories()
     #
     self._world_model, self._fox_spawner, self._carrot_spawner = gen.GenerateWorld(event_manager, (64, 64))
     self._player_controller = PlayerController(event_manager)
     self._game_loop_controller = GameLoopController(event_manager)
     self._keyboard_controller = StartScreenKeyboardController(event_manager)
     self._area_view = None
     self._time_spent_view = None
     self._health_view = None
     self._carrot_counter_view = None
     self._stats_view = None
     self._status_text_view = None
     self._game_over_view = None
     self._time = 0
     #
     with pygame_.Pygame():
         self._pygame_view = pygame_.PygameView(event_manager,
                                                u"Apocalypse Bunny", (800, 480))
         assets.load()
         self._title_view = views.StartScreenView(event_manager)
         self._pygame_view.addView(self._title_view)
         self._pygame_controller = pygame_.PygameController(event_manager)
         # Here I select the bunny and show its area.  It's a bit of a hack
         # since I know their entity_id and area_id.  But I don't care, this
         # game is supposed to be quick and dirty.
         # Run the game until a QuitEvent is posted.
         self._game_loop_controller.run()
         LOGGER.info("Stopping...")
Beispiel #2
0
 def __init__(self, event_manager):
     evtman.SingleListener.__init__(self, event_manager)
     views.setupEntityViewFactories()
     #
     self._world_model, self._fox_spawner, self._carrot_spawner = gen.GenerateWorld(
         event_manager, (64, 64))
     self._player_controller = PlayerController(event_manager)
     self._game_loop_controller = GameLoopController(event_manager)
     self._keyboard_controller = StartScreenKeyboardController(
         event_manager)
     self._area_view = None
     self._time_spent_view = None
     self._health_view = None
     self._carrot_counter_view = None
     self._stats_view = None
     self._status_text_view = None
     self._game_over_view = None
     self._time = 0
     #
     with pygame_.Pygame():
         self._pygame_view = pygame_.PygameView(event_manager,
                                                u"Apocalypse Bunny",
                                                (800, 480))
         assets.load()
         self._title_view = views.StartScreenView(event_manager)
         self._pygame_view.addView(self._title_view)
         self._pygame_controller = pygame_.PygameController(event_manager)
         # Here I select the bunny and show its area.  It's a bit of a hack
         # since I know their entity_id and area_id.  But I don't care, this
         # game is supposed to be quick and dirty.
         # Run the game until a QuitEvent is posted.
         self._game_loop_controller.run()
         LOGGER.info("Stopping...")
    def loadSpriteAnim(self, filename):
        """Loads sprite animation from file."""
        self.sequences = {}
        file = assets.load(filename)
        tmp = json.load(file)
        file.close()

        # Graphics for animation
        img_list = assets.getImageList(tmp["image"], tmp["columns"], tmp["rows"])

        # Create the animation sequences from the file's data
        for sequence in tmp["sequences"]:
            frames = []
            for cell,duration in sequence["frames"]:
                frames.append((img_list[cell], duration))
            self.sequences[sequence["name"]] = Sequence(sequence["looping"], frames)
        tw, th = texture.image.size
        return {
            'w': fw,
            'h': fh,
            'px': image.px - trimx,
            'py': image.py - trimy,
            'u': atlas_image.x / float(tw),
            'v': atlas_image.y / float(th),
            'du': fw / float(tw),
            'dv': fh / float(th),
            'transposed': atlas_image.transposed
        }

    # print '----------'
    # print str(json.dumps({
    # 	'textures': dict((t.id,export_json_texture(t)) for t in assetGroup.textures)
    # }))
    # print '----------'

    with open(outpath, 'w') as f:
        f.write(
            json.dumps({
                'textures':
                dict((t.id, export_json_texture(t))
                     for t in assetGroup.textures)
            }))


if __name__ == '__main__':
    export_json_assets(assets.load('assets.xml'), 'assets.json')