예제 #1
0
 /**
  * @param CannonBall $object
  * @return bool
  */
 public function isHit($object)
 {
     if ($object instanceof CannonBall) {
         foreach ($object->pixels as $pixel) {
             if (!$pixel->destroyedLocation) {
                 $currentPosition = Math::pointSum($object->position, $pixel);
                 $previousPosition = Math::pointSum($object->previousPosition, $pixel);
                 if (!$this->triggered && ($currentPosition->x >= $this->position->x && $previousPosition->x <= $this->position->x)) {
                     $diff = Math::pointDiff($currentPosition, $previousPosition);
                     $slope = 0;
                     if ($diff->x != 0) {
                         $slope = -1 * ($diff->y / $diff->x);
                     }
                     $intercept = $this->position->y - $previousPosition->y;
                     $intersectPoint = new Point($this->position->x, $this->position->y + ($slope * ($this->position->x - $previousPosition->x) - $intercept));
                     if ($intersectPoint->y >= $this->position->y && $intersectPoint->y <= $this->position->y + 13) {
                         $this->triggered = true;
                         $this->powerCordColor = Color::WHITE;
                         return $this->triggered;
                     }
                 }
             }
         }
     }
     return false;
 }