Esempio n. 1
0
    def _set_ghost_eyes(self,
                        ghost_id,
                        direction,
                        cycle=None,
                        is_scared=False):
        ghost_ref = self._ghosts_ref[ghost_id]

        if is_scared:
            self._scene.add_action(
                scene_actions.ChangeSprite(ref=ghost_ref,
                                           cycle=cycle,
                                           child_ref=self._ghost_eyes_ref,
                                           sprite_asset=scene_actions.Asset(
                                               bundle_name='main',
                                               asset_name='GhostParts',
                                               index=4)))
        else:
            self._scene.add_action(
                scene_actions.ChangeSprite(
                    ref=ghost_ref,
                    cycle=cycle,
                    child_ref=self._ghost_eyes_ref,
                    sprite_asset=scene_actions.Asset(
                        bundle_name='main',
                        asset_name='GhostParts',
                        index=self._ghost_eyes_index[direction])))
Esempio n. 2
0
    def draw(self):
        self._scene.add_action(
            scene_actions.InstantiateBundleAsset(
                ref=self._top_panel_ref,
                asset=scene_actions.Asset(bundle_name='main',
                                          asset_name='TopPanel'),
                default_parent=scene_actions.EDefaultParent.RootCanvas))

        # Cycle
        self._set_cycle_text(0)

        # Agents
        for side in self._sides:
            agents = self._world.polices if side == 'Police' else self._world.terrorists
            table_ref = self._polices_table_ref if side == 'Police' else self._terrorists_table_ref
            agents_ref = self._polices_ref if side == 'Police' else self._terrorists_ref
            asset_name = 'PoliceStatus' if side == 'Police' else 'TerroristStatus'

            for agent in agents:
                reference = self._rm.new()
                agents_ref[agent.id] = reference

                self._scene.add_action(
                    scene_actions.InstantiateBundleAsset(
                        ref=reference,
                        parent_ref=self._top_panel_ref,
                        parent_child_ref=table_ref,
                        asset=scene_actions.Asset(bundle_name='main',
                                                  asset_name=asset_name),
                    ))
                self._set_text('Stats/ID', str(agent.id), reference)
                self._update_agent(reference, agent, side)
Esempio n. 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)
                ))
Esempio n. 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))
Esempio n. 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)
Esempio n. 6
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)))
Esempio n. 7
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
     ))
Esempio n. 8
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))
Esempio n. 9
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))
Esempio n. 10
0
    def draw_statuses(self):
        self._scene.add_action(
            scene_actions.InstantiateBundleAsset(
                ref=self._top_panel_ref,
                asset=scene_actions.Asset(bundle_name='main',
                                          asset_name='TopPanel'),
                default_parent=scene_actions.EDefaultParent.RootCanvas))

        # Cycle
        self._set_cycle_text(0)

        # Pacman health
        for i in range(self._world.pacman.health):
            new_ref = self._rm.new()
            self._health_images_ref.append(new_ref)

            self._scene.add_action(
                scene_actions.InstantiateBundleAsset(
                    ref=new_ref,
                    asset=scene_actions.Asset(bundle_name='main',
                                              asset_name='PacmanImage'),
                    parent_ref=self._top_panel_ref,
                    parent_child_ref=self._health_panel_ref))
Esempio n. 11
0
    def _draw_agents(self):
        for side in self._sides:
            agents = self._world.polices if side == 'Police' else self._world.terrorists
            skins = self.POLICE_SKINS if side == 'Police' else self.TERRORIST_SKINS
            material_offsets = self.POLICE_MATERIAL_OFFSETS if side == 'Police' else self.TERRORIST_MATERIAL_OFFSETS
            heads = self.POLICE_HEADS if side == 'Police' else self.TERRORIST_HEADS
            items = self.POLICE_ITEMS if side == 'Police' else self.TERRORIST_ITEMS

            for agent in agents:
                reference = self._rm.new()
                self._agents_ref[side][agent.id] = reference

                self._scene.add_action(
                    scene_actions.InstantiateBundleAsset(
                        ref=reference,
                        asset=scene_actions.Asset(bundle_name='main',
                                                  asset_name=side)))

                # set ID
                self._scene.add_action(
                    scene_actions.ChangeText(
                        ref=reference,
                        child_ref=
                        'Root/Hips/Spine_01/Spine_02/Spine_03/Neck/Head/Canvas/ID',
                        text=str(agent.id)))

                # set appearance
                skin = skins[agent.id % len(skins)]
                self._scene.add_action(
                    scene_actions.ChangeIsActive(
                        ref=reference,
                        child_ref='Skin/{0}'.format(skin),
                        is_active=True))

                material_num = (
                    ((agent.id // len(material_offsets)) +
                     material_offsets[agent.id % len(material_offsets)]) %
                    self.TOTAL_SKINS_MATERIALS) + 1
                self._scene.add_action(
                    scene_actions.ChangeMaterial(
                        ref=reference,
                        child_ref='Skin/{0}'.format(skin),
                        material_asset=scene_actions.Asset(
                            bundle_name='main',
                            asset_name='Material{:d}'.format(material_num)),
                        index=0))

                for head in heads[agent.id % len(heads)]:
                    if head == None:
                        continue
                    self._scene.add_action(
                        scene_actions.ChangeIsActive(
                            ref=reference,
                            child_ref=
                            'Root/Hips/Spine_01/Spine_02/Spine_03/Neck/Head/HeadMask/{0}'
                            .format(head),
                            is_active=True))

                for item in items[agent.id % len(items)]:
                    if item == None:
                        continue
                    self._scene.add_action(
                        scene_actions.ChangeIsActive(
                            ref=reference,
                            child_ref='Root/Hips/Items/{0}'.format(item),
                            is_active=True))

                self._scene.add_action(
                    scene_actions.ChangeIsActive(
                        ref=reference,
                        child_ref=
                        'Root/Hips/Spine_01/Spine_02/Spine_03/Clavicle_R/Shoulder_R/Elbow_R/Hand_R/{0}'
                        .format(side + 'Rifle'),
                        is_active=True))

                # set position
                self._agents_direction[side][agent.id] = agent.init_direction
                self._move_xz(reference, None, None, agent.position)
                self._turn_y(reference, None, None,
                             self.DIR_TO_ANGLE[agent.init_direction.name])
Esempio n. 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))
Esempio n. 13
0
 def _init_render_settings(self):
     self._scene.add_action(
         scene_actions.ChangeRenderSettings(
             skybox_asset=scene_actions.Asset(bundle_name='main',
                                              asset_name='Skybox'),
             ambient_intensity=1.5))