the letters shown */ private array $letters = []; /** @var list found */ private array $found = []; private float $letterClock = 0.0; /** the credits have started (cgood) */ private float $scroll = -1.0; private float $bars = 0.0; public function enter(array $params = []): void { parent::enter($params); $this->letters = array_fill(0, 6, ' '); $this->found = array_fill(0, 6, false); $this->letterClock = -0.5; // xWait (500) $this->scroll = -1.0; $this->bars = 0.0; $this->showCursor(false); } public function exit(): void { $this->showCursor(true); } public function update(float $dt): void { parent::update($dt); if ($this->time > 0.5 && $this->anyInput()) { $this->showCursor(true); $this->scenes()->pop(); return; } if ($this->scroll < 0) { $this->letterClock += $dt; while ($this->letterClock >= 0.035) { $this->letterClock -= 0.035; $this->drawLetters(); } if (!in_array(false, $this->found, true)) { $this->scroll = 0.0; } return; } // Timer1: 200 twips every 300 ms; Timer2: the red bars, 2 pixels a step $this->scroll += $dt * (200 / 15) / 0.3; $this->bars = min(FullScreen::H, $this->bars + $dt * 240); } /** A random capital (or small letter for i, n, i) for each letter not found yet; it stays once it is the right one. */ private function drawLetters(): void { foreach (self::WORD as $i => $want) { if ($this->found[$i]) { continue; } $small = in_array($i, [1, 2, 4], true); $this->letters[$i] = chr(($small ? 97 : 65) + mt_rand(0, 26)); if ($this->letters[$i] === $want) { $this->found[$i] = true; } } } /** @return list the letters on the screen (tests) */ public function letters(): array { return $this->letters; } public function scrolling(): bool { return $this->scroll >= 0; } public function render(Renderer $r): void { $c = $this->canvas($r); // the frame of the letters (Shape1) and the letters (Label2, green) $c->frame(8, 440, 625, 33, '#000000'); foreach ($this->letters as $i => $letter) { $c->text($letter, 248 + $i * 24 + 12, 442, 26, '#00ff00', 'center'); } if ($this->scroll < 0) { return; } $c->fill(0, 0, 4, $this->bars, '#ff0000'); $c->fill(635, 0, 4, $this->bars, '#ff0000'); foreach (self::CREDITS as [$text, $twips, $align]) { $y = $twips / 15 - $this->scroll; if ($y > 400 || $y < -30) { continue; } // brighter at the bottom, black at the top (red = (Top - 20) / 5, in twips) $grey = (int)max(0, min(255, ($y * 15 - 20) / 5 / 4)); $x = $align === 1 ? 620 : 320; $c->text($text, $x, $y, 18, [$grey, $grey, $grey], $align === 1 ? 'right' : 'center'); } } }