예제 #1
0
    def _draw_board(self):
        for y in range(self._world.height):
            for x in range(self._world.width):
                cell = self._world.board[y][x]
                if cell == ECell.Empty: continue

                scene_pos = self._get_scene_position(x=x, y=y)
                z = 5
                reference = self._rm.new()

                # if cell == ECell.Wall and (y == self._world.height - 1 or y == 0 or x == self._world.width - 1 or x == 0):
                #     self._scene.add_action(scene_actions.InstantiateBundleAsset(
                #         ref = reference,
                #         asset = scene_actions.Asset(bundle_name='main', asset_name='Wall')
                #     ))
                #     self._scene.add_action(scene_actions.ChangeSprite(
                #         ref = reference,
                #         sprite_asset = scene_actions.Asset(bundle_name='main', asset_name='Walls', index=0)
                #     ))

                if cell == ECell.Wall:
                    wall_type, wall_angle = self._get_wall_type_angle(x, y)
                    if wall_type == None: continue

                    self._scene.add_action(scene_actions.InstantiateBundleAsset(
                        ref = reference,
                        asset = scene_actions.Asset(bundle_name='main', asset_name='Wall')
                    ))
                    self._scene.add_action(scene_actions.ChangeSprite(
                        ref = reference,
                        sprite_asset = scene_actions.Asset(bundle_name='main', asset_name='Walls', index=wall_type)
                    ))
                    self._scene.add_action(scene_actions.ChangeTransform(
                        ref = reference,
                        rotation = scene_actions.Vector3(z=wall_angle)
                    ))

                elif cell == ECell.Food:
                    self._foods_ref[x, y] = reference
                    self._scene.add_action(scene_actions.InstantiateBundleAsset(
                        ref = reference,
                        asset = scene_actions.Asset(bundle_name='main', asset_name='Food')
                    ))

                elif cell == ECell.SuperFood:
                    self._super_foods_ref[x, y] = reference
                    self._scene.add_action(scene_actions.InstantiateBundleAsset(
                        ref = reference,
                        asset = scene_actions.Asset(bundle_name='main', asset_name='SuperFood')
                    ))

                # Set Position
                self._scene.add_action(scene_actions.ChangeTransform(
                    ref = reference,
                    position = scene_actions.Vector3(x=scene_pos['x'], y=scene_pos['y'], z=z)
                ))
예제 #2
0
    def _init_fow(self):
        for y in range(self._world.height):
            for x in range(self._world.width):
                fow_ref = self._rm.new()
                police_vision_ref = self._rm.new()
                terrorist_vision_ref = self._rm.new()
                self._fows_ref[(x, y)] = fow_ref
                self._police_visions_ref[(x, y)] = police_vision_ref
                self._terrorist_visions_ref[(x, y)] = terrorist_vision_ref

                pos = self._get_scene_position(Position(x=x, y=y))

                self._scene.add_action(
                    scene_actions.InstantiateBundleAsset(
                        ref=fow_ref,
                        asset=scene_actions.Asset(bundle_name='main',
                                                  asset_name='FOW')))
                self._scene.add_action(
                    scene_actions.ChangeTransform(
                        ref=fow_ref,
                        position=scene_actions.Vector3(x=pos['x'],
                                                       y=self.FOW_Y,
                                                       z=pos['z'])))

                self._scene.add_action(
                    scene_actions.InstantiateBundleAsset(
                        ref=police_vision_ref,
                        asset=scene_actions.Asset(bundle_name='main',
                                                  asset_name='PoliceVision')))
                self._scene.add_action(
                    scene_actions.ChangeTransform(
                        ref=police_vision_ref,
                        position=scene_actions.Vector3(x=pos['x'],
                                                       y=self.VISIONS_Y,
                                                       z=pos['z'])))
                self._scene.add_action(
                    scene_actions.ChangeIsActive(ref=police_vision_ref,
                                                 is_active=False))

                self._scene.add_action(
                    scene_actions.InstantiateBundleAsset(
                        ref=terrorist_vision_ref,
                        asset=scene_actions.Asset(
                            bundle_name='main', asset_name='TerroristVision')))
                self._scene.add_action(
                    scene_actions.ChangeTransform(
                        ref=terrorist_vision_ref,
                        position=scene_actions.Vector3(x=pos['x'],
                                                       y=self.VISIONS_Y,
                                                       z=pos['z'])))
                self._scene.add_action(
                    scene_actions.ChangeIsActive(ref=terrorist_vision_ref,
                                                 is_active=False))
예제 #3
0
    def _draw_players(self):
        # Draw pacman
        pacman_angle = self._angle[self._world.pacman.direction]
        scene_pos = self._get_scene_position(self._world.pacman.position)
        self._pacman_ref = drm.new()

        self._scene.add_action(
            scene_actions.InstantiateBundleAsset(ref=self._pacman_ref,
                                                 asset=scene_actions.Asset(
                                                     bundle_name='main',
                                                     asset_name='Pacman')))
        self._scene.add_action(
            scene_actions.ChangeTransform(
                ref=self._pacman_ref,
                position=scene_actions.Vector3(x=scene_pos['x'],
                                               y=scene_pos['y'],
                                               z=0),
                rotation=scene_actions.Vector3(z=pacman_angle),
                change_local=False))

        # Draw ghosts
        for ghost in self._world.ghosts:
            scene_pos = self._get_scene_position(ghost.position)
            self._ghosts_ref[ghost.id] = drm.new()
            color = self._ghosts_color[ghost.id % len(self._ghosts_color)]

            self._scene.add_action(
                scene_actions.InstantiateBundleAsset(
                    ref=self._ghosts_ref[ghost.id],
                    asset=scene_actions.Asset(bundle_name='main',
                                              asset_name='Ghost')))
            self._scene.add_action(
                scene_actions.ChangeTransform(ref=self._ghosts_ref[ghost.id],
                                              position=scene_actions.Vector3(
                                                  x=scene_pos['x'],
                                                  y=scene_pos['y'],
                                                  z=0),
                                              change_local=False))
            # Change color
            self._scene.add_action(
                scene_actions.ChangeSprite(ref=self._ghosts_ref[ghost.id],
                                           child_ref='Body',
                                           color=color))
            self._scene.add_action(
                scene_actions.ChangeSprite(ref=self._ghosts_ref[ghost.id],
                                           child_ref='Foots',
                                           color=color))

            self._set_ghost_eyes(ghost.id, ghost.direction)
예제 #4
0
 def _turn_y(self, reference, cycle, duration_cycles, angle):
     self._scene.add_action(
         scene_actions.ChangeTransform(
             ref=reference,
             cycle=cycle,
             duration_cycles=duration_cycles,
             rotation=scene_actions.Vector3(y=angle)))
예제 #5
0
    def _init_camera(self):
        fov = 60  # TODO: calculate
        extra_camera_boundry = -10

        self._scene.add_action(
            scene_actions.ChangeCamera(
                ref=self._rm.get('MainCamera'),
                is_orthographic=False,
                field_of_view=fov,
                min_position=scene_actions.Vector3(
                    x=(self.X_OFFSET + extra_camera_boundry),
                    y=2,
                    z=(self.Z_OFFSET + extra_camera_boundry)),
                max_position=scene_actions.Vector3(
                    x=-(self.X_OFFSET + extra_camera_boundry),
                    y=100,
                    z=-(self.Z_OFFSET + extra_camera_boundry)),
                min_zoom=fov - 20,
                max_zoom=fov + 40,
                post_process_profile_asset=scene_actions.Asset(
                    bundle_name='main', asset_name='PostProcess'),
            ))
        self._scene.add_action(
            scene_actions.ChangeTransform(ref=self._rm.get('MainCamera'),
                                          position=scene_actions.Vector3(
                                              x=0,
                                              y=10,
                                              z=(self.Z_OFFSET +
                                                 extra_camera_boundry)),
                                          rotation=scene_actions.Vector3(x=30,
                                                                         y=0,
                                                                         z=0)))
예제 #6
0
    def _deep_down(self, reference, cycle):
        cycle = cycle if cycle != None else 0

        self._scene.add_action(
            scene_actions.ChangeTransform(
                ref=reference,
                cycle=cycle,
                duration_cycles=self.DEEP_DOWN_CYCLES,
                position=scene_actions.Vector3(y=self.DEEP_DOWN_Y)))
예제 #7
0
 def _move_xz(self, reference, cycle, duration_cycles, position):
     scene_position = self._get_scene_position(position)
     self._scene.add_action(
         scene_actions.ChangeTransform(ref=reference,
                                       cycle=cycle,
                                       duration_cycles=duration_cycles,
                                       position=scene_actions.Vector3(
                                           x=scene_position['x'],
                                           z=scene_position['z'])))
예제 #8
0
 def _change_rifle_transform(self, reference, cycle, side, state):
     self._scene.add_action(
         scene_actions.ChangeTransform(
             ref=reference,
             child_ref=
             'Root/Hips/Spine_01/Spine_02/Spine_03/Clavicle_R/Shoulder_R/Elbow_R/Hand_R/{}Rifle'
             .format(side),
             cycle=cycle,
             position=self.RIFLE_TRANSFORM[side][state]['position'],
             rotation=self.RIFLE_TRANSFORM[side][state]['rotation']))
예제 #9
0
 def _init_light(self):
     main_light = self._rm.new()
     self._scene.add_action(
         scene_actions.CreateBasicObject(
             ref=main_light, type=scene_actions.EBasicObjectType.Light))
     self._scene.add_action(
         scene_actions.ChangeTransform(ref=main_light,
                                       rotation=scene_actions.Vector3(x=90,
                                                                      y=0,
                                                                      z=0)))
     self._scene.add_action(
         scene_actions.ChangeLight(ref=main_light, shadow_strength=0.4))
예제 #10
0
    def _draw_O(self, x, y):
        scene_pos = self._get_scene_position(x, y)

        ref = self.scene.rm.new()
        self.scene.add_action(
            scene_actions.CreateBasicObject(
                ref=ref,
                type=scene_actions.EBasicObjectType.Ellipse2D,
            ))
        self.scene.add_action(
            scene_actions.ChangeTransform(
                ref=ref,
                position=scene_actions.Vector3(x=scene_pos['x'],
                                               y=scene_pos['y']),
            ))
        self.scene.add_action(
            scene_actions.ChangeEllipse2D(
                ref=ref,
                duration_cycles=1,
                fill_color=scene_actions.Vector4(x=1, y=0, z=0, w=1),
                x_radius=0.3,
                y_radius=0.3,
            ))
예제 #11
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())
예제 #12
0
    def _draw_board(self):
        ground_ref = self._rm.new()
        self._scene.add_action(
            scene_actions.InstantiateBundleAsset(ref=ground_ref,
                                                 asset=scene_actions.Asset(
                                                     bundle_name='main',
                                                     asset_name='Ground')))
        self._scene.add_action(
            scene_actions.ChangeTransform(
                ref=ground_ref,
                child_ref='Beach',
                scale=scene_actions.Vector3(
                    x=self._world.width * self.CELL_SIZE *
                    self.BEACH_SCALE_FACTOR,
                    z=self._world.height * self.CELL_SIZE *
                    self.BEACH_SCALE_FACTOR)))

        water_ref = self._rm.new()
        self._scene.add_action(
            scene_actions.InstantiateBundleAsset(ref=water_ref,
                                                 asset=scene_actions.Asset(
                                                     bundle_name='main',
                                                     asset_name='Water')))
        self._scene.add_action(
            scene_actions.ChangeTransform(
                ref=water_ref, position=scene_actions.Vector3(y=self.WATER_Y)))

        # Draw non-player cells
        for y in range(self._world.height):
            for x in range(self._world.width):
                cell = self._world.board[y][x]

                if cell == ECell.Empty:
                    continue

                reference = self._rm.new()

                if cell == ECell.Wall:
                    self._scene.add_action(
                        scene_actions.InstantiateBundleAsset(
                            ref=reference,
                            asset=scene_actions.Asset(bundle_name='main',
                                                      asset_name='Barrier')))

                elif cell in [
                        ECell.SmallBombSite, ECell.MediumBombSite,
                        ECell.LargeBombSite, ECell.VastBombSite
                ]:
                    self._bombsites_ref[(x, y)] = reference
                    self._scene.add_action(
                        scene_actions.InstantiateBundleAsset(
                            ref=reference,
                            asset=scene_actions.Asset(bundle_name='main',
                                                      asset_name=cell.name)))

                    # Add floor
                    floor_ref = self._rm.new()
                    self._scene.add_action(
                        scene_actions.InstantiateBundleAsset(
                            ref=floor_ref,
                            asset=scene_actions.Asset(bundle_name='main',
                                                      asset_name='BombFloor')))
                    self._move_xz(floor_ref, None, None, Position(x=x, y=y))

                # Set Position
                self._move_xz(reference, None, None, Position(x=x, y=y))