39 lines
852 B
PHP
39 lines
852 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Game;
|
|
|
|
final class InputState
|
|
{
|
|
/** @var array<string> Currently-held keys (lowercase: w/a/s/d/space/shift). */
|
|
public array $keys;
|
|
|
|
/** Normalized aim direction in world space, sent by the client. */
|
|
public Vector2 $aim;
|
|
|
|
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
|
|
{
|
|
$this->keys = [];
|
|
$this->aim = $aim ?? new Vector2(1.0, 0.0);
|
|
$this->fire = false;
|
|
$this->autoAim = false;
|
|
}
|
|
}
|