def test_get_tiles_around_tile_full_tile(map1): pos = (20, 20) tiles = game.game_map.get_tiles_around_tile(pos, 3, True) assert tiles.ndim == 2 and tiles.size == 14 * 14 t_utils.check_list_contains_objects_of_type(tiles.ravel(), 86, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 8, Bush) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 6, Wall)
def test_get_tiles_around_tile(map1): pos = (20, 20) tiles = game.game_map.get_tiles_around_tile(pos, 3) assert tiles.ndim == 2 and tiles.size == 7 * 7 t_utils.check_list_contains_objects_of_type(tiles.ravel(), 9, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 6, Bush) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 4, Wall)
def test_get_tile_ray_full_tile_edge_case(map2): pos = (12, 5) tiles = game.game_map.get_tile_ray(pos, (0, -1), 3, True) assert tiles.shape[1] == 2 and tiles.ndim == 2 and tiles.size == 10 t_utils.check_list_contains_objects_of_type(tiles.ravel(), 2, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 1, Flag) t_utils.check_list_contains_objects_of_type(tiles[0], 2, None)
def test_get_tile_relative_to_entity_full_tile(map1): entity = Tank(x=7 * constants.TILE_SIZE + constants.TANK_SIZE // 2, y=20 * constants.TILE_SIZE + constants.TANK_SIZE // 2, batch=None) returned_tiles = game.game_map.get_tile_next_to_entity( entity, (0, 1), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 2, None) returned_tiles = game.game_map.get_tile_next_to_entity( entity, (1, 0), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 1, None) t_utils.check_list_contains_objects_of_type(returned_tiles, 1, Wall) returned_tiles = game.game_map.get_tile_next_to_entity( entity, (0, -1), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 1, None) t_utils.check_list_contains_objects_of_type(returned_tiles, 1, DestructibleWall) returned_tiles = game.game_map.get_tile_next_to_entity( entity, (-1, 0), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 2, None)
def test_get_tile_relative_to_indexes_full_tile(map1): pos = (7, 20) returned_tiles = game.game_map.get_tile_next_to_indexes(pos, (0, 1), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 2, None) returned_tiles = game.game_map.get_tile_next_to_indexes(pos, (1, 0), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 1, None) t_utils.check_list_contains_objects_of_type(returned_tiles, 1, Wall) returned_tiles = game.game_map.get_tile_next_to_indexes(pos, (0, -1), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 1, None) t_utils.check_list_contains_objects_of_type(returned_tiles, 1, DestructibleWall) returned_tiles = game.game_map.get_tile_next_to_indexes(pos, (-1, 0), True) assert len(returned_tiles) == 2 t_utils.check_list_contains_objects_of_type(returned_tiles, 2, None)
def test_get_tile_ray_full_tile(map1): pos = (12, 20) tiles = game.game_map.get_tile_ray(pos, (-1, 0), 4, True) assert tiles.shape[1] == 2 and tiles.ndim == 2 and tiles.size == 16 t_utils.check_list_contains_objects_of_type(tiles.ravel(), 7, Wall) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 1, Bush) t_utils.check_list_contains_objects_of_type(tiles[0], 2, None) t_utils.check_list_contains_objects_of_type(tiles[7], 2, Wall) tiles = game.game_map.get_tile_ray(pos, (1, 0), 12, True) assert tiles.shape[1] == 2 and tiles.ndim == 2 and tiles.size == 28 t_utils.check_list_contains_objects_of_type(tiles.ravel(), 10, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 2, Wall) t_utils.check_list_contains_objects_of_type(tiles[0], 2, None) t_utils.check_list_contains_objects_of_type(tiles[2], 2, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles[11], 2, None) tiles = game.game_map.get_tile_ray(pos, (0, 1), 4, True) assert tiles.shape[1] == 2 and tiles.ndim == 2 and tiles.size == 12 t_utils.check_list_contains_objects_of_type(tiles.ravel(), 10, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 1, Bush) t_utils.check_list_contains_objects_of_type(tiles[0], 1, None) t_utils.check_list_contains_objects_of_type(tiles[0], 1, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles[1], 1, Bush) t_utils.check_list_contains_objects_of_type(tiles[1], 1, DestructibleWall) tiles = game.game_map.get_tile_ray(pos, (0, -1), 7, True) assert tiles.shape[1] == 2 and tiles.ndim == 2 and tiles.size == 7 * 4 t_utils.check_list_contains_objects_of_type(tiles.ravel(), 2, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles.ravel(), 3, Bush) t_utils.check_list_contains_objects_of_type(tiles[0], 2, None) t_utils.check_list_contains_objects_of_type(tiles[2], 1, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles[13], 2, Bush)
def test_get_tile_ray(map1): pos = (12, 20) tiles = game.game_map.get_tile_ray(pos, (-1, 0), 4) assert tiles.ndim == 1 and tiles.size == 4 t_utils.check_list_contains_objects_of_type(tiles, 1, Wall) assert tiles[0] is None assert type(tiles[3]) is Wall tiles = game.game_map.get_tile_ray(pos, (1, 0), 7) assert tiles.ndim == 1 and tiles.size == 7 t_utils.check_list_contains_objects_of_type(tiles, 3, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles, 1, Wall) assert tiles[0] is None assert type(tiles[3]) is DestructibleWall assert type(tiles[6]) is Wall tiles = game.game_map.get_tile_ray(pos, (0, 1), 4) assert tiles.ndim == 1 and tiles.size == 4 t_utils.check_list_contains_objects_of_type(tiles, 1, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles, 1, Bush) assert tiles[0] is None assert type(tiles[2]) is Bush tiles = game.game_map.get_tile_ray(pos, (0, -1), 15) assert tiles.ndim == 1 and tiles.size == 15 t_utils.check_list_contains_objects_of_type(tiles, 1, DestructibleWall) t_utils.check_list_contains_objects_of_type(tiles, 1, Bush) assert tiles[0] is None assert type(tiles[13]) is Bush assert type(tiles[14]) is DestructibleWall
def test_check_collision(): colliding_entities = [] test_entity = Tank(x=1 * constants.TANK_SIZE + constants.TANK_SIZE // 2, y=1 * constants.TANK_SIZE, batch=None) game.entity_manager.add_entity(test_entity) # Basic tests assert collision.check_collision(test_entity, test_entity.rect, None, colliding_entities, game.entity_manager, game.game_map) assert len(colliding_entities) == 1 t_utils.check_list_contains_objects_of_type(colliding_entities, 1, Flag) test_entity.move(-constants.TILE_SIZE // 2, 0) assert collision.check_collision(test_entity, test_entity.rect, None, colliding_entities, game.entity_manager, game.game_map) assert len(colliding_entities) == 3 t_utils.check_list_contains_objects_of_type(colliding_entities, 1, Flag) t_utils.check_list_contains_objects_of_type(colliding_entities, 2, Wall) # With multiple entities in the entity manager another_test_entity = Tank(x=0 + constants.TANK_SIZE // 2, y=0 + constants.TANK_SIZE // 2, batch=None) game.entity_manager.add_entity(another_test_entity) assert collision.check_collision(test_entity, test_entity.rect, None, colliding_entities, game.entity_manager, game.game_map) assert len(colliding_entities) == 4 t_utils.check_list_contains_objects_of_type(colliding_entities, 1, Flag) t_utils.check_list_contains_objects_of_type(colliding_entities, 2, Wall) t_utils.check_list_contains_objects_of_type(colliding_entities, 1, Tank) # Test ignored entities ignored_entities = [ another_test_entity, game.game_map.get_tile_at_indexes(2, 0), game.game_map.get_tile_at_indexes(1, 1) ] assert collision.check_collision(test_entity, test_entity.rect, ignored_entities, colliding_entities, game.entity_manager, game.game_map) assert len(colliding_entities) == 1 t_utils.check_list_contains_objects_of_type(colliding_entities, 1, Wall)