示例#1
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)))
示例#2
0
    def on_initialize_gui(self):
        print("initialize gui")

        self.CELL_SIZE = 1
        self.CELL_OFFSET = -3 / 2 * self.CELL_SIZE

        self.scene.add_action(
            scene_actions.ChangeCamera(
                ref=self.scene.rm.get('MainCamera'),
                clear_flag=scene_actions.ECameraClearFlag.SolidColor,
                background_color=scene_actions.Vector4(x=1, y=1, z=1, w=1),
                is_orthographic=True,
                orthographic_size=2,
                min_position=scene_actions.Vector3(x=-2, y=-2, z=-10),
                max_position=scene_actions.Vector3(x=2, y=2, z=-10),
                min_rotation=scene_actions.Vector2(x=0, y=0),
                max_rotation=scene_actions.Vector2(x=0, y=0),
                min_zoom=1,
                max_zoom=3))

        # Draw lines
        for i in range(1, 3):
            start = self._get_scene_position(i, 0, get_center=False)
            end = self._get_scene_position(i, 3, get_center=False)
            self._draw_line(scene_actions.Vector4(x=0, y=0, z=0),
                            (start['x'], start['y']), (end['x'], end['y']))
            self._draw_line(scene_actions.Vector4(x=0, y=0, z=0),
                            (start['y'], start['x']), (end['y'], end['x']))

        self.scene.add_action(scene_actions.EndCycle())
        self.scene.apply_actions()
示例#3
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)
                ))
示例#4
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))
示例#5
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)
示例#6
0
    def _init_camera(self):
        orthographic_size = self._world.height * self._cell_size / 2 + 2

        self._scene.add_action(scene_actions.ChangeCamera(
            ref = self._rm.get('MainCamera'),
            clear_flag = scene_actions.ECameraClearFlag.SolidColor,
            background_color = scene_actions.Vector4(x=0, y=19/255, z=48/255),
            is_orthographic = True,
            orthographic_size = orthographic_size,
            min_position = scene_actions.Vector3(x=self._x_offset, y=self._y_offset, z=-10),
            max_position = scene_actions.Vector3(x=-self._x_offset, y=-self._y_offset, z=-10),
            min_rotation = scene_actions.Vector2(x=0, y=0),
            max_rotation = scene_actions.Vector2(x=0, y=0),
            min_zoom = self._cell_size * 2,
            max_zoom = orthographic_size * 2
        ))
示例#7
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)))
示例#8
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)))
示例#9
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'])))
示例#10
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))
示例#11
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,
            ))
示例#12
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())
示例#13
0
    def _init_contants(self, config):
        self.CELL_SIZE = config['cell_size']
        self.X_OFFSET = -self._world.width / 2.0 * self.CELL_SIZE
        self.Z_OFFSET = -self._world.height / 2.0 * self.CELL_SIZE

        self.FOW_Y = 2.5
        self.VISIONS_Y = 0

        self.DIR_TO_ANGLE = {
            ECommandDirection.Up.name: 0,
            ECommandDirection.Right.name: 90,
            ECommandDirection.Down.name: 180,
            ECommandDirection.Left.name: -90
        }

        self.ANGLE_BETWEEN_OFFSET = -90

        self.BOMB_OPERATIONS_COMPLETED_SOUND_CYCLES = 1.5

        self.TURN_CYCLES = 0.3
        self.MOVE_CYCLES = 0.4
        self.STOP_CYCLES = 0.3

        self.EXPLOSION_OFFSET_CYCLES = 1
        self.EXPLOSION_CYCLES = 3
        self.EXPLOSION_SOUND_CYCLES = 2
        self.EXPLOSION_THROWBACK = 5
        self.EXPLOSION_THROWBACK_CYCLES = 2
        self.EXPLOSION_THROWBACK = 5

        self.SHOOT_OFFSET_CYCLES = 1
        self.BEFORE_SHOOT_CYCLES = 1
        self.SHOOT_CYCLES = 1
        self.SHOOT_THROWBACK_CYCLES = 2
        self.SHOOT_THROWBACK = 1
        self.SHOOT_ANGLE_BETWEEN_OFFSET = self.ANGLE_BETWEEN_OFFSET - 6

        self.DEEP_DOWN_Y = -7
        self.DEEP_DOWN_CYCLES = 5

        self.RIFLE_TRANSFORM = {
            'Police': {
                'Default': {
                    'position':
                    scene_actions.Vector3(x=11.8, y=5.6, z=-0.5),
                    'rotation':
                    scene_actions.Vector3(x=-21.869, y=97.065, z=263.517),
                },
                'Fire': {
                    'position':
                    scene_actions.Vector3(x=9.8, y=7.1, z=-2.2),
                    'rotation':
                    scene_actions.Vector3(x=10.032, y=80.775, z=260.71),
                }
            },
            'Terrorist': {
                'Default': {
                    'position':
                    scene_actions.Vector3(x=10.5, y=5.4, z=-2.6),
                    'rotation':
                    scene_actions.Vector3(x=-17.88, y=93.76501, z=266.088),
                },
                'Fire': {
                    'position':
                    scene_actions.Vector3(x=10.3, y=5.4, z=-1.6),
                    'rotation':
                    scene_actions.Vector3(x=9.580001, y=83.952, z=272.559),
                }
            }
        }

        self.WATER_Y = -2
        self.BEACH_SCALE_FACTOR = 0.1

        self.TOTAL_SKINS_MATERIALS = 4

        self.POLICE_SKINS = ['MaleSWAT', 'FemaleFBI', 'FemaleShirt', 'MaleFBI']
        self.POLICE_MATERIAL_OFFSETS = [0, 2, 2, 0]
        self.POLICE_HEADS = [[None], [None], ['WomanHair'], [None]]
        self.POLICE_ITEMS = [[None]]

        self.TERRORIST_SKINS = [
            'MaleSuitVest', 'FemaleSuitVest', 'MaleOverall', 'FemaleOverall'
        ]
        self.TERRORIST_MATERIAL_OFFSETS = [0, 2, 2, 0]
        self.TERRORIST_HEADS = [['Clown'], ['Chicken'],
                                ['ManHair', 'WeldersMask'], ['Trump'],
                                ['Horse'], ['Tiger'], ['Panda'], ['Balaclava'],
                                ['ManHair', 'Fox'], ['Hat'],
                                ['ManHair', 'Hockey'], ['Paperbag']]
        self.TERRORIST_ITEMS = [[None]]
示例#14
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))