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


PHP Animal::onUpdate方法代码示例

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


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

示例1: onUpdate

 public function onUpdate($tick)
 {
     parent::onUpdate($tick);
     if ($this->age > 20) {
         $this->kill();
         $this->close();
     }
     return true;
 }
开发者ID:yungtechboy1,项目名称:Genisys,代码行数:9,代码来源:Lightning.php

示例2: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== false) {
         return false;
     }
     if (++$this->switchDirectionTicker === 100) {
         $this->switchDirectionTicker = 0;
         if (mt_rand(0, 100) < 50) {
             $this->swimDirection = null;
         }
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->isAlive()) {
         if ($this->y > 62 and $this->swimDirection !== null) {
             $this->swimDirection->y = -0.5;
         }
         /*$inWater = $this->isInsideOfAir();
         		if(!$inWater){
         			//$this->motionY -= $this->gravity;
         			$this->swimDirection = null;
         		}else*/
         if ($this->swimDirection !== null) {
             if ($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()) {
                 $this->motionX = $this->swimDirection->x * $this->swimSpeed;
                 $this->motionY = $this->swimDirection->y * $this->swimSpeed;
                 $this->motionZ = $this->swimDirection->z * $this->swimSpeed;
             }
         } else {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = mt_rand(50, 100);
         }
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($expectedPos->distanceSquared($this) > 0) {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = mt_rand(50, 100);
         }
         $friction = 1 - $this->drag;
         $this->motionX *= $friction;
         $this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         $f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
         $this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         $this->pitch = -atan2($f, $this->motionY) * 180 / M_PI;
         if ($this->onGround) {
             $this->motionY *= -0.5;
         }
         $this->updateMovement();
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
 }
开发者ID:PepbookPvP,项目名称:Genisys,代码行数:54,代码来源:Bat.php

示例3: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->knockback) {
         if (time() < $this->knockback) {
             return parent::onUpdate($currentTick);
         }
         $this->knockback = 0;
     }
     $hasUpdate = false;
     $this->timings->startTiming();
     // Handle flying objects...
     $tickDiff = max(1, $currentTick - $this->lastUpdate);
     $bb = clone $this->getBoundingBox();
     $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0;
     if (!$onGround) {
         // falling or jumping...
         $this->motionY -= $this->gravity;
         $this->x += $this->motionX * $tickDiff;
         $this->y += $this->motionY * $tickDiff;
         $this->z += $this->motionZ * $tickDiff;
         //echo ("Falling...\n");
     } else {
         $this->motionX = 0;
         // No longer jumping/falling
         $this->motionY = 0;
         $this->motionZ = 0;
         if ($this->y != floor($this->y)) {
             $this->y = floor($this->y);
         }
         // Try to attack a player
         list($target, $dist) = $this->findTarget();
         if ($target !== null && $dist > 0 && $dist > self::$mindist) {
             $dir = $target->subtract($this);
             $dir = $dir->divide($dist);
             $this->yaw = rad2deg(atan2(-$dir->getX(), $dir->getZ()));
             $this->pitch = rad2deg(atan(-$dir->getY()));
             $x = $dir->getX() * self::$speed;
             $y = 0;
             $z = $dir->getZ() * self::$speed;
         } else {
             $x = (mt_rand() / mt_getrandmax() * 2 - 1) * self::$speed;
             $y = 0;
             $z = (mt_rand() / mt_getrandmax() * 2 - 1) * self::$speed;
             $this->yaw = rad2deg(atan2(-$x, $z));
         }
         $isJump = count($this->level->getCollisionBlocks($bb->offset($x, 1.2, $z))) <= 0;
         if (count($this->level->getCollisionBlocks($bb->offset(0, 0.1, $z))) > 0) {
             if ($isJump) {
                 $y = self::$jump;
                 $this->motionZ = $z;
             }
             $z = 0;
         }
         if (count($this->level->getCollisionBlocks($bb->offset($x, 0.1, 0))) > 0) {
             if ($isJump) {
                 $y = self::$jump;
                 $this->motionX = $x;
             }
             $x = 0;
         }
         //if ($y) echo "Jumping\n";
         $ev = new \pocketmine\event\entity\EntityMotionEvent($this, new \pocketmine\math\Vector3($x, $y, $z));
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $this->x += $x;
         $this->y += $y;
         $this->z += $z;
     }
     $bb = clone $this->getBoundingBox();
     $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0;
     $this->onGround = $onGround;
     $this->timings->stopTiming();
     $hasUpdate = parent::onUpdate($currentTick) || $hasUpdate;
     return $hasUpdate;
 }
开发者ID:AvivShopen,项目名称:bad-plugins,代码行数:77,代码来源:Chicken.php

示例4: onUpdate

 public function onUpdate($currentTick)
 {
     $hasUpdate = false;
     $this->timings->startTiming();
     // Handle flying objects...
     $tickDiff = max(1, $currentTick - $this->lastUpdate);
     $bb = clone $this->getBoundingBox();
     $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0;
     if (!$onGround) {
         // falling or jumping...
         $this->motionY -= $this->gravity;
         $this->x += $this->motionX * $tickDiff;
         $this->y += $this->motionY * $tickDiff;
         $this->z += $this->motionZ * $tickDiff;
         //echo ("Falling...\n");
     } else {
         $this->motionX = 0;
         // No longer jumping/falling
         $this->motionY = 0;
         $this->motionZ = 0;
         if ($this->y != floor($this->y)) {
             $this->y = floor($this->y);
         }
         // Try to attack a player
         $target = null;
         if ($this->petOwner->player) {
             $target = $this->petOwner->player;
             if ($target) {
                 if ($target->getLevel() != $this->level) {
                     // Pet is in a different level...
                     $target = null;
                 } else {
                     $dist = $this->distance($target);
                 }
             }
         }
         // if no target despawn
         if ($target === null) {
             $this->close();
             return;
         }
         if ($target !== null && $dist != 0) {
             $dir = $target->getLevel()->getSafeSpawn($target)->subtract($this);
             $dir = $dir->divide($dist);
             $this->yaw = rad2deg(atan2(-$dir->getX(), $dir->getZ()));
             $this->pitch = rad2deg(atan(-$dir->getY()));
             // if dist to owner < move dist or pet is being told to stay just look at owner
             if ($dist <= self::$dist || $this->isSitting) {
                 //$this->yaw = rad2deg(atan2(-$dir->getX(),$dir->getZ()));
                 //$this->pitch = rad2deg(atan(-$dir->getY()));
                 $this->updateMovement();
                 $this->level->addEntityMovement($this->chunk->getX(), $this->chunk->getZ(), $this->id, $this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->yaw);
             }
             // otherwise do a full movement
             if ($dist > self::$dist && !$this->isSitting) {
                 $x = $dir->getX() * self::$speed;
                 $y = 0;
                 $z = $dir->getZ() * self::$speed;
                 $isJump = count($this->level->getCollisionBlocks($bb->offset($x, 1.2, $z))) <= 0;
                 if (count($this->level->getCollisionBlocks($bb->offset(0, 0.1, $z))) > 0) {
                     if ($isJump) {
                         $y = self::$jump;
                         $this->motionZ = $z;
                     }
                     $z = 0;
                 }
                 if (count($this->level->getCollisionBlocks($bb->offset($x, 0.1, 0))) > 0) {
                     if ($isJump) {
                         $y = self::$jump;
                         $this->motionX = $x;
                     }
                     $x = 0;
                 }
                 //if ($y) echo "Jumping\n";
                 $ev = new \pocketmine\event\entity\EntityMotionEvent($this, new \pocketmine\math\Vector3($x, $y, $z));
                 $this->server->getPluginManager()->callEvent($ev);
                 if ($ev->isCancelled()) {
                     return false;
                 }
                 $this->x += $x;
                 $this->y += $y;
                 $this->z += $z;
             }
             if ($dist > 40) {
                 $target->sendMessage($this->petName_unformatted . " could not keep up - use /pet spawn again to bring them back");
                 $this->close();
             }
         }
     }
     $bb = clone $this->getBoundingBox();
     $onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0;
     $this->onGround = $onGround;
     $this->timings->stopTiming();
     $hasUpdate = parent::onUpdate($currentTick) || $hasUpdate;
     return $hasUpdate;
 }
开发者ID:flaxues,项目名称:BuddyPets,代码行数:96,代码来源:Pet.php


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