class Body: def __init__(self, coords, initial_velocity, recipe): self.recipe = recipe self.sprite = Visible(coords, recipe['radius'], colour=recipe['colour']) self.movement = MovingCircle(coords, max_accelleration=recipe['accelleration'], initial_velocity=initial_velocity) self.substance = ObstructingCircle(coords, recipe['radius'], image=recipe) self.coords = self.movement.coords self.radius = recipe['radius'] self.velocity = self.movement.velocity def update(self, screen): self.sprite.draw(self.movement.coords, screen) def move(self, list_of_game_objects, goal_vector): self.movement.set_accelleration(goal_vector) self.movement.move(list_of_game_objects) self.substance.center = self.movement.coords self.coords = self.movement.coords self.velocity = self.movement.velocity
def __init__(self, coords, initial_velocity, recipe): self.recipe = recipe self.sprite = Visible(coords, recipe['radius'], colour=recipe['colour']) self.movement = MovingCircle(coords, max_accelleration=recipe['accelleration'], initial_velocity=initial_velocity) self.substance = ObstructingCircle(coords, recipe['radius'], image=recipe) self.coords = self.movement.coords self.radius = recipe['radius'] self.velocity = self.movement.velocity
class Item(ScreenObject): def __init__(self, coords, colour, radius=5): super(Item, self).__init__() self.radius = radius self.image = {'kind': 'item', 'colour': colour} self.start_coords = np.array(coords) self.sprite = Visible(coords, self.radius, colour=colour) def collide(self, colliding_object): return None def coords(self): return self.start_coords def update(self, screen, list_of_game_objects): self.sprite.draw(self.coords(), screen)
def test_update_rect_center(): vis = Visible((10, 10), 5) vis.change_rect_center((20, 20)) assert vis.rect.center == (20, 20)
def test_rect_is_centered(): vis = Visible((10, 10), 5) assert vis.rect.center == (10, 10)
def test_update_rect_center_rounds_floats(): vis = Visible((10, 10), 5) vis.change_rect_center((1.6, 1.4)) assert vis.rect.center == (2, 1)
def __init__(self, coords, colour, radius=5): super(Item, self).__init__() self.radius = radius self.image = {'kind': 'item', 'colour': colour} self.start_coords = np.array(coords) self.sprite = Visible(coords, self.radius, colour=colour)