Esempio n. 1
0
 protected function check_range(Ship $target, Weapon $weapon)
 {
     $x = $target->getPos()['x'] - $this->getPos()['x'];
     $y = $target->getPos()['y'] - $this->getPos()['y'];
     $distance = sqrt(pow($x, 2) + pow($y, 2));
     if ($distance != 0) {
         if ($distance < $weapon->getRange()['short']) {
             return 1;
         } else {
             if ($distance < $weapon->getRange()['mid']) {
                 return 2;
             } else {
                 if ($distance < $weapon->getRange()['long']) {
                     return 3;
                 } else {
                     return 0;
                 }
             }
         }
     }
 }
Esempio n. 2
0
function posship(Ship $ship, $key)
{
    $pos = $ship->getPos();
    $size = $ship->getSize();
    $x = $pos['x'] * 10 + 2 * $pos['x'];
    $y = $pos['y'] * 10 + 2 * $pos['y'];
    $width = $size['height'] * 10 + 2 * $size['height'];
    if ($ship->getDirection() == Ship::SOUTH) {
        $rotate = 'transform-origin: 50% 50%;transform : rotate(90deg);';
    } else {
        if ($ship->getDirection() == Ship::NORTH) {
            $rotate = 'transform-origin: 50% 50%;transform : rotate(270deg);';
        } else {
            if ($ship->getDirection() == Ship::WEST) {
                $rotate = 'transform-origin: 50% 50%;transform : rotateY(180deg);';
            } else {
                $rotate = "";
            }
        }
    }
    echo '<div style=" ' . $rotate . 'position: absolute; left:' . $x . '; top:' . $y . ';">
	  	<img src="' . $ship->getSprite() . '" width ="' . $width . 'px" data-ship="' . $key . '"  class="ship"></div>';
}