<?phpnamespace App\Scene;use JumPHP\Renderer\Renderer;use JumPHP\Scene\AbstractScene;/** The end of a level: kills, items, secrets counting up, the time against the par time. */final class IntermissionScene extends AbstractScene{ private array $p = []; private float $t = 0.0; public function enter(array $params = []): void { $this->p = $params + ['stats' => ['kills' => 0, 'items' => 0, 'secrets' => 0, 'time' => 0, 'par' => 0], 'name' => '', 'next' => null]; $this->t = 0.0; } public function update(float $dt): void { $before = (int)($this->t * 10); $this->t += $dt; if ((int)($this->t * 10) !== $before && $this->t < 2.2) { $this->sound()->playSfx('pistol'); } $a = $this->actions(); if ($this->t > 0.6 && ($a->isPressed('confirm') || $a->isPressed('use') || $a->isPressed('fire'))) { if ($this->t < 2.2) { $this->t = 2.2; return; } if ($this->p['next'] === null) { $this->scenes()->switchTo(VictoryScene::class); return; } $this->scenes()->switchTo(PlayScene::class, ['level' => $this->p['next'], 'skill' => $this->p['skill'], 'carry' => $this->p['carry']]); } } public function render(Renderer $r): void { $r->clear([24, 8, 8]); for ($y = 0; $y < 200; $y += 4) { $r->fillRect(0, $y, 320, 2, [40 + ($y % 16), 12, 10]); } $f = $this->font(); $f->draw($r, $this->p['name'], 160, 20, 2, [255, 220, 120], 'center', [0, 0, 0]); $f->draw($r, 'FINISHED', 160, 40, 2, [255, 255, 255], 'center', [0, 0, 0]); $s = $this->p['stats']; $k = min(1.0, $this->t / 0.6); $rows = [ ['KILLS', (int)($s['kills'] * $k) . '%'], ['ITEMS', (int)($s['items'] * min(1.0, max(0.0, ($this->t - 0.5) / 0.6))) . '%'], ['SECRETS', (int)($s['secrets'] * min(1.0, max(0.0, ($this->t - 1.0) / 0.6))) . '%'], ['TIME', $this->t > 1.6 ? sprintf('%d:%02d', intdiv($s['time'], 60), $s['time'] % 60) : ''], ['PAR', $this->t > 1.6 ? sprintf('%d:%02d', intdiv($s['par'], 60), $s['par'] % 60) : ''], ]; foreach ($rows as $i => [$label, $value]) { $f->draw($r, $label, 70, 72 + $i * 18, 2, [255, 80, 60], 'left', [0, 0, 0]); $f->draw($r, $value, 250, 72 + $i * 18, 2, [255, 255, 255], 'right', [0, 0, 0]); } if ($this->t > 2.2 && fmod($this->t, 1.0) < 0.7) { $f->draw($r, $this->p['next'] === null ? 'PRESS ENTER' : 'PRESS ENTER FOR THE NEXT LEVEL', 160, 180, 1, [220, 220, 220], 'center'); } }}