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


PHP Shape::isHit方法代码示例

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


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

示例1: isHit

 /**
  * @param CannonBall $cannonBall
  * @param Point $previousPoint
  * @return bool
  */
 public function isHit($cannonBall, $previousPoint)
 {
     //$cannonBall->pixels = array_values($cannonBall->pixels);
     $total = count($cannonBall->pixels);
     for ($index = 0; $index < $total; $index++) {
         //if(!isset($cannonBall->pixels[]))
         $pixel = $cannonBall->pixels[$index];
         $pixelPosition = new Point($cannonBall->position->x + $pixel->x, $cannonBall->position->y + $pixel->y);
         $hit = $this->body->isHit($pixelPosition);
         if ($hit !== false) {
             $pixelLevels = $this->bodyHeight <= $this->bodyWidth ? $this->bodyHeight : $this->bodyWidth;
             $currentPixelLevel = 0;
             $validHit = false;
             while (!$validHit && $currentPixelLevel <= $pixelLevels) {
                 $body_a_x = $this->body->a->x + $currentPixelLevel;
                 $body_b_y = $this->body->b->y + $currentPixelLevel;
                 $body_c_x = $this->body->c->x - $currentPixelLevel;
                 if ($hit->x >= $previousPoint->x) {
                     $x = $body_a_x <= $previousPoint->x ? $previousPoint->x : $body_a_x;
                     $y = $body_b_y <= $previousPoint->y ? $previousPoint->y : $body_b_y;
                     $x = $hit->x - ($hit->x - $x);
                     $y = $hit->y - ($hit->y - $y);
                 } else {
                     $x = $body_c_x >= $previousPoint->x ? $previousPoint->x : $body_c_x;
                     $y = $body_b_y <= $previousPoint->y ? $previousPoint->y : $body_b_y;
                     $x = $hit->x - ($hit->x - $x);
                     $y = $hit->y - ($hit->y - $y);
                 }
                 $x = (int) round($x);
                 $y = (int) round($y);
                 $validHit = true;
                 if (isset($this->destroyedParts[$x])) {
                     foreach ($this->destroyedParts[$x] as $destroyedY) {
                         if ($destroyedY == $y) {
                             $currentPixelLevel++;
                             $validHit = false;
                             break;
                         }
                     }
                 }
                 if ($validHit) {
                     $this->destroyedParts[$x][] = $y;
                     array_splice($cannonBall->pixels, $index, 1);
                     $index--;
                     $total--;
                 }
             }
             if (count($cannonBall->pixels) <= 0) {
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:nunomcb,项目名称:yoda-hipchat,代码行数:59,代码来源:index.php


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