Exemplo n.º 1
0
def main():

    # Init module
    pyg.init()

    # Init screen
    reset_screen(INSTRUCTION_FILE)

    # Play music
    play_music(MUSIC_FILE, volume=VOLUME)

    # Load ressources
    with TimeControl(FIRST_INSTRUCTION_TIME):
        from Map import Map

    # Loop infinitely
    while True:

        # Loop over levels
        for i in xrange(1, NB_LEVELS+1):

            # Loop over game overs
            while True:

                # Print stage screen
                with TimeControl(STAGE_TIME):
                    gen_stage_screen(i)

                # Create map
                mp = Map(MAP_FORMAT.format(i), i)

                # Main loop
                win, reset = mp.view.reactor_loop()

                # Test victory
                if win: break

                # Game over screen
                if not reset:
                    with TimeControl(GAMEOVER_TIME):
                        reset_screen(GAMEOVER_FILE)

            # Hard Reset
            #if hard_reset: break

        if not reset:
            # End screen
            with TimeControl(ENDSCREEN_TIME):
                reset_screen(ENDSCREEN_FILE)

            # Credits screen
            with TimeControl(CREDITS_TIME):
                reset_screen(CREDITS_FILE)

        # Instruction screen
        with TimeControl(INSTRUCTION_TIME):
            reset_screen(INSTRUCTION_FILE)

    # Quit
    pyg.quit()
Exemplo n.º 2
0
    def __init__(self, action_handler, index):
        # Init clock
        self.clock = pyg.time.Clock()

        # Set handler
        self.action_handler = action_handler

        # Init groupsView
        self.all_sprites = LayeredDirty()
        Fps.containers += (self.all_sprites,)

        # Create window
        self.screen, self.background = reset_screen()
        if DISPLAY_FPS:
            Fps(self.clock)

        # Blit level
        image, rect = get_stage_image(index)
        self.background.blit(image, rect)

        # Tile handling
        from TileView import TileView
        TileView.layer_container = self.all_sprites

        # Initialize attributes
        self.exit = False
        self.done = False
        self.countdown = None
Exemplo n.º 3
0
    def reactor_loop(self):
        # Infinite loop
        while True:
            # Get input
            for ev in pyg.event.get():
                # Quit
                if (ev.type == pyg.KEYDOWN and ev.key == pyg.K_ESCAPE)\
                   or ev.type == pyg.QUIT:
                    safe_exit()
                # Fullscreen
                if ev.type == pyg.KEYDOWN and ev.key == pyg.K_f:
                    # Toggle fullscreen
                    Constants.FULLSCREEN ^= True
                    # Reset screen
                    self.screen, _ = reset_screen()
                    args = self.background, self.background.get_rect()
                    self.screen.blit(*args)
                    # Repaint all
                    self.all_sprites._use_update = False
                # Mute
                if ev.type == pyg.KEYDOWN and ev.key == pyg.K_SEMICOLON:
                    volume = 0 if pyg.mixer.music.get_volume() else VOLUME
                    pyg.mixer.music.set_volume(float(volume)/100)
                # Reset
                if (ev.type == pyg.KEYDOWN and ev.key == pyg.K_r) or\
                (ev.type == pyg.JOYBUTTONDOWN and ev.button in RESET_BUTTONS):
                    win_reset = False, True
                    return win_reset

            # Handle countdown
            if self.done and next(self.countdown):
                self.all_sprites.empty()
                win_reset = self.win, False
                return win_reset

            # Read input
            if not self.done:
                self.action_handler.read_inputs()

            # Clear sprites from screen
            self.all_sprites.clear(self.screen, self.background)

            # Update sprites
            self.all_sprites.update()

            # Draw sprites on screen
            dirty = self.all_sprites.draw(self.screen)

            # Update display
            pyg.display.update(dirty)

            # Frame rate control
            self.clock.tick(FPS)