Files
zombie-game/app/Game/Entities/WitchProjectile.php
T
2026-09-07 20:37:40 +02:00

78 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Game\Entities;
use App\Game\EntityList;
use App\Game\GameObject;
use App\Game\Room;
use App\Game\Vector2;
final class WitchProjectile extends GameObject
{
private EntityList $container;
private Room $room;
public float $size;
/** @var array<float> */
public array $color;
private float $time = 0.0;
public function __construct(
float $x,
float $y,
Vector2 $direction,
EntityList $container,
Room $room,
float $speed = 220.0,
float $size = 12.0,
array $color = [0.7, 0.2, 1.0, 1.0],
) {
parent::__construct($x, $y);
$this->container = $container;
$this->room = $room;
$this->velocity = $direction->mulS($speed);
$this->size = $size;
$this->color = $color;
$this->width = $size;
$this->height = $size;
}
public function kind(): string
{
return 'projectile';
}
public function update(float $dt): void
{
parent::update($dt);
$this->time += $dt;
if (
$this->pos->x < -$this->size
|| $this->pos->x > $this->room->width + $this->size
|| $this->pos->y < -$this->size
|| $this->pos->y > $this->room->height + $this->size
) {
$this->container->remove($this);
}
}
public function toSnapshot(): array
{
return [
'eid' => $this->eid,
'd' => $this->kind(),
'x' => round($this->pos->x, 1),
'y' => round($this->pos->y, 1),
'vx' => round($this->velocity->x, 1),
'vy' => round($this->velocity->y, 1),
's' => $this->size,
];
}
}