Entrar
PT
games/doom-jumphp / tests / PlayerTest.php · commit 8e1cb9f
<?phpnamespace Tests;use App\Game\Info;use App\Game\Weapons;final class PlayerTest extends WorldTestCase{    public function testThePlayerWalksForwardAndStopsAtTheWall(): void    {        $this->load('test');        $mo = $this->placePlayer(4, 9, 90);        $y0 = $mo->y;        $this->tics(20, ['forward' => 1]);        self::assertGreaterThan($y0 + 50, $mo->y, 'walked north');        $this->tics(200, ['forward' => 2]);        // the room ends at the door's wall (row 4): the player stays inside        [, $wallY] = $this->cell(4, 4);        self::assertLessThan($wallY - 32, $mo->y + $mo->radius - 0.01);    }    public function testThePlayerTurns(): void    {        $this->load('test');        $mo = $this->placePlayer(4, 9, 90);        $this->tics(10, ['turn' => 0.1]);        self::assertEqualsWithDelta(deg2rad(90) + 1.0, $mo->angle, 0.001);    }    public function testThePlayerClimbsAStepButNotAWall(): void    {        $this->load('test');        // the step 's' (16 high) is in column 6, rows 5 and 8        $mo = $this->placePlayer(5, 8, 0);        for ($i = 0; $i < 40 && $mo->sector->char !== 's'; $i++) {            $this->tics(1, ['forward' => 1]);        }        $this->tics(2);        self::assertSame('s', $mo->sector->char);        self::assertSame(16.0, $mo->z, 'on the step');        // the pillar '#' (column 3, row 7) stops the player        $mo = $this->placePlayer(1, 7, 0);        $this->tics(60, ['forward' => 1]);        self::assertLessThan(3 * 64 - $mo->radius + 0.01, $mo->x);    }    public function testAcidHurts(): void    {        $this->load('test');        $this->noMonsters();        $this->placePlayer(9, 8, 0);        self::assertSame(-16.0, $this->world->player->mo->sector->floor);        $this->tics(70);        self::assertLessThan(100, $this->world->player->health);    }    public function testTheSidearmUsesAmmunitionAndTheWeaponsSwitch(): void    {        $this->load('test');        $p = $this->world->player;        $this->tics(30);        self::assertSame('READY', $p->wState);        $this->tics(12, ['fire' => true]);        self::assertLessThan(50, $p->ammo['bullets']);        $this->tics(30);        $this->tics(40, ['weapon' => 1]);        self::assertSame(1, $p->weapon);        self::assertSame('READY', $p->wState);        self::assertSame('WRCH', Weapons::LIST[$p->weapon]['sprite']);    }    public function testPickingUpAMedkitHeals(): void    {        $this->load('test');        $this->noMonsters();        $mo = $this->placePlayer(4, 9, 90);        $this->world->player->health = 50;        $this->world->spawn('medkit', $mo->x, $mo->y + 40, null);        $this->tics(15, ['forward' => 1]);        self::assertSame(75, $this->world->player->health);        self::assertStringContainsString('MEDKIT', $this->world->message);    }    public function testAWeaponPickupGivesItAndBringsItUp(): void    {        $this->load('test');        $this->noMonsters();        $mo = $this->placePlayer(4, 9, 90);        $this->world->spawn('scattergun', $mo->x, $mo->y + 40, null);        $this->tics(60, ['forward' => 1]);        self::assertTrue($this->world->player->weapons[3]);        self::assertSame(3, $this->world->player->weapon);        self::assertGreaterThan(0, $this->world->player->ammo['shells']);        self::assertTrue(Info::SPECIAL > 0);    }}