本文整理汇总了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;
}
示例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;
}
示例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
}
}
}
}