RU
games/doom-jumphp / tests / MonsterTest.php · commit 8e1cb9f
<?phpnamespace Tests;use App\Game\Info;final class MonsterTest extends WorldTestCase{    public function testTheSidearmKillsAHusk(): void    {        $this->load('test');        $this->noMonsters();        $mo = $this->placePlayer(4, 9, 90);        $husk = $this->world->spawn('husk', $mo->x, $mo->y + 180, null);        $this->tics(30);        for ($i = 0; $i < 40 && $husk->health > 0; $i++) {            $this->tics(20, ['fire' => true]);        }        self::assertLessThanOrEqual(0, $husk->health);        self::assertTrue($husk->is(Info::CORPSE));        self::assertSame(1, $this->world->player->kills);        $this->tics(60);        self::assertSame('L', $husk->frame, 'lying dead');    }    public function testAHuskWakesUpAndShootsThePlayer(): void    {        $this->load('test');        $this->noMonsters();        $mo = $this->placePlayer(4, 9, 90);        $husk = $this->world->spawn('husk', $mo->x, $mo->y + 200, null);        $husk->angle = deg2rad(270);        $this->tics(35 * 8);        self::assertNotSame('HUSK_STND', $husk->state);        self::assertLessThan(100, $this->world->player->health, 'it hit the player');    }    public function testAGnasherChasesAndBites(): void    {        $this->load('test');        $this->noMonsters();        $mo = $this->placePlayer(2, 9, 0);        $g = $this->world->spawn('gnasher', $mo->x + 400, $mo->y, null);        $g->angle = M_PI;        $x0 = $g->x;        $this->tics(35 * 6);        self::assertLessThan($x0 - 100, $g->x, 'it came closer');        self::assertLessThan(100, $this->world->player->health);    }    public function testASpitterThrowsAcid(): void    {        $this->load('test');        $this->noMonsters();        $mo = $this->placePlayer(2, 9, 0);        $s = $this->world->spawn('spitter', $mo->x + 500, $mo->y, null);        $s->angle = M_PI;        $seen = false;        for ($i = 0; $i < 35 * 8 && !$seen; $i++) {            $this->tics(1);            foreach ($this->world->mobjs as $m) {                $seen = $seen || $m->type === 'acidball';            }        }        self::assertTrue($seen);    }    public function testABarrelExplodesAndHurtsAround(): void    {        $this->load('test');        $this->noMonsters();        $mo = $this->placePlayer(4, 9, 90);        $barrel = $this->world->spawn('barrel', $mo->x, $mo->y + 150, null);        $husk = $this->world->spawn('husk', $mo->x + 40, $mo->y + 170, null);        $this->tics(30);        for ($i = 0; $i < 20 && !$barrel->removed; $i++) {            $this->tics(15, ['fire' => true]);        }        $this->tics(40);        self::assertTrue($barrel->removed);        self::assertLessThanOrEqual(0, $husk->health);    }}