Exemplo n.º 1
0
    def update(self, events, world):
        settings = world.find_component("settings")

        for event in events:
            if event.type == EQUIP_QUIT:
                return SceneManager.new_root(scenes.title.TitleScene())
            if event.type == EQUIP_BUY_CLOUD_SLEEVES:
                self._shop(settings["cloudSleevesCost"], "cloud_sleeves",
                           world)
                self.teardown(world)
                self.setup(world)
            if event.type == EQUIP_BUY_WINGS:
                self._shop(settings["wingsCost"], "wings", world)
                self.teardown(world)
                self.setup(world)
            if event.type == EQUIP_BUY_JET_BOOTS:
                self._shop(settings["jetBootsCost"], "jet_boots", world)
                self.teardown(world)
                self.setup(world)
            if event.type == EQUIP_SAVE_AND_START:
                self._save(settings["save_file"], world)
                self.teardown(world)
                return SceneManager.push(GameScene())

        world.process_all_systems(events)
Exemplo n.º 2
0
    def update(self, events, world):
        for event in events:
            if event.type == NEW_GAME:
                return SceneManager.new_root(GameScene())
            if event.type == CONTINUE:
                # we have no data to save right now, so just start a fresh game if we have a save file
                settings = world.find_component("settings")
                if path.exists(
                        path.join(user_data_dir(APP_NAME, APP_AUTHOR),
                                  settings["save_file"])):
                    with open(
                            path.join(user_data_dir(APP_NAME, APP_AUTHOR),
                                      settings["save_file"]),
                            "r",
                    ) as f:
                        loaded_json = json.load(f)
                        player_entity = world.find_entity("player")
                        player_entity.player.currency = loaded_json["currency"]
                        player_entity.player.hasCloudSleeves = loaded_json[
                            "hasCloudSleeves"]
                        player_entity.player.hasWings = loaded_json["hasWings"]
                        player_entity.player.hasJetBoots = loaded_json[
                            "hasJetBoots"]
                self.teardown(world)
                return SceneManager.push(EquipScene())
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                return SceneManager.pop()

        world.process_all_systems(events)
Exemplo n.º 3
0
    def update(self, events, world):
        context = world.find_component("context")
        settings = world.find_component("settings")
        context["paused"] = True

        exiting = False

        for event in events:
            if event.type == PAUSE_QUIT_TO_MENU:
                context["paused"] = False
                exiting = True
            elif event.type == PAUSE_SAVE_AND_QUIT:
                self._save(settings["save_file"], world)
                context["paused"] = False
                world.inject_event({
                    "type": "sound",
                    "action": "stop",
                    "sound": "background_music",
                })

                self.teardown(world)
                return SceneManager.push(scenes.equip.EquipScene())

        if exiting:
            world.inject_event({
                "type": "sound",
                "action": "stop",
                "sound": "background_music",
            })
            return SceneManager.new_root(scenes.title.TitleScene())

        world.process_all_systems(events)
Exemplo n.º 4
0
    def update(self, events, world):
        # Run all the systems registered in the world
        world.process_all_systems(events)

        # If a key press is detected, push the next scene
        for event in events:
            if event.type == SCENE_REFOCUS:
                self._transition_back_to(events, world)
            if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
                self._transition_away_from(events, world)
                return SceneManager.push(MenuScene())
Exemplo n.º 5
0
    def update(self, events, world):
        for event in events:
            if event.type == SCENE_REFOCUS:
                self._transition_back_to(events, world)
            if event.type == NEW_GAME:
                self.teardown(world)
                return SceneManager.new_root(GameScene())
            if event.type == CONTINUE:
                self.teardown(world)
                post(Event(LOAD))
                return SceneManager.new_root(GameScene())
            if event.type == CONTROLS:
                self._transition_away_from(events, world)
                return SceneManager.push(ControlsScene())
            if event.type == CREDITS:
                self._transition_away_from(events, world)
                return SceneManager.push(CreditsScene())
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                return SceneManager.pop()

        world.process_all_systems(events)
Exemplo n.º 6
0
    def update(self, events, world):

        # Start music loop
        world.inject_event({
            "type": "sound",
            "action": "start",
            "sound": "title_music",
        })

        # Run all the systems registered in the world
        world.process_all_systems(events)

        # If a key press is detected, push the next scene
        for event in events:
            if event.type == SCENE_REFOCUS:
                self._transition_back_to(events, world)
            if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
                self._transition_away_from(events, world)
                return SceneManager.push(MenuScene())
Exemplo n.º 7
0
    def update(self, events, world):

        # There will only ever be one player entity, unless scope drastically changes
        player_entity = world.filter("player")[0]

        # No physics until the player has jumped
        if player_entity.player.has_jumped:

            # First, clear out per-frame physics values
            world.inject_event({"type": "physics_frame_reset"})

            # TODO: Simulate gravity as a force, instead of just doing it in the movement system
            # world.inject_event({"type": "physics_force", "magnitude": 0, "angle": 90})

            # Then gliding, which translates rotation into acceleration
            world.inject_event({"type": "glide"})

            # Finally, we add movement after any events that could affect acceleration
            world.inject_event({"type": "move"})

        world.process_all_systems(events)

        keys = pygame.key.get_pressed()

        # Before doing anything else, the player must jump off the cliff
        if not player_entity.player.has_jumped:

            if keys[pygame.K_SPACE]:

                # Tell everyone we've jumped
                player_entity.player.has_jumped = True

                # The jump itself
                world.inject_event({
                    "type": "physics_force",
                    "magnitude": 5,
                    "angle": -20
                })

                # Start background music
                world.inject_event({
                    "type": "sound",
                    "action": "start",
                    "sound": "background_music",
                })

        # We don't want to rotate before jumping.
        # TODO: or do we?
        else:

            # The player only has direct control over their angle from the ground.
            # Our rudimentary physics takes care of the rest.
            # Also, clamp the angle from straight up to straight down.
            if keys[pygame.K_RIGHT]:
                angle = player_entity.rotation.angle + 1
                player_entity.rotation.angle = min(angle, 90)
            if keys[pygame.K_LEFT]:
                angle = player_entity.rotation.angle - 1
                player_entity.rotation.angle = max(angle, -90)

        for event in events:
            # Use keyup here as a simple way to only trigger once and not repeatedly
            if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
                return SceneManager.push(PauseScene())
Exemplo n.º 8
0
    def update(self, events, world):

        for event in events:
            if event.type == VICTORY:
                return SceneManager.replace(VictoryScene())

            if event.type == SCENE_REFOCUS:
                self.teardown(world)
                self.setup(world)

        # Loading should happen only AFTER refocusing, if both events have fired this frame
        for event in events:
            if event.type == LOAD:
                load(world)

        context = world.find_component("context")
        screen = context["screen"]

        # There will only ever be one player entity, unless scope drastically changes
        player_entity = world.filter("player")[0]

        # No physics until the player has jumped
        if player_entity.player.has_jumped:

            # First, clear out per-frame physics values
            world.inject_event({"type": "physics_frame_reset"})

            # TODO: Simulate gravity as a force, instead of just doing it in the movement system
            # world.inject_event({"type": "physics_force", "magnitude": 0, "angle": 90})

            # Then gliding, which translates rotation into acceleration
            world.inject_event({"type": "glide"})

            # Finally, we add movement after any events that could affect acceleration
            world.inject_event({"type": "move"})

            if calculate_altitude(player_entity, screen) > 0:

                # allow the deafening silence to emphasize the player's deadly mistake
                world.inject_event(
                    {
                        "type": "sound",
                        "action": "stop",
                        "sound": "background_music",
                    }
                )

                # also make a funny sound effect
                world.inject_event(
                    {
                        "type": "sound",
                        "action": "play",
                        "sound": "crash",
                    }
                )

                for sys in self.systems:
                    world.unregister_system(sys)
                return SceneManager.push(CrashResultsScene())

        world.process_all_systems(events)

        keys = pygame.key.get_pressed()
        mods = pygame.key.get_mods()

        # # Win button for debugging
        # if keys[pygame.K_v]:
        #     pygame.event.post(pygame.event.Event(VICTORY))

        # Before doing anything else, the player must jump off the cliff
        if not player_entity.player.has_jumped:

            if keys[pygame.K_SPACE] and not player_entity.player.jumping:

                # Tell everyone we've jumped
                player_entity.player.has_jumped = True
                player_entity.player.jumping = True

                # The jump itself
                world.inject_event(
                    {"type": "physics_force", "magnitude": 20, "angle": -20}
                )

                # Start background music
                world.inject_event(
                    {
                        "type": "sound",
                        "action": "start",
                        "sound": "background_music",
                    }
                )

        # We don't want to rotate before jumping. TODO: or do we?
        else:

            if player_entity.player.jumping:
                player_entity.rotation.angle += 0.5
                if player_entity.rotation.angle > 0:
                    player_entity.player.jumping = False

            rotation_speed = 1
            # If you have the wings upgrade, you can use shift to go back to slower rotation
            if player_entity.player.hasWings and not mods & pygame.KMOD_SHIFT:
                rotation_speed = 2

            # The player only has direct control over their angle from the ground.
            # Our rudimentary physics takes care of the rest.
            # Also, clamp the angle from straight up to straight down.
            if keys[pygame.K_RIGHT]:
                player_entity.player.jumping = False
                angle = player_entity.rotation.angle + rotation_speed
                player_entity.rotation.angle = min(angle, 90)
            if keys[pygame.K_LEFT]:
                player_entity.player.jumping = False
                angle = player_entity.rotation.angle - rotation_speed
                player_entity.rotation.angle = max(angle, -90)

            for event in events:
                if (
                    event.type == pygame.KEYDOWN
                    and event.key == pygame.K_SPACE
                    and player_entity.player.has_jumped
                    and player_entity.player.hasJetBoots
                    and player_entity.player.numBoosts > 0
                ):
                    player_entity.player.jumping = False
                    player_entity.player.numBoosts -= 1
                    world.inject_event(
                        {
                            "type": "physics_force",
                            "magnitude": 15,
                            "angle": player_entity.rotation.angle,
                        }
                    )

        for event in events:
            # Use keyup here as a simple way to only trigger once and not repeatedly
            if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
                return SceneManager.push(PauseScene())
Exemplo n.º 9
0
    def update(self, events, world):

        for event in events:
            if event.type == SCENE_REFOCUS:
                self.teardown(world)
                self.setup(world)

        # Loading MUST happen after refocusing
        for event in events:
            if event.type == LOAD:
                load(world)

        context = world.find_component("context")
        screen = context["screen"]

        # There will only ever be one player entity, unless scope drastically changes
        player_entity = world.filter("player")[0]

        # No physics until the player has jumped
        if player_entity.player.has_jumped:

            # First, clear out per-frame physics values
            world.inject_event({"type": "physics_frame_reset"})

            # TODO: Simulate gravity as a force, instead of just doing it in the movement system
            # world.inject_event({"type": "physics_force", "magnitude": 0, "angle": 90})

            # Then gliding, which translates rotation into acceleration
            world.inject_event({"type": "glide"})

            # Finally, we add movement after any events that could affect acceleration
            world.inject_event({"type": "move"})

            if calculate_altitude(player_entity, screen) > 0:
                for sys in self.systems:
                    world.unregister_system(sys)
                return SceneManager.push(CrashResultsScene())

        world.process_all_systems(events)

        keys = pygame.key.get_pressed()
        mods = pygame.key.get_mods()

        # TODO: this is just for debug purposes
        if keys[pygame.K_c]:
            player_entity.player.currency = 100000

        # Before doing anything else, the player must jump off the cliff
        if not player_entity.player.has_jumped:

            if keys[pygame.K_SPACE]:

                # Tell everyone we've jumped
                player_entity.player.has_jumped = True

                # The jump itself
                world.inject_event(
                    {"type": "physics_force", "magnitude": 10, "angle": -20}
                )

                # Start background music
                world.inject_event(
                    {
                        "type": "sound",
                        "action": "start",
                        "sound": "background_music",
                    }
                )

        # We don't want to rotate before jumping. TODO: or do we?
        else:

            rotation_speed = 1
            if player_entity.player.hasWings and not mods & pygame.KMOD_SHIFT:
                rotation_speed = 3

            # The player only has direct control over their angle from the ground.
            # Our rudimentary physics takes care of the rest.
            # Also, clamp the angle from straight up to straight down.
            if keys[pygame.K_RIGHT]:
                angle = player_entity.rotation.angle + rotation_speed
                player_entity.rotation.angle = min(angle, 90)
            if keys[pygame.K_LEFT]:
                angle = player_entity.rotation.angle - rotation_speed
                player_entity.rotation.angle = max(angle, -90)

            for event in events:
                if (
                    event.type == pygame.KEYDOWN
                    and event.key == pygame.K_SPACE
                    and player_entity.player.has_jumped
                    and player_entity.player.hasJetBoots
                    and player_entity.player.numBoosts > 0
                ):
                    player_entity.player.numBoosts -= 1
                    world.inject_event(
                        {
                            "type": "physics_force",
                            "magnitude": 50,
                            "angle": player_entity.rotation.angle,
                        }
                    )

        for event in events:
            # Use keyup here as a simple way to only trigger once and not repeatedly
            if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
                return SceneManager.push(PauseScene())