game->peek('game'); return $game; } public function testTheChoiceScreenStartsPhaseTwo(): void { $this->game->start(TitleScene::class); $this->game->run(5); $this->game->shot('choice'); $this->game->press('right', 5); $this->game->press('confirm', 5); self::assertSame('freedoom2', $this->dm()->iwad); self::assertTrue($this->dm()->commercial); $this->game->run(20); $this->game->shot('title-phase2'); } public function testPhaseTwoBeginsOnMapOne(): void { $this->game->start(PlayScene::class, ['iwad' => 'freedoom2', 'map' => 1, 'skill' => 2, 'newGame' => true]); $world = $this->dm()->world; self::assertSame('MAP01', $world->mapName(1, 1)); self::assertNotNull($world->map->pointInSubsector($world->player->mo->x, $world->player->mo->y)); $this->game->hold('up', 40); $this->game->shot('map01'); } public function testTheSuperShotgunFiresTwoShells(): void { $this->game->start(PlayScene::class, ['iwad' => 'freedoom2', 'map' => 1, 'skill' => 2, 'newGame' => true]); $p = $this->dm()->world->player; $p->weaponOwned[Player::WP_SUPERSHOTGUN] = true; $p->ammo[Player::AM_SHELL] = 10; $this->game->press('weapon3', 100); self::assertSame(Player::WP_SUPERSHOTGUN, $p->readyWeapon); $this->game->hold('fire', 20); self::assertSame(8, $p->ammo[Player::AM_SHELL]); } public function testAFatsoThrowsFireballs(): void { $this->game->start(PlayScene::class, ['iwad' => 'freedoom2', 'map' => 1, 'skill' => 2, 'newGame' => true]); $w = $this->dm()->world; $mo = $w->player->mo; $fatso = $w->spawnMobj($mo->x + 300 * cos($mo->angle), $mo->y + 300 * sin($mo->angle), World::ONFLOORZ, Info::MT_FATSO); $fatso->target = $mo; $w->setMobjState($fatso, Info::S_FATT_ATK1); $this->game->run(40); $shots = 0; foreach ($w->thinkers as $t) { if ($t instanceof \App\Dm\Play\Mobj && !$t->removed && $t->type === Info::MT_FATSHOT) { $shots++; } } self::assertGreaterThan(0, $shots); } public function testASavedGameComesBackAsItWas(): void { $this->game->start(PlayScene::class, ['iwad' => 'freedoom1', 'episode' => 1, 'map' => 1, 'skill' => 2, 'newGame' => true]); $this->game->hold('up', 40); $g = $this->dm(); $p = $g->world->player; $x = $p->mo->x; $y = $p->mo->y; $p->health = 57; self::assertTrue(SaveGames::write($this->engine()->storage, $g->iwad, 0, $g->world, 1, 1)); $this->game->hold('up', 40); $data = SaveGames::read($this->engine()->storage, $g->iwad, 0); self::assertNotNull($data); $this->game->start(PlayScene::class, ['load' => $data]); $p = $this->dm()->world->player; self::assertEqualsWithDelta($x, $p->mo->x, 0.01); self::assertEqualsWithDelta($y, $p->mo->y, 0.01); self::assertSame(57, $p->health); $this->game->run(30); // the loaded world plays on } public function testTheMapKeyShowsTheAutomap(): void { $this->game->start(PlayScene::class, ['iwad' => 'freedoom1', 'episode' => 1, 'map' => 1, 'skill' => 2, 'newGame' => true]); $this->game->hold('up', 30); $this->game->press('map', 5); self::assertTrue($this->dm()->automap->active); $this->game->shot('automap'); $this->game->press('map', 5); self::assertFalse($this->dm()->automap->active); } public function testEachLevelHasItsSong(): void { $this->game->start(PlayScene::class, ['iwad' => 'freedoom1', 'episode' => 1, 'map' => 1, 'skill' => 2, 'newGame' => true]); self::assertSame('D_E1M1', $this->dm()->music->playing); $pcm = $this->dm()->music->render(2048); self::assertSame(4096, strlen($pcm)); self::assertNotSame(str_repeat("\0", 4096), $pcm, 'the synthesizer plays notes'); } private function engine(): \JumPHP\Kernel\Engine { return \JumPHP\Kernel\Engine::get(); } }