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 test_casting(self): light = Light(10, 10, 50) light.update() visibitlity = light.visibility result = [(0.0, 0.00019999800003844825), (0.0, 0.0), (0.00019999800003844825, 0.0), (31.99941601284763, 0.0), (32.0, 7.105427357601002e-15), (32.0, 0.0002654533388604108), (32.0, 31.999560004399918), (32.0, 32.0), (31.999560004399914, 32.0), (0.00026545333886218714, 31.999999999999996), (7.105427357601002e-15, 32.0), (0.0, 31.999416012847632)] self.assertEqual(result, visibitlity)
class SwingingLight: def __init__(self, x, y, rope_length, obstacles=[]): """expects that set_up_surface for Light has been called""" self.x = x self.y = y self.obstacles = obstacles self.rope_length = rope_length self.bob = Pendulum(BOB_ANGLE, self.rope_length, (self.x, self.y)) self.light = Light(self.x, self.y + self.rope_length, SWINGING_LIGHT_RADIUS, self.obstacles) self.light.update() def update(self): self.bob.recompute_angle() x = self.bob.rect.center[0] y = self.bob.rect.center[1] self.light.update_light_position(x, y) def update_position(self, x, y): self.x = x self.y = y self.bob = Pendulum(BOB_ANGLE, self.rope_length, (self.x, self.y)) self.light.update_light_position(self.x, self.y + self.rope_length) def update_obstacles(self, obstacles): self.obstacles = obstacles self.light.update_obstacles(self.obstacles) def collide(self, position): return math.sqrt((self.x - position[0])**2 + (self.y - position[1])**2) <= 30 def draw(self, surface, camera): pygame.draw.line( surface, (0, 0, 0), camera.apply((self.x, self.y)), camera.apply((self.bob.rect.center[0], self.bob.rect.center[1])), 5) self.light.draw_light(camera) self.light.draw_shadow(camera)
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)]))