예제 #1
0
 def _change_background_music(self, music, cycle = None):
     self._scene.add_action(scene_actions.ChangeAudioSource(
         ref = self._background_music_ref,
         cycle = cycle,
         audio_clip_asset = scene_actions.Asset(bundle_name='main', asset_name=music),
         time = 0,
         play = True
     ))
예제 #2
0
    def _init_sounds(self):
        # Background Music
        self._scene.add_action(
            scene_actions.CreateBasicObject(
                ref=self._background_music_ref,
                type=scene_actions.EBasicObjectType.AudioSource))
        self._scene.add_action(
            scene_actions.ChangeAudioSource(
                ref=self._background_music_ref,
                audio_clip_asset=scene_actions.Asset(bundle_name='main',
                                                     asset_name='siren'),
                spatial_blend=0,
                play=True,
                loop=True))

        # Wakawaka Music
        self._scene.add_action(
            scene_actions.CreateBasicObject(
                ref=self._wakawaka_music_ref,
                type=scene_actions.EBasicObjectType.AudioSource))
        self._scene.add_action(
            scene_actions.ChangeAudioSource(
                ref=self._wakawaka_music_ref,
                audio_clip_asset=scene_actions.Asset(bundle_name='main',
                                                     asset_name='wakawaka'),
                spatial_blend=0,
                loop=True))

        # Eat ghost Music
        self._scene.add_action(
            scene_actions.CreateBasicObject(
                ref=self._eat_ghost_music_ref,
                type=scene_actions.EBasicObjectType.AudioSource))
        self._scene.add_action(
            scene_actions.ChangeAudioSource(
                ref=self._eat_ghost_music_ref,
                audio_clip_asset=scene_actions.Asset(bundle_name='main',
                                                     asset_name='eatghost'),
                spatial_blend=0,
                loop=True))
예제 #3
0
    def _play_sound(self, reference, child_ref, cycle, sound_name=None):
        clip_asset = None
        if sound_name != None:
            clip_asset = scene_actions.Asset(bundle_name='main',
                                             asset_name=sound_name)

        self._scene.add_action(
            scene_actions.ChangeAudioSource(ref=reference,
                                            child_ref=child_ref,
                                            cycle=cycle,
                                            play=True,
                                            time=0,
                                            audio_clip_asset=clip_asset))
예제 #4
0
    def update(self, current_cycle, events):
        is_eat_food = False
        is_kill_ghost = False
        is_pacman_dead = False
        dead_ghosts_id = []

        # Update Status
        self._game_status.update_statuses(current_cycle)

        # Manage events
        for event in events:

            # Move
            if event.type in [GuiEventType.MovePacman, GuiEventType.MoveGhost]:
                ref = self._pacman_ref if event.type == GuiEventType.MovePacman else self._ghosts_ref[
                    event.payload['id']]
                pos = self._get_scene_position(event.payload['new_pos'])
                is_ghost_dead = 'id' in event.payload and event.payload[
                    'id'] in dead_ghosts_id

                self._scene.add_action(
                    scene_actions.ChangeTransform(
                        ref=ref,
                        cycle=1 if is_ghost_dead else None,
                        duration_cycles=1
                        if not is_pacman_dead and not is_ghost_dead else None,
                        position=scene_actions.Vector3(x=pos['x'], y=pos['y']),
                        change_local=False))

            # Change Pacman direction
            elif event.type == GuiEventType.ChangePacmanDirection:
                angle = self._angle[event.payload['direction']]
                self._scene.add_action(
                    scene_actions.ChangeTransform(
                        ref=self._pacman_ref,
                        rotation=scene_actions.Vector3(z=angle),
                        change_local=False))

            # Change Ghost direction
            elif event.type == GuiEventType.ChangeGhostDirection:
                self._set_ghost_eyes(
                    event.payload['id'],
                    event.payload['direction'],
                    cycle=1 if event.payload['id'] in dead_ghosts_id else None)

            # Eat Food
            elif event.type == GuiEventType.EatFood:
                is_eat_food = True
                # Remove food
                self._scene.add_action(
                    scene_actions.Destroy(
                        cycle=self._eat_delay,
                        ref=self._foods_ref[event.payload["position"].x,
                                            event.payload["position"].y]))

            # Eat Super Food
            elif event.type == GuiEventType.EatSuperFood:
                is_eat_food = True
                # Remove super food
                self._scene.add_action(
                    scene_actions.Destroy(cycle=self._eat_delay,
                                          ref=self._super_foods_ref[
                                              event.payload["position"].x,
                                              event.payload["position"].y]))

                # Pacman giant form
                self._change_pacman_animation('PacmanSuper', self._eat_delay)
                self._change_background_music('intermission', self._eat_delay)

            # End Giant Form
            elif event.type == GuiEventType.EndGiantForm:
                # Go to default mode
                self._change_pacman_animation('PacmanNormal')
                self._change_background_music('siren')

            # Kill Pacman
            elif event.type == GuiEventType.KillPacman:
                is_pacman_dead = True
                self._scene.add_action(scene_actions.EndCycle())

                # stop eating sound
                if self._eating_food:
                    self._eating_food = False
                    self._stop_eating_sound()

                # Update health
                self._game_status.decrease_health()

                # Play death animation and music
                self._scene.add_action(
                    scene_actions.ChangeTransform(
                        ref=self._pacman_ref,
                        rotation=scene_actions.Vector3(z=0),
                        change_local=False))
                self._change_pacman_animation('PacmanDie')
                self._change_background_music('death')

                self._scene.add_action(scene_actions.EndCycle())
                self._scene.add_action(scene_actions.EndCycle())
                self._scene.add_action(scene_actions.EndCycle())

                # Back to normal after 3 cycle
                self._change_pacman_animation('PacmanNormal')
                self._change_background_music('siren')

            # Update giant form status
            elif event.type == GuiEventType.UpdateGiantFormStatus:
                self._game_status.update_super_text(event.payload['remaining'])

            # Kill Ghost
            elif event.type == GuiEventType.KillGhost:
                is_kill_ghost = True
                dead_ghosts_id.append(event.payload['id'])

        # kill ghost sound
        if is_kill_ghost:
            self._scene.add_action(
                scene_actions.ChangeAudioSource(ref=self._eat_ghost_music_ref,
                                                cycle=self._eat_delay,
                                                play=True,
                                                time=0))
            self._scene.add_action(
                scene_actions.ChangeAudioSource(ref=self._eat_ghost_music_ref,
                                                cycle=self._eat_delay + 1,
                                                play=False))

        # eating sound
        if is_eat_food and not self._eating_food:
            self._scene.add_action(
                scene_actions.ChangeAudioSource(ref=self._wakawaka_music_ref,
                                                cycle=self._eat_delay,
                                                play=True))
        elif not is_eat_food and self._eating_food:
            self._stop_eating_sound()

        self._eating_food = is_eat_food

        if not is_pacman_dead:
            self._scene.add_action(scene_actions.EndCycle())
예제 #5
0
 def _stop_eating_sound(self):
     self._scene.add_action(
         scene_actions.ChangeAudioSource(ref=self._wakawaka_music_ref,
                                         play=False))
예제 #6
0
 def _pause_sound(self, reference, child_ref, cycle):
     self._scene.add_action(
         scene_actions.ChangeAudioSource(ref=reference,
                                         child_ref=child_ref,
                                         cycle=cycle,
                                         play=False))