Example #1
0
def game_loop(screen):
    events = []
    last_frame_time = None

    scene = TitleScene(screen)

    while True:
        if not scene.lazy_redraw():
            clock.tick(60)
            events = pygame.event.get()

        process_events(events, scene)

        if scene.lazy_redraw():
            if scene.dirty:
                scene.draw()
            events = [pygame.event.wait()]
        else:
            elapsed = time.time(
            ) - last_frame_time if last_frame_time else .001

            scene.tick(elapsed)

            last_frame_time = time.time()

            dirty_rects = scene.draw()
            pygame.display.update(dirty_rects)

        screen.set_clip()

        new_scene = scene.switchToScene()
        if new_scene:
            scene = new_scene
Example #2
0
def game_loop(screen):
    events = []
    last_frame_time = None

    scene = TitleScene(screen)

    while True:
        if not scene.lazy_redraw():
            clock.tick(60)
            events = pygame.event.get()

        process_events(events, scene)

        if scene.lazy_redraw():
            if scene.dirty:
                scene.draw()
            events = [pygame.event.wait()]
        else:
            elapsed = time.time() - last_frame_time if last_frame_time else .001

            scene.tick(elapsed)

            last_frame_time = time.time()

            dirty_rects = scene.draw()
            pygame.display.update(dirty_rects)

        screen.set_clip()

        new_scene = scene.switchToScene()
        if new_scene:
            scene = new_scene
Example #3
0
File: game.py Project: jpmit/ggj14
    def mainloop(self):
        
        # first scene of the game
        ascene = TitleScene(self)

        # initialize clock
        dt = self.clock.tick(FPS) / 1000.0

        # store 'pressed actions' to complement events
        pressed = {}
        for action in ALL_ACTIONS:
            pressed[action] = False

        while ascene != None:
            
            # get the events we are interested in as well as the
            # currently pressed keys, and whether we want to quit.
            events, pressed, quitevent, menuevent = get_events(pressed)

            # scene specific updating based on events.
            ascene.process_input(events, pressed, dt)

            # update not based on events.
            ascene.update(dt)

            # draw to the screen.
            ascene.render(self.screen)

            # possible change to new scene.
            ascene = ascene.next

            # draw to the screen!
            pygame.display.flip()

            # delay for correct time here.
            dt = self.clock.tick(FPS) / 1000.0

            if menuevent:
                ascene = TitleScene(self)
                
            if quitevent:
                ascene = None
                pygame.quit()