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

50 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Game\Entities;
use App\Game\EntityList;
use App\Game\Player;
use App\Game\Room;
final class MegaTank extends Zombie
{
public function __construct(
float $x,
float $y,
EntityList $container,
Room $room,
?Player $initialTarget,
array $config = [],
?callable $onDeath = null,
) {
$spawnCount = $config['spawnCount'] ?? 3;
$spawnOnDeath = $config['spawnOnDeath'] ?? null;
parent::__construct($x, $y, $container, $room, $config, $onDeath ?? function (Zombie $mega) use ($spawnCount, $spawnOnDeath): void {
if ($spawnOnDeath === null) {
return;
}
for ($i = 0; $i < $spawnCount; $i++) {
$angle = ($i / $spawnCount) * M_PI * 2.0;
$offset = $mega->size + 28.0;
$spawnOnDeath(
$mega->pos->x + cos($angle) * $offset,
$mega->pos->y + sin($angle) * $offset,
$mega->container,
$mega->room,
$mega->target,
);
}
});
if ($initialTarget !== null) {
$this->target = $initialTarget;
}
}
public function kind(): string
{
return 'megatank';
}
}