示例#1
0
    def before_gameloop(self):
        resman.read("data/resources.cfg")

        self.game_data = GameData(self.userinput)

        # apply configuration settings
        SoundManager.set_sound_volume(self.config.sound_volume)
        SoundManager.set_music_volume(self.config.music_volume)

        # set state
        self.menu = MonorailMenu(self.game_data)
        self.game = MonorailGame(self.game_data)
        self.editor = None

        self.state = self.game
        self.state = self.menu

        # set window buttons
        self.max_button = ImageButton(copy.copy(resman.get("game.max_button")),
                                      Vec2D(800 - 16 - 4, 4))
示例#2
0
    def before_gameloop( self ):
        resman.read("data/resources.cfg")

        self.game_data = GameData( self.userinput )

        # apply configuration settings
        SoundManager.set_sound_volume( self.config.sound_volume )
        SoundManager.set_music_volume( self.config.music_volume )

        # set state
        self.menu = MonorailMenu( self.game_data )
        self.game = MonorailGame( self.game_data )
        self.editor = None

        self.state = self.game
        self.state = self.menu

        # set window buttons
        self.max_button = ImageButton( copy.copy(resman.get("game.max_button")), Vec2D(800-16-4, 4) )
示例#3
0
class Monorail (Game):
    """The Monorail main application

    public members:
    - game_is_done: True when app should exit
    """

    def __init__( self, configuration ):
        Game.__init__( self, _("Mystic Mine"), configuration )

    def before_gameloop( self ):
        resman.read("data/resources.cfg")

        self.game_data = GameData( self.userinput )

        # apply configuration settings
        SoundManager.set_sound_volume( self.config.sound_volume )
        SoundManager.set_music_volume( self.config.music_volume )

        # set state
        self.menu = MonorailMenu( self.game_data )
        self.game = MonorailGame( self.game_data )
        self.editor = None

        self.state = self.game
        self.state = self.menu

        # set window buttons
        self.max_button = ImageButton( copy.copy(resman.get("game.max_button")), Vec2D(800-16-4, 4) )



    def do_tick( self, indev ):
        if indev.key.is_down(K_F5) and indev.key.is_down(K_F8) and indev.key.went_down( K_ESCAPE ):
            self.game_is_done = True

        if indev.key.is_down(K_F5) and indev.key.is_down(K_F8) and indev.key.went_down( K_e ):
            if self.state == self.game:
                level_nr = self.game_data.get_quest().get_current_level_nr()
                self.editor = MonorailEditor( level_nr )
                self.state = self.editor
            elif self.state == self.editor:
                self.editor.save_all()
                self.game = MonorailGame( self.game_data )
                self.state = self.game

        if self.state == self.game:
            if self.game.is_done(): # or indev.key.went_down( K_0 ):
                self.game.to_next_level = False
                if self.game.state == MonorailGame.STATE_DONE: # or indev.key.went_down( K_0 ):
                    if self.game_data.is_single_player():
                        if self.game_data.get_quest().progress == self.game_data.get_quest().get_level_count() - 1:
                            self.game_data.set_game_finished()
                        self.game_data.get_quest().to_next_level()
                        self.game_data.save_single_player_progress()
                        self.state = self.menu
                        self.menu.show_level_select()
                    else:
                        self.game_data.get_quest().to_next_level()
                        self.game.restart( self.game_data )
                elif self.game.state == MonorailGame.STATE_MENU:
                    self.state = self.menu
                    self.menu.show_main_menu()
                elif self.game.state == MonorailGame.STATE_QUIT:
                    self.game_is_done = True
        elif self.state == self.menu:
            if self.menu.is_done():
                if self.menu.should_quit:
                    self.game_is_done = True
                else:
                    self.state = self.game
                    self.game.restart( self.game_data )

        self.state.do_tick( indev )

        # Handle maximize button
        self.max_button.tick( indev, None )
        if self.max_button.went_down():
            self.config.is_fullscreen = not self.config.is_fullscreen
            if not self.config.is_fullscreen:
                pygame.display.set_mode(self.config.resolution)
            else:
                pygame.display.set_mode(self.config.resolution, pygame.FULLSCREEN)

    def render( self, surface, interpol, time_sec ):
        self.state.draw( surface, interpol, time_sec )
        self.max_button.draw( surface, interpol, time_sec )
        self.state.draw_mouse( surface, interpol, time_sec )
示例#4
0
class Monorail(Game):
    """The Monorail main application

    public members:
    - game_is_done: True when app should exit
    """
    def __init__(self, configuration):
        Game.__init__(self, _("Mystic Mine"), configuration)

    def before_gameloop(self):
        resman.read("data/resources.cfg")

        self.game_data = GameData(self.userinput)

        # apply configuration settings
        SoundManager.set_sound_volume(self.config.sound_volume)
        SoundManager.set_music_volume(self.config.music_volume)

        # set state
        self.menu = MonorailMenu(self.game_data)
        self.game = MonorailGame(self.game_data)
        self.editor = None

        self.state = self.game
        self.state = self.menu

        # set window buttons
        self.max_button = ImageButton(copy.copy(resman.get("game.max_button")),
                                      Vec2D(800 - 16 - 4, 4))

    def do_tick(self, indev):
        if indev.key.is_down(K_F5) and indev.key.is_down(
                K_F8) and indev.key.went_down(K_ESCAPE):
            self.game_is_done = True

        if indev.key.is_down(K_F5) and indev.key.is_down(
                K_F8) and indev.key.went_down(K_e):
            if self.state == self.game:
                level_nr = self.game_data.get_quest().get_current_level_nr()
                self.editor = MonorailEditor(level_nr)
                self.state = self.editor
            elif self.state == self.editor:
                self.editor.save_all()
                self.game = MonorailGame(self.game_data)
                self.state = self.game

        if self.state == self.game:
            if self.game.is_done():  # or indev.key.went_down( K_0 ):
                self.game.to_next_level = False
                if self.game.state == MonorailGame.STATE_DONE:  # or indev.key.went_down( K_0 ):
                    if self.game_data.is_single_player():
                        if self.game_data.get_quest(
                        ).progress == self.game_data.get_quest(
                        ).get_level_count() - 1:
                            self.game_data.set_game_finished()
                        self.game_data.get_quest().to_next_level()
                        self.game_data.save_single_player_progress()
                        self.state = self.menu
                        self.menu.show_level_select()
                    else:
                        self.game_data.get_quest().to_next_level()
                        self.game.restart(self.game_data)
                elif self.game.state == MonorailGame.STATE_MENU:
                    self.state = self.menu
                    self.menu.show_main_menu()
                elif self.game.state == MonorailGame.STATE_QUIT:
                    self.game_is_done = True
        elif self.state == self.menu:
            if self.menu.is_done():
                if self.menu.should_quit:
                    self.game_is_done = True
                else:
                    self.state = self.game
                    self.game.restart(self.game_data)

        self.state.do_tick(indev)

        # Handle maximize button
        self.max_button.tick(indev, None)
        if self.max_button.went_down():
            self.config.is_fullscreen = not self.config.is_fullscreen
            if not self.config.is_fullscreen:
                pygame.display.set_mode(self.config.resolution)
            else:
                pygame.display.set_mode(self.config.resolution,
                                        pygame.FULLSCREEN)

    def render(self, surface, interpol, time_sec):
        self.state.draw(surface, interpol, time_sec)
        self.max_button.draw(surface, interpol, time_sec)
        self.state.draw_mouse(surface, interpol, time_sec)