Ejemplo n.º 1
0
    def setup(self, world):
        context = world.find_component("context")
        settings = world.find_component("settings")
        background = context["background"]

        # Create our player entity here, and we can extend it once we pick an option
        # player_entity = world.gen_entity()
        # player_entity.attach(PlayerComponent())

        # menu setup
        men = []
        men.append(("New Game", lambda: post(Event(NEW_GAME))))
        if path.exists(
                path.join(user_data_dir(APP_NAME, APP_AUTHOR),
                          settings["save_file"])):
            men.append(("Continue", lambda: post(Event(CONTINUE))))
        men.append(("How to Play", lambda: post(Event(CONTROLS))))
        men.append(("Credits", lambda: post(Event(CREDITS))))
        men.append(("Quit", lambda: post(Event(QUIT))))

        for idx, m in enumerate(men):
            offset = -((len(men) * 60) // 2) + 140

            rect = pygame.Rect(0, 0, 200, 60)
            rect.centerx = background.get_width() // 2
            rect.centery = background.get_height() // 2 + (offset + (idx * 60))

            button = world.gen_entity()
            button.attach(ButtonComponent(
                rect,
                m[0].upper(),
                m[1],
            ))
Ejemplo n.º 2
0
    def setup(self, world):
        context = world.find_component("context")
        background = context["background"]

        # Create a sprite for the header
        self.pause = pygame.sprite.Sprite()
        self.pause.image = self.regular_font.render("Paused", 1,
                                                    (200, 200, 200))
        self.pause.rect = self.pause.image.get_rect(
            centerx=background.get_width() // 2,
            centery=background.get_height() // 4)

        options = [
            ("Continue", lambda: post(Event(PAUSE_CONTINUE))),
            ("Save & Quit", lambda: post(Event(PAUSE_SAVE_AND_QUIT))),
            ("Quit to Menu", lambda: post(Event(PAUSE_QUIT_TO_MENU))),
        ]
        for idx, menu_item in enumerate(options):
            offset = 0

            rect = pygame.Rect(0, 0, 200, 60)
            rect.centerx = background.get_width() // 2
            rect.centery = background.get_height() // 2 + (offset + (idx * 70))

            button = world.gen_entity()
            button.attach(
                ButtonComponent(
                    rect,
                    menu_item[0].upper(),
                    menu_item[1],
                ))

        # Put all the sprites we want to render into a sprite group for easy adds and removes
        self.pause_screen = pygame.sprite.Group()
        self.pause_screen.add(self.pause)
Ejemplo n.º 3
0
    def setup(self, world):
        context = world.find_component("context")
        background = context["background"]

        player_entity = world.find_entity("player")

        # Create a sprite for the header
        self.pause = pygame.sprite.Sprite()
        self.pause.image = self.huge_font.render("You Crashed!", 1,
                                                 (200, 200, 200))
        self.pause.rect = self.pause.image.get_rect(
            centerx=background.get_width() // 2,
            centery=background.get_height() // 4)

        self.pause_help = pygame.sprite.Sprite()
        self.pause_help.image = self.regular_font.render(
            "Try hitting clouds, birds, or airplanes to get money for upgrades!",
            1,
            (200, 200, 200),
        )
        self.pause_help.rect = self.pause_help.image.get_rect(
            centerx=background.get_width() // 2,
            centery=background.get_height() // 2)

        self.pause_currency = pygame.sprite.Sprite()
        self.pause_currency.image = self.regular_font.render(
            f"Current money for upgrades: ${ player_entity.player.currency }",
            1,
            (200, 200, 200),
        )
        self.pause_currency.rect = self.pause_currency.image.get_rect(
            centerx=background.get_width() // 2,
            centery=background.get_height() // 2 + 100,
        )

        # menu setup
        men = [
            ("Quit", lambda: post(Event(PAUSE_QUIT_TO_MENU))),
            ("Save + Continue", lambda: post(Event(PAUSE_SAVE_AND_QUIT))),
        ]

        for idx, m in enumerate(men):
            offset = -((len(men) * 480) // 2) + 240

            rect = pygame.Rect(0, 0, 190, 49)
            rect.centerx = background.get_width() // 2 + (offset + (idx * 480))
            rect.centery = background.get_height() - 100

            button = world.gen_entity()
            button.attach(ButtonComponent(
                rect,
                m[0].upper(),
                m[1],
            ))

        # Put all the sprites we want to render into a sprite group for easy adds and removes
        self.pause_screen = pygame.sprite.Group()
        self.pause_screen.add(self.pause)
        self.pause_screen.add(self.pause_help)
        self.pause_screen.add(self.pause_currency)
Ejemplo n.º 4
0
    def setup(self, world):
        context = world.find_component("context")
        background = context["background"]

        rect = pygame.Rect(0, 0, 190, 49)
        rect.centerx = background.get_width() // 2
        rect.centery = background.get_height() // 2 + 100

        button = world.gen_entity()
        button.attach(
            ButtonComponent(
                rect,
                "Back".upper(),
                lambda: post(Event(BACK)),
            ))
Ejemplo n.º 5
0
    def setup(self, world):
        context = world.find_component("context")
        background = context["background"]

        # Create a sprite for the title
        victory_text = pygame.sprite.Sprite()
        victory_text.image = self.victory_font.render("VICTORY", True,
                                                      (240, 240, 240))
        victory_text.rect = victory_text.image.get_rect(
            centerx=background.get_width() // 2, centery=110)

        self.victory_screen.add(victory_text)

        sub_text = pygame.sprite.Sprite()
        sub_text.image = self.regular_font.render(
            "Never regret thy fall, O Icarus of the fearless flight",
            True,
            (185, 185, 185),
        )
        sub_text.rect = sub_text.image.get_rect(
            centerx=background.get_width() // 2, centery=190)

        self.victory_screen.add(sub_text)

        # menu setup
        men = [
            ("Quit", lambda: post(Event(PAUSE_QUIT_TO_MENU))),
        ]

        for idx, m in enumerate(men):
            offset = -((len(men) * 480) // 2) + 240

            rect = pygame.Rect(0, 0, 190, 49)
            rect.centerx = background.get_width() // 2 + (offset + (idx * 480))
            rect.centery = background.get_height() - 100

            button = world.gen_entity()
            button.attach(ButtonComponent(
                rect,
                m[0].upper(),
                m[1],
            ))
Ejemplo n.º 6
0
    def setup(self, world):
        context = world.find_component("context")
        background = context["background"]
        settings = world.find_component("settings")

        player_entity = world.find_entity("player")
        player_entity.player.has_jumped = False

        # menu setup
        men = []
        men.append(("Quit", lambda: post(Event(EQUIP_QUIT))))
        men.append(("Save + Start", lambda: post(Event(EQUIP_SAVE_AND_START))))

        for idx, m in enumerate(men):
            offset = -((len(men) * 480) // 2) + 240

            rect = pygame.Rect(0, 0, 190, 49)
            rect.centerx = background.get_width() // 2 + (offset + (idx * 480))
            rect.centery = background.get_height() - 100

            button = world.gen_entity()
            button.attach(
                ButtonComponent(
                    rect,
                    m[0].upper(),
                    m[1],
                )
            )

        rect = pygame.Rect(120, 560, 49, 49)
        jet_boots_button = world.gen_entity()
        jet_boots_button.attach(
            ButtonComponent(
                rect,
                "Buy" if player_entity.player.hasJetBoots == 0 else "",
                lambda: post(Event(EQUIP_BUY_JET_BOOTS)),
                is_small=True,
                is_disabled=(
                    player_entity.player.currency < settings["jetBootsCost"]
                    or player_entity.player.hasJetBoots == 1
                ),
                image="resources/checkmark.png"
                if player_entity.player.hasJetBoots == 1
                else None,
            )
        )

        rect = pygame.Rect(640, 560, 49, 49)
        cloud_sleeves_button = world.gen_entity()
        cloud_sleeves_button.attach(
            ButtonComponent(
                rect,
                "Buy" if player_entity.player.hasCloudSleeves == 0 else "",
                lambda: post(Event(EQUIP_BUY_CLOUD_SLEEVES)),
                is_small=True,
                is_disabled=(
                    player_entity.player.currency < settings["cloudSleevesCost"]
                    or player_entity.player.hasCloudSleeves == 1
                ),
                image="resources/checkmark.png"
                if player_entity.player.hasCloudSleeves == 1
                else None,
            )
        )

        rect = pygame.Rect(640, 660, 49, 49)
        wings_button = world.gen_entity()
        wings_button.attach(
            ButtonComponent(
                rect,
                text="Buy"
                if player_entity.player.hasCloudSleeves == 1
                and player_entity.player.hasWings == 0
                else "",
                callback=lambda: post(Event(EQUIP_BUY_WINGS)),
                is_small=True,
                is_disabled=(
                    (
                        player_entity.player.currency < settings["wingsCost"]
                        and player_entity.player.hasCloudSleeves == 1
                    )
                    or player_entity.player.hasCloudSleeves == 0
                    or player_entity.player.hasWings == 1
                ),
                image="resources/locked.png"
                if player_entity.player.hasCloudSleeves == 0
                else "resources/checkmark.png"
                if player_entity.player.hasWings == 1
                else None,
            )
        )