def test_step() -> None: cfg = Configuration(chunk_height=8) cfg.START_X = 2 * cfg.BLOCK_WIDTH map = Map(cfg) player = Player(cfg) chunk_test = [ " ", " ", " ", "WW WW", "W W", " ", " W", "WWWWW", ] map.load_chunk(chunk_test, 0) # test vertical moves player.step(4, map.blocks) assert player.y_speed == -cfg.SPEED_Y assert player.x_speed == 0 assert player.rect.x == cfg.START_X assert player.rect.y == cfg.START_Y - cfg.SPEED_Y for _ in range(20): player.step(5, map.blocks) # test horizontal moves player.x_speed = cfg.SPEED_X player.step(1, map.blocks) assert player.x_speed == cfg.SPEED_X assert player.rect.x == 48 assert player.rect.y == 208 player.step(1, map.blocks) assert player.x_speed < cfg.SPEED_X assert player.rect.x == 48 assert player.rect.y == 208
def test_slowdown() -> None: cfg = Configuration() cfg.SLOWDOWN_X = 0.8 player = Player(cfg) player.x_speed = 0.5 player.slowdown() assert player.x_speed == 0.0 player.x_speed = 2.0 player.slowdown() assert player.x_speed == int(2.0 * 0.8)
def test_level_generation() -> None: cfg = Configuration() map = Map(cfg) map.load_chunk("init", 0) assert map.level_generation() assert map.level_generation() assert map.level_generation() assert not map.level_generation() cfg.RANDOM_GEN = True map = Map(cfg) map.load_chunk("init", 0) assert map.level_generation()
def test_reset() -> None: cfg = Configuration(chunk_height=3) map = Map(cfg) chunk = [" ", " ", "W"] map.load_chunk(chunk, 0) map.level_idx += 1 assert len(map.blocks) == 1 assert map.level_idx == 2 map.reset() assert len(map.blocks) == 0 assert map.level_idx == 1
def test_load_chunk() -> None: cfg = Configuration(chunk_height=3) map = Map(cfg) chunk_test = [ " ", "W", "W", ] map.load_chunk(chunk_test, 0) assert len(map.blocks) == 2 map.reset() chunk_test.append("W") with pytest.raises(ValueError): map.load_chunk(chunk_test, 0)
def test_valid_chunk() -> None: cfg = Configuration(chunk_height=3) map = Map(cfg) invalid_chunk1 = [ " ", " ", ] assert not map.valid_chunk(invalid_chunk1) invalid_chunk2 = [ " ", " ", " ", ] assert not map.valid_chunk(invalid_chunk2) valid_chunk = [ " ", " W", "WW", ] assert map.valid_chunk(valid_chunk)
def test_block() -> None: cfg = Configuration() block = Block(1, 2, cfg) block.move(5.4, 2.1) assert block.rect.x == int(1 + 5.4) assert block.rect.y == int(2 + 2.1)