UK
games/dmmotor / src / Dm / Play / StrobeFlash.php · commit 9d248a4
<?php/* * dmmotor — a strobe light (strobe_t of p_lights.c). * Copyright (C) 1993-1996 by id Software, Inc.; PHP port for dmmotor. GPL v2 (see LICENSE). */namespace App\Dm\Play;use App\Dm\Sector;final class StrobeFlash implements Thinker{    public const STROBEBRIGHT = 5;    public const FASTDARK = 15;    public const SLOWDARK = 35;    public int $count = 0;    public int $minLight = 0;    public int $maxLight = 0;    public int $darkTime = 0;    public int $brightTime = self::STROBEBRIGHT;    public function __construct(public Sector $sector)    {    }    public static function spawn(World $w, Sector $sec, int $fastOrSlow, bool $inSync): self    {        $f = new self($sec);        $f->darkTime = $fastOrSlow;        $f->maxLight = $sec->lightLevel;        $f->minLight = World::minSurroundingLight($sec, $sec->lightLevel);        if ($f->minLight === $f->maxLight) {            $f->minLight = 0;        }        $sec->special = 0;        $f->count = $inSync ? 1 : (Random::p() & 7) + 1;        return $f;    }    public function think(World $w): void    {        if (--$this->count > 0) {            return;        }        if ($this->sector->lightLevel === $this->minLight) {            $this->sector->lightLevel = $this->maxLight;            $this->count = $this->brightTime;        } else {            $this->sector->lightLevel = $this->minLight;            $this->count = $this->darkTime;        }    }    public function isRemoved(): bool    {        return false;    }}