def set_up_boundaries(self): self.world.append( Block((0, 0, 0), LevelDesign.GAME_MEASURES[0], 32, 0, 0, TAG_GROUND)) self.world.append( Block((0, 0, 0), LevelDesign.GAME_MEASURES[0], 32, 0, LevelDesign.GAME_MEASURES[1] - 32, TAG_GROUND)) self.world.append( Block((0, 0, 0), 32, LevelDesign.GAME_MEASURES[1], 0, 0, TAG_WALL)) self.world.append( Block((0, 0, 0), 32, LevelDesign.GAME_MEASURES[1], LevelDesign.GAME_MEASURES[0] - 32, 0, TAG_WALL))
def setUpClass(cls): pygame.init() pygame.display.set_mode((1, 1)) cls.value = 10 cls.block1 = Block((0, 0, 0), cls.value, cls.value, cls.value, cls.value, TAG_GROUND) cls.block2 = Block((0, 0, 0), cls.value, cls.value, cls.value, cls.value, TAG_WALL) cls.saw_block = SawBlock(cls.value, cls.value, cls.value * 10) cls.light = Light(cls.value, cls.value, cls.value, [cls.block1, cls.block2]) cls.swinging_light = SwingingLight(cls.value, cls.value, cls.value * 10, [cls.block1, cls.block2])
def test_casting_with_obstacles(self): block = Block((0, 0, 0), 10, 10, 10, 10) light = Light(10, 10, 50, [block]) light.update() visibitlity = light.visibility self.assertEqual(visibitlity, self.result)
def spawn_block(self, information, camera, colour=(0, 0, 0)): """information contains, width, height, tag""" self.world.append( Block(colour, information[0], information[1], camera.reverse_apply((32, 32))[0], camera.reverse_apply((32, 32))[1], information[2])) for light in self.lights: light.update_obstacles(self.world)
def setUp(self): class World: def __init__(self, blocks=[], saws=[]): self.level_blocks = blocks self.level_saws = saws block = Block((0, 0, 0), 10, 10, 20, 10) world = World([block]) self.camera = Camera(100, 100, 100, 100) self.batarang = Batarang(20, 10, world)
def deserialize(self, d): if d["type"] == OBJECT_BLOCK: return Block(d["colour"], d["width"], d["height"], d["x"], d["y"], d["tag"]) elif d["type"] == OBJECT_SAW_BLOCK: return SawBlock(d["x"], d["y"], d["length"]) elif d["type"] == OBJECT_LIGHT: return Light(d["x"], d["y"], d["radius"]) elif d["type"] == OBJECT_SETTINGS: return Settings(d["level_width"], d["level_height"], d["music"], d["start_position"]) elif d["type"] == OBJECT_SWINGING_LIGHT: return SwingingLight(d["x"], d["y"], d["rope_length"])
def test_functionality(self): class EVT: def __init__(self, event, key): self.type = event self.key = key events = [EVT(6, 1), EVT(4, 1), EVT(3, 306)] world = [Block((0, 0, 0), 500, 500, 0, 0)] self.graple.aim = (50, 50) self.graple.should_aim = True self.graple.functionality(events, world) self.assertEqual(self.graple.should_release, True) self.assertEqual(self.graple.should_retract, False) self.assertEqual(self.graple.shooter, True)
def __init__(self): self.world = [] self.lights = [] self.swinging_lights = [] # this is the block according to which the view will move self.observer = Block((0, 0, 0), WIDTH, HEIGHT, 0, 0) self.setup_menu_camera() self.setup_text_boxes() self.setup_buttons() self.set_up_boundaries() Light.set_up_surfaces(LevelDesign.GAME_MEASURES[0], LevelDesign.GAME_MEASURES[1]) self.settings = Settings(LevelDesign.GAME_MEASURES[0], LevelDesign.GAME_MEASURES[1], MUSIC_IN_GAME1, DEFAULT_START_POSITION)
def test_is_illuminated(self): block = Block((0, 0, 0), 10, 10, 10, 10) light = Light(5, 5, 50, [block]) light.update() self.assertTrue(light.is_illuminated([(6, 6)]))
def test_update_light_position(self): block = Block((0, 0, 0), 10, 10, 10, 10) light = Light(5, 5, 50, [block]) light.update_light_position(10, 10) visibility = light.visibility self.assertEqual(visibility, self.result)
def test_update_obstacles(self): block = Block((0, 0, 0), 10, 10, 10, 10) light = Light(10, 10, 50) light.update_obstacles([block]) visibility = light.visibility self.assertEqual(visibility, self.result)