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


PHP Random::nextBoundedInt方法代码示例

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


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

示例1: placeObject

 public function placeObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     $this->treeHeight = $random->nextBoundedInt(4) + 6;
     $topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2));
     $lRadius = 2 + $random->nextBoundedInt(2);
     $this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - $random->nextBoundedInt(3));
     $radius = $random->nextBoundedInt(2);
     $maxR = 1;
     $minR = 0;
     for ($yy = 0; $yy <= $topSize; ++$yy) {
         $yyy = $y + $this->treeHeight - $yy;
         for ($xx = $x - $radius; $xx <= $x + $radius; ++$xx) {
             $xOff = abs($xx - $x);
             for ($zz = $z - $radius; $zz <= $z + $radius; ++$zz) {
                 $zOff = abs($zz - $z);
                 if ($xOff === $radius and $zOff === $radius and $radius > 0) {
                     continue;
                 }
                 if (!Block::$solid[$level->getBlockIdAt($xx, $yyy, $zz)]) {
                     $level->setBlockIdAt($xx, $yyy, $zz, $this->leafBlock);
                     $level->setBlockDataAt($xx, $yyy, $zz, $this->type);
                 }
             }
         }
         if ($radius >= $maxR) {
             $radius = $minR;
             $minR = 1;
             if (++$maxR > $lRadius) {
                 $maxR = $lRadius;
             }
         } else {
             ++$radius;
         }
     }
 }
开发者ID:TexusDark,项目名称:Ananas-MP,代码行数:35,代码来源:SpruceTree.php

示例2: growTree

 public static function growTree(ChunkManager $level, $x, $y, $z, Random $random, $type = 0)
 {
     switch ($type) {
         case Sapling::SPRUCE:
             $tree = new SpruceTree();
             break;
         case Sapling::BIRCH:
             if ($random->nextBoundedInt(39) === 0) {
                 $tree = new BirchTree(\true);
             } else {
                 $tree = new BirchTree();
             }
             break;
         case Sapling::JUNGLE:
             $tree = new JungleTree();
             break;
         case Sapling::OAK:
         default:
             $tree = new OakTree();
             /*if($random->nextRange(0, 9) === 0){
             			$tree = new BigTree();
             		}else{*/
             //}
             break;
     }
     if ($tree->canPlaceObject($level, $x, $y, $z, $random)) {
         $tree->placeObject($level, $x, $y, $z, $random);
     }
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:29,代码来源:Tree.php

示例3: placeObject

 public function placeObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     $this->treeHeight = $random->nextBoundedInt(3) + 5;
     if ($this->superBirch) {
         $this->treeHeight += 5;
     }
     parent::placeObject($level, $x, $y, $z, $random);
 }
开发者ID:kazuemon,项目名称:NIGHTMARE,代码行数:8,代码来源:BirchTree.php

示例4: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, $this->waterOdd) === 0) {
         $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
         $y = $random->nextBoundedInt(128);
         $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
         $pond = new \pocketmine\level\generator\object\Pond($random, new Water());
         if ($pond->canPlaceObject($level, $x, $y, $z)) {
             $pond->placeObject($level, $x, $y, $z);
         }
     }
 }
开发者ID:xHFx,项目名称:ImagicalMine,代码行数:12,代码来源:Pond.php

示例5: __construct

 public function __construct(Random $random, $octaves, $persistence, $expansion = 1)
 {
     $this->octaves = $octaves;
     $this->persistence = $persistence;
     $this->expansion = $expansion;
     $this->offsetX = $random->nextFloat() * 256;
     $this->offsetY = $random->nextFloat() * 256;
     $this->offsetZ = $random->nextFloat() * 256;
     for ($i = 0; $i < 512; ++$i) {
         $this->perm[$i] = 0;
     }
     for ($i = 0; $i < 256; ++$i) {
         $this->perm[$i] = $random->nextBoundedInt(256);
     }
     for ($i = 0; $i < 256; ++$i) {
         $pos = $random->nextBoundedInt(256 - $i) + $i;
         $old = $this->perm[$i];
         $this->perm[$i] = $this->perm[$pos];
         $this->perm[$pos] = $old;
         $this->perm[$i + 256] = $this->perm[$i];
     }
 }
开发者ID:mattiasaxelsson,项目名称:PocketMine-MP,代码行数:22,代码来源:Perlin.php

示例6: __construct

 public function __construct(Random $random, $octaves, $frequency, $amplitude, $lacunarity)
 {
     $this->octaves = $octaves;
     $this->frequency = $frequency;
     $this->lacunarity = $lacunarity;
     $this->amplitude = $amplitude;
     $this->offsetX = $random->nextFloat() * 256;
     $this->offsetY = $random->nextFloat() * 256;
     $this->offsetZ = $random->nextFloat() * 256;
     for ($i = 0; $i < 512; ++$i) {
         $this->perm[$i] = 0;
     }
     for ($i = 0; $i < 256; ++$i) {
         $this->perm[$i] = $random->nextBoundedInt(256);
     }
     for ($i = 0; $i < 256; ++$i) {
         $pos = $random->nextBoundedInt(256 - $i) + $i;
         $old = $this->perm[$i];
         $this->perm[$i] = $this->perm[$pos];
         $this->perm[$pos] = $old;
         $this->perm[$i + 256] = $this->perm[$i];
     }
 }
开发者ID:TylerGames,项目名称:PocketMine-MP,代码行数:23,代码来源:Perlin.php

示例7: placeObject

 public function placeObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     $this->treeHeight = $random->nextBoundedInt(3) + 4;
     parent::placeObject($level, $x, $y, $z, $random);
 }
开发者ID:xHFx,项目名称:ImagicalMine,代码行数:5,代码来源:OakTree.php

示例8: generateCaveBranch

 private function generateCaveBranch(ChunkManager $level, Vector3 $chunk, Vector3 $target, $horizontalScale, $verticalScale, $horizontalAngle, $verticalAngle, int $startingNode, int $nodeAmount, Random $random)
 {
     $middle = new Vector3($chunk->getX() + 8, 0, $chunk->getZ() + 8);
     $horizontalOffset = 0;
     $verticalOffset = 0;
     if ($nodeAmount <= 0) {
         $size = 7 * 16;
         $nodeAmount = $size - $random->nextBoundedInt($size / 4);
     }
     $intersectionMode = $random->nextBoundedInt($nodeAmount / 2) + $nodeAmount / 4;
     $extraVerticalScale = $random->nextBoundedInt(6) == 0;
     if ($startingNode == -1) {
         $startingNode = $nodeAmount / 2;
         $lastNode = true;
     } else {
         $lastNode = false;
     }
     for (; $startingNode < $nodeAmount; $startingNode++) {
         $horizontalSize = 1.5 + sin($startingNode * pi() / $nodeAmount) * $horizontalScale;
         $verticalSize = $horizontalSize * $verticalScale;
         $target = $target->add(VectorMath::getDirection3D($horizontalAngle, $verticalAngle));
         if ($extraVerticalScale) {
             $verticalAngle *= 0.92;
         } else {
             $verticalScale *= 0.7;
         }
         $verticalAngle += $verticalOffset * 0.1;
         $horizontalAngle += $horizontalOffset * 0.1;
         $verticalOffset *= 0.9;
         $horizontalOffset *= 0.75;
         $verticalOffset += ($random->nextFloat() - $random->nextFloat()) * $random->nextFloat() * 2;
         $horizontalOffset += ($random->nextFloat() - $random->nextFloat()) * $random->nextFloat() * 4;
         if (!$lastNode) {
             if ($startingNode == $intersectionMode and $horizontalScale > 1 and $nodeAmount > 0) {
                 $this->generateCaveBranch($level, $chunk, $target, $random->nextFloat() * 0.5 + 0.5, 1, $horizontalAngle - pi() / 2, $verticalAngle / 3, $startingNode, $nodeAmount, new Random($random->nextInt()));
                 $this->generateCaveBranch($level, $chunk, $target, $random->nextFloat() * 0.5 + 0.5, 1, $horizontalAngle - pi() / 2, $verticalAngle / 3, $startingNode, $nodeAmount, new Random($random->nextInt()));
                 return;
             }
             if ($random->nextBoundedInt(4) == 0) {
                 continue;
             }
         }
         $xOffset = $target->getX() - $middle->getX();
         $zOffset = $target->getZ() - $middle->getZ();
         $nodesLeft = $nodeAmount - $startingNode;
         $offsetHorizontalScale = $horizontalScale + 18;
         if ($xOffset * $xOffset + $zOffset * $zOffset - $nodesLeft * $nodesLeft > $offsetHorizontalScale * $offsetHorizontalScale) {
             return;
         }
         if ($target->getX() < $middle->getX() - 16 - $horizontalSize * 2 or $target->getZ() < $middle->getZ() - 16 - $horizontalSize * 2 or $target->getX() > $middle->getX() + 16 + $horizontalSize * 2 or $target->getZ() > $middle->getZ() + 16 + $horizontalSize * 2) {
             continue;
         }
         $start = new Vector3(floor($target->getX() - $horizontalSize) - $chunk->getX() - 1, floor($target->getY() - $verticalSize) - 1, floor($target->getZ() - $horizontalSize) - $chunk->getZ() - 1);
         $end = new Vector3(floor($target->getX() + $horizontalSize) - $chunk->getX() + 1, floor($target->getY() + $verticalSize) + 1, floor($target->getZ() + $horizontalSize) - $chunk->getZ() + 1);
         $node = new CaveNode($level, $chunk, $start, $end, $target, $verticalSize, $horizontalSize);
         if ($node->canPlace()) {
             $node->place();
         }
         if ($lastNode) {
             break;
         }
     }
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:63,代码来源:Cave.php


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