Sign in
EN
games/doom-jumphp / src / Game / Player.php · commit 8e1cb9f
<?phpnamespace App\Game;/** The player: health, armour, weapons, ammunition, keys, view (player_t / d_player.h). */final class Player{    public const VIEWHEIGHT = 41.0;    public const AMMO_MAX = ['bullets' => 200, 'shells' => 50, 'cells' => 300];    public Mobj $mo;    public int $health = 100;    public int $armor = 0;    public int $armorType = 0;    /** @var array<string, int> */    public array $ammo = ['bullets' => 50, 'shells' => 0, 'cells' => 0];    /** @var array<int, bool> */    public array $weapons = [1 => true, 2 => true, 3 => false, 4 => false, 5 => false];    public int $weapon = 2;    public ?int $pending = null;    /** @var array<string, bool> */    public array $keys = ['red' => false, 'blue' => false, 'yellow' => false];    public float $viewz = 0.0;    public float $pviewz = 0.0;    public float $viewheight = self::VIEWHEIGHT;    public float $deltaviewheight = 0.0;    public float $bob = 0.0;    public int $damagecount = 0;    public int $bonuscount = 0;    public ?Mobj $attacker = null;    public int $kills = 0;    public int $items = 0;    public int $secrets = 0;    public int $refire = 0;    public bool $attackDown = false;    public bool $useDown = false;    public bool $dead = false;    /** the weapon in the hands: state, tics, offset */    public string $wState = '';    public int $wTics = 0;    public float $wx = 0.0;    public float $wy = 0.0;    /** the muzzle flash (frame letter of the weapon sprite) for a few tics */    public int $flashTics = 0;    public int $turnHeld = 0;    public float $pangle = 0.0;    /** cheats / tests */    public bool $god = false;    /** Keeps what a player carries from a level to the next (health, armour, weapons, ammo). */    public function carry(): array    {        return ['health' => $this->health, 'armor' => $this->armor, 'armorType' => $this->armorType, 'ammo' => $this->ammo,            'weapons' => $this->weapons, 'weapon' => $this->weapon];    }    public function restore(array $c): void    {        $this->health = $c['health'];        $this->armor = $c['armor'];        $this->armorType = $c['armorType'];        $this->ammo = $c['ammo'];        $this->weapons = $c['weapons'];        $this->weapon = $c['weapon'];    }}