当前位置: 首页>>代码示例>>PHP>>正文


PHP Position::distance方法代码示例

本文整理汇总了PHP中pocketmine\level\Position::distance方法的典型用法代码示例。如果您正苦于以下问题:PHP Position::distance方法的具体用法?PHP Position::distance怎么用?PHP Position::distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\level\Position的用法示例。


在下文中一共展示了Position::distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPosList

 public function getPosList()
 {
     $out = [];
     for ($x = $this->centre->getX() - $this->radius; $x <= $this->centre->getX() + $this->radius; $x++) {
         for ($y = $this->centre->getY() - $this->radius; $y <= $this->centre->getY() + $this->radius; $x++) {
             for ($z = $this->centre->getZ() - $this->radius; $z <= $this->centre->getZ() + $this->radius; $x++) {
                 $v = new Position($x, $y, $z, $this->centre->getLevel());
                 if ($v->distance($this->centre) <= $this->radius) {
                     $out[] = $v;
                 }
             }
         }
     }
     return $out;
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:15,代码来源:SphereSpace.php

示例2: getNearestPlayers

 /**
  * @param Position $center
  * @param callable[] $exceptions
  * @return array
  */
 public static function getNearestPlayers(Position $center, array $exceptions = [])
 {
     $currentDistance = PHP_INT_MAX;
     $nearest = [];
     foreach ($center->getLevel()->getPlayers() as $player) {
         foreach ($exceptions as $e) {
             if (call_user_func($e, $player) === false) {
                 $continue = true;
                 break;
             }
         }
         if (isset($continue)) {
             continue;
         }
         if ($player === $center) {
             continue;
         }
         if ($center->distance($player) === $currentDistance) {
             $nearest[] = $player;
         } elseif ($center->distance($player) < $currentDistance) {
             $nearest = [$player];
         }
     }
     return $nearest;
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:30,代码来源:CmdSel.php

示例3: fire

 public function fire()
 {
     foreach ($this->getServer()->getLevels() as $level) {
         if (!$level instanceof Level) {
             continue;
         }
         if (!isset($this->db["Sparklers"][$level->getFolderName()])) {
             continue;
         }
         foreach ($this->db["Sparklers"][$level->getFolderName()] as $keyPos => $keyValue) {
             $explode = explode(".", $keyPos);
             if (!isset($explode[2])) {
                 break;
             }
             // WRONG DATA
             $pillarPos = new Position($explode[0], $explode[1], $explode[2], $level);
             $players = [];
             foreach ($this->getServer()->getOnlinePlayers() as $player) {
                 if ($pillarPos->distance($player) < 25) {
                     $players[] = $player;
                 }
             }
             if (count($players) == 0) {
                 continue;
             }
             $level->addSound(new PopSound($pillarPos), $players);
             for ($h = 1; $h <= 11; $h++) {
                 $pillarPos->setComponents($pillarPos->x, ++$pillarPos->y, $pillarPos->z);
                 $level->addParticle(new DustParticle($pillarPos, 255, 255, 255, 255), $players);
             }
             $headPos = new Position($pillarPos->x, $pillarPos->y - 10, $pillarPos->z, $level);
             $r = mt_rand(0, 255);
             $g = mt_rand(0, 255);
             $b = mt_rand(0, 255);
             for ($r = 1; $r <= 5; $r++) {
                 $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3));
                 $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players);
                 // WHITE
             }
             $r = mt_rand(0, 255);
             $g = mt_rand(0, 255);
             $b = mt_rand(0, 255);
             for ($r = 1; $r <= 5; $r++) {
                 $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3));
                 $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players);
                 // GREEN
             }
             $r = mt_rand(0, 255);
             $g = mt_rand(0, 255);
             $b = mt_rand(0, 255);
             for ($r = 1; $r <= 5; $r++) {
                 $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3));
                 $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players);
                 // PINK
             }
             $r = mt_rand(0, 255);
             $g = mt_rand(0, 255);
             $b = mt_rand(0, 255);
             for ($r = 1; $r <= 5; $r++) {
                 $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3));
                 $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players);
                 // ORANGE
             }
             $r = mt_rand(0, 255);
             $g = mt_rand(0, 255);
             $b = mt_rand(0, 255);
             for ($r = 1; $r <= 5; $r++) {
                 $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3));
                 $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players);
                 // BLUE
             }
         }
     }
 }
开发者ID:nesgohood,项目名称:PMMP-Plugins,代码行数:74,代码来源:Sparklers.php


注:本文中的pocketmine\level\Position::distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。