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