Only auto aim and healthbars

This commit is contained in:
armel committed 2026-09-07 23:02:47 +02:00
1 parent 54c6327ac7
commit a914bd74fe
14 files changed
+95 -89

No files matched your search

+2 -3
View File
@@ -240,7 +240,6 @@ final class GameSimulator
$keys = is_array($frame['keys'] ?? null) ? $frame['keys'] : [];
$input->keys = array_values(array_filter($keys, 'is_string'));
$input->fire = (bool) ($frame['fire'] ?? false);
$input->autoAim = (bool) ($frame['autoAim'] ?? false);
$aim = $frame['aim'] ?? null;
if (is_array($aim)) {
@@ -265,10 +264,8 @@ final class GameSimulator
$entry['engine']->tick($dt);
if ($room->state === Room::STATE_OVER) {
$room->seq++;
$this->broadcastRoom($room);
} elseif ($this->frame % self::SNAPSHOT_EVERY === 0) {
$room->seq++;
$this->broadcastRoom($room);
}
}
@@ -280,6 +277,8 @@ final class GameSimulator
return;
}
$room->seq++;
$players = [];
foreach ($room->players as $player) {
$players[] = $player->toSnapshot();
-5
View File
@@ -14,18 +14,14 @@ final class InputState
public bool $fire;
public bool $autoAim;
public function __construct(
array $keys = [],
?Vector2 $aim = null,
bool $fire = false,
bool $autoAim = false,
) {
$this->keys = $keys;
$this->aim = $aim ?? new Vector2(1.0, 0.0);
$this->fire = $fire;
$this->autoAim = $autoAim;
}
public function reset(?Vector2 $aim = null): void
@@ -33,6 +29,5 @@ final class InputState
$this->keys = [];
$this->aim = $aim ?? new Vector2(1.0, 0.0);
$this->fire = false;
$this->autoAim = false;
}
}
+9 -14
View File
@@ -60,8 +60,6 @@ final class Player extends GameObject
public bool $dead = false;
public bool $autoAim = false;
private float $cooldown = 0.0;
private Vector2 $aimDirection;
@@ -154,22 +152,19 @@ final class Player extends GameObject
);
$aim = $this->input->aim;
$autoAimActive = $this->input->autoAim || $this->autoAim;
$hasTarget = false;
if ($autoAimActive) {
$nearest = $this->nearestZombie();
if ($nearest !== null) {
$hasTarget = true;
$toEnemy = $nearest->pos->subV($this->pos);
if ($toEnemy->lengthSquared() > 1.0) {
$aim = $toEnemy;
}
$nearest = $this->nearestZombie();
if ($nearest !== null) {
$hasTarget = true;
$toEnemy = $nearest->pos->subV($this->pos);
if ($toEnemy->lengthSquared() > 1.0) {
$aim = $toEnemy;
}
}
if ($aim->lengthSquared() > 1.0) {
$this->aimDirection = $aim->divS($aim->length());
} elseif ($aim->lengthSquared() > 0.01 && $this->input->aim !== null && ! $autoAimActive) {
// Raw normalized direction from the client when not auto-aiming.
} elseif ($aim->lengthSquared() > 0.01 && $this->input->aim !== null) {
// Use the raw client direction when no auto-aim target is near.
$this->aimDirection = $aim->normalize();
}
@@ -177,7 +172,7 @@ final class Player extends GameObject
$this->damageCooldown = max(0.0, $this->damageCooldown - $dt);
$this->cooldown -= $dt;
if ($this->cooldown <= 0.0 && ($this->input->fire || ($autoAimActive && $hasTarget))) {
if ($this->cooldown <= 0.0 && ($this->input->fire || $hasTarget)) {
$this->cooldown = $this->fireRate;
$this->shoot();
}
-1
View File
@@ -73,7 +73,6 @@ final class Room
$this->spawnTimer = 0.0;
$this->pickupTimer = 8.0;
$this->events = [];
$this->seq++;
foreach ($this->entities->copy() as $entity) {
if ($entity instanceof Player) {