Пример #1
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)
Пример #2
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)
                ))
Пример #3
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))
Пример #4
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)
Пример #5
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))
Пример #6
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])
Пример #7
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))