Ejemplo n.º 1
0
class MainMenu(game.State):
    def __init__(self):
        super(MainMenu, self).__init__()

        self.title = Line((game.screen_size[0] / 2, game.screen_size[1] / 4),
                          "Houd de knop ingedrukt", game.get_font('title'))

        self.cursor = Cursor()
        self.start_button = Button(
            (game.screen_size[0] / 2, game.screen_size[1] / 2),
            self.start_button_pressed)

        game.global_state_changed.subscribe(self.global_state_changed)

    def update(self, delta):
        self.title.update(delta)
        self.cursor.update(delta)
        self.start_button.update(delta)

    def draw(self, surface):
        self.title.draw(surface)
        self.start_button.draw(surface)
        self.cursor.draw(surface)

    def start_button_pressed(self):
        game.set_global_state('tutorial')

    def global_state_changed(self, previous_state, new_state):
        if new_state is 'main_menu':
            self.cursor.set_position((0, 0))
            self.cursor.cursor_up()
Ejemplo n.º 2
0
class MainMenuLocation(_Location):
    def __init__(self, parent):
        super().__init__(parent)
        self.bg = Sprite(
            0,
            0,
            image=pygame.image.load("assets/misc/mainMenu.png").convert(),
            size=c.sizes["win"])
        pygame.mixer.music.load("assets/audio/Intro.mp3")
        pygame.mixer.music.play(-1)
        self.play_button = Button(
            c.pads["play"],
            pygame.image.load("assets/misc/start.png").convert_alpha(),
            pygame.image.load(
                "assets/misc/startHighlight.png").convert_alpha())
        self.exit = Button(
            c.pads["exit"],
            pygame.image.load("assets/misc/potQuit.png").convert(),
            pygame.image.load("assets/misc/potQuitHighlight.png").convert())

    def update(self):
        mouse_pos = pygame.mouse.get_pos()

        self.bg.update(self.screen)
        self.play_button.update(self.screen, mouse_pos)
        self.exit.update(self.screen, mouse_pos)

    def event(self, event):
        mouse_pos = pygame.mouse.get_pos()
        if event.type == MOUSEBUTTONUP and event.button == 1:
            if self.play_button.click(mouse_pos):
                from .chooseYourPlants import LevelPreparationLocation
                self.parent.change_location(
                    LevelPreparationLocation(self.parent))
            if self.exit.click(mouse_pos):
                sys.exit()