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


PHP Monster::onUpdate方法代码示例

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


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

示例1: onUpdate

 public function onUpdate($currentTick)
 {
     $config = Server::getInstance()->getMobConfig();
     if ($config->get("living-zombie") == "true") {
         if (!isset($this->ai)) {
             $this->ai = new ZombieAI($this);
         }
         $this->ai->onUpdate($currentTick);
     }
     parent::onUpdate($currentTick);
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:11,代码来源:Zombie.php

示例2: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== false) {
         return false;
     }
     if ($this->getLevel()->getServer()->aiConfig["zombie"] != 2) {
         return parent::onUpdate($currentTick);
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->isAlive()) {
         /* Don't use time directly
          * Instead, get remainder of current time divided by 24,000
          * This tells us the time of day, which is what we really need
          */
         $timeOfDay = abs($this->getLevel()->getTime() % 24000);
         if (0 < $timeOfDay and $timeOfDay < 13000) {
             $this->setOnFire(2);
         }
         //僵尸起火
         $p = $this->getNearestPlayer();
         //找到最近的可以被仇恨的玩家
         if (!$p) {
             $this->hated = false;
             if (++$this->moveTicker >= 100) {
                 $this->moveDirection = $this->generateRandomDirection();
                 $this->moveTicker = 0;
             }
         } else {
             $this->hated = $p;
             if ($p->distance($this) <= $this->fire_r) {
                 $p->setOnFire(2);
             }
             //点燃玩家
             if (!$this->tempTicking) {
                 if (++$this->hateTicker >= 10 or $this->moveDirection == null) {
                     //每0.5秒获取僵尸前进的新方向
                     $this->moveDirection = $this->generateDirection($p);
                     $this->hateTicker = 0;
                 }
             }
         }
         if ($this->tempTicking) {
             //帮助僵尸寻找新的方向走出困境
             if (++$this->tempTicker >= 20) {
                 $this->tempTicking = false;
                 $this->tempTicker = 0;
             }
         }
         if ($this->hated instanceof Player) {
             //攻击玩家
             if ($this->hated->distance($this) < $this->attack_r) {
                 $this->hated->attack(2, new EntityDamageByEntityEvent($this, $this->hated, EntityDamageEvent::CAUSE_ENTITY_ATTACK, 2));
             }
         }
         if ($this->moveDirection != null) {
             if ($this->motionX ** 2 + $this->motionZ ** 2 <= $this->moveDirection->lengthSquared()) {
                 $motionY = $this->getVelY();
                 //僵尸运动计算
                 if ($motionY >= 0) {
                     $this->motionX = $this->moveDirection->x * $this->moveSpeed;
                     $this->motionZ = $this->moveDirection->z * $this->moveSpeed;
                     $this->motionY = $motionY;
                 } else {
                     $this->moveDirection = $this->generateRandomDirection();
                     //生成随机运动方向
                     $this->moveTicker = 0;
                     $this->tempTicking = true;
                 }
             }
         } else {
             $this->moveDirection = $this->generateRandomDirection();
             $this->moveTicker = 0;
         }
         //var_dump($this->moveDirection,$this->motionX,$this->motionZ);
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         if ($this->motionY == 0) {
             $this->motionY -= $this->gravity;
         }
         //重力计算
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($expectedPos->distanceSquared($this) > 0) {
             $this->moveDirection = $this->generateRandomDirection();
         }
         $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);
         $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:AnonymousProjects,项目名称:PocketMine-MP-Original,代码行数:98,代码来源:Zombie.php


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