JA
games/doom-jumphp / src / Scene / VictoryScene.php · commit 8e1cb9f
<?phpnamespace App\Scene;use JumPHP\Renderer\Renderer;use JumPHP\Scene\AbstractScene;/** The end of the episode: a text that scrolls in, like the original's finale. */final class VictoryScene extends AbstractScene{    private const TEXT = "THE WARDEN FALLS AND THE CORE GOES\n"        . "QUIET. THE MACHINES THAT DUG TOO DEEP\n"        . "ARE STILL. THE THINGS THEY WOKE UP\n"        . "LIE IN PIECES BEHIND YOU.\n\n"        . "BUT FAR BELOW, IN THE DARK UNDER THE\n"        . "STATION, SOMETHING ELSE IS LISTENING.\n\n"        . "THE ABYSS IS NOT EMPTY.\n\n"        . "THANKS FOR PLAYING IRON ABYSS.";    private float $t = 0.0;    public function enter(array $params = []): void    {        $this->t = 0.0;    }    public function update(float $dt): void    {        $this->t += $dt;        $a = $this->actions();        if ($this->t > 1 && ($a->isPressed('confirm') || $a->isPressed('back'))) {            if ($this->t * 30 < strlen(self::TEXT)) {                $this->t = 100;                return;            }            $this->scenes()->switchTo(TitleScene::class);        }    }    public function render(Renderer $r): void    {        $r->clear([10, 6, 20]);        for ($i = 0; $i < 60; $i++) {            $r->fillRect(($i * 53) % 320, ($i * 97) % 200, 1, 1, [80 + $i % 120, 70, 120]);        }        $shown = substr(self::TEXT, 0, (int)($this->t * 30));        $this->font()->draw($r, $shown, 20, 30, 1, [255, 220, 160], 'left', [0, 0, 0]);    }}