Beispiel #1
0
    def __init__(self, game,):
        super(PlayingState, self).__init__(lock=1000)
        self._timer = 0
        self._game = game
        setMouseVisible(False)
        
        #build the loading screen
        loading_label = Label(0, 0, 28, u"Loading...", kind="widget.label.loading", color=BLUE)
        self._game.sprite_factory.showSpritesFromKind("widget.label.loading", True)
        
        surface = Window().surface
        surface.fill(GREY)
        loading_label_pos = (surface.get_rect().centerx - loading_label.width / 2,
                             surface.get_rect().centery - loading_label.height / 2)
        surface.blit(loading_label.sprite.image, loading_label_pos)
        displayFlip()
        
        #load game data
        tiles = TileMap("media/map_data.dump").tiles
        mousse = Mousse("renard", "00", (20, 210), 100)
        
        vegetables = ["carotte", "navet"]
        veg_spawners = []
        for i in range(1, 24):
            veg_spawners.append(VegSpawner("poulailler_%s" % (vegetables[randint(0, len(vegetables) - 1)]),
                                            (90 + randint(30, 720), 170 + randint(-80, 320)), 98))
        

        self._game.addObjects("map", tiles)
        self._game.addObjects("characters", mousse)
        self._game.addObjects("items", veg_spawners)

        
        self._camera = Camera()
        self._game.addObjects("camera", self._camera)

        self._game.observeKeyboard(mousse.keyboard, self.keyboard)
        #destroy the loading screen
        self._game.sprite_factory.delSpritesFromKind("widget.label.loading")
        Window().bgd = BROWN_EARTH
        displayFlip()
Beispiel #2
0
class PlayingState(TimeLockedState):
    def __init__(self, game,):
        super(PlayingState, self).__init__(lock=1000)
        self._timer = 0
        self._game = game
        setMouseVisible(False)
        
        #build the loading screen
        loading_label = Label(0, 0, 28, u"Loading...", kind="widget.label.loading", color=BLUE)
        self._game.sprite_factory.showSpritesFromKind("widget.label.loading", True)
        
        surface = Window().surface
        surface.fill(GREY)
        loading_label_pos = (surface.get_rect().centerx - loading_label.width / 2,
                             surface.get_rect().centery - loading_label.height / 2)
        surface.blit(loading_label.sprite.image, loading_label_pos)
        displayFlip()
        
        #load game data
        tiles = TileMap("media/map_data.dump").tiles
        mousse = Mousse("renard", "00", (20, 210), 100)
        
        vegetables = ["carotte", "navet"]
        veg_spawners = []
        for i in range(1, 24):
            veg_spawners.append(VegSpawner("poulailler_%s" % (vegetables[randint(0, len(vegetables) - 1)]),
                                            (90 + randint(30, 720), 170 + randint(-80, 320)), 98))
        

        self._game.addObjects("map", tiles)
        self._game.addObjects("characters", mousse)
        self._game.addObjects("items", veg_spawners)

        
        self._camera = Camera()
        self._game.addObjects("camera", self._camera)

        self._game.observeKeyboard(mousse.keyboard, self.keyboard)
        #destroy the loading screen
        self._game.sprite_factory.delSpritesFromKind("widget.label.loading")
        Window().bgd = BROWN_EARTH
        displayFlip()
        
        
    @property
    def time(self): 
        return self._timer
        
    def update(self, *args, **kwargs):
        super(PlayingState, self).update()
        tick = kwargs["tick"]
        self._timer += tick

        self._game.updateObjects(tick=tick, delta=self._camera.delta)        
        self._game.physic_world.step(1.0 / 60.0, 6, 6)
        self._game.sprite_factory.update("*", tick)
        
    def keyboard(self, keysdown, keysup):
        if "k" in keysdown:
            self._camera.moveIP(17, 0)
        elif "l" in keysdown:
            self._camera.moveIP(-17, 0)

    def release(self):
        self._game.delObjects("items")
        self._game.delObjects("map")
        self._game.delObjects("characters") 
        self._game.delObjects("camera")