def runTest(self): ent1 = CompoundEntity() ent2 = CompoundEntity() ent2.name = 'target entity' manager = CDManager(None, None) manager.objects.append(ent1) manager.objects.append(ent2) index = manager.get_entity_index(ent2) self.assertEqual(index, 1)
def runTest(self): action_event = ActionEvent() action_event.subject = 'blah' action_event.event_object = 'blah' action_event.affected_attribute = EntityAttributes.radius action_event.attribute_outcome = EntityAttributeOutcomes.increase result = CDManager.detect_scenarios(action_event) self.assertIsInstance(result, list) self.assertGreaterEqual(len(result), 1, 'Should find at least one candidate verb')
def setUp(self, mockSurface, mockSpace): self.manager = CDManager(mockSurface, mockSpace)
def setup_pymunk_environment(events: List[ActionEvent], sentence: str=None): assert type(events) == list # pylint: disable=no-member pygame.init() screen = pygame.display.set_mode((600, 600)) pygame.display.set_caption(sentence or 'Simulation') clock = pygame.time.Clock() space = pymunk.Space() space.gravity = (0.0, 0.0) space.add_collision_handler( CollisionTypes.ABSORBABLE, CollisionTypes.ABSORBER).begin = CDUtilities.CollisionAbsorber draw_options = pymunk.pygame_util.DrawOptions(screen) manager = CDManager(screen, space) manager.print_events = False balls = [] # Add objects _create_entities(manager, events) for entity in manager.objects: for particle in entity.parts: balls.append(particle) # Begin simulation while True: for keyboard_events in pygame.event.get(): if keyboard_events.type == QUIT: sys.exit(0) elif keyboard_events.type == KEYDOWN and keyboard_events.key == K_ESCAPE: sys.exit(0) balls_to_remove = [] for ball in balls: grav_force = pymunk.Vec2d() for other_ball in balls: grav_force = grav_force + \ utilities.calc_gravitational_force( other_ball.body, ball.body) ball.body.apply_force_at_local_point(grav_force, (0, 0)) for ball in balls_to_remove: space.remove(ball, ball.body) # 3 balls.remove(ball) # 4 steps_per_frame = 50 # larger value increases accuracy of simulation, but decreases speed frames_per_tick = 1 for x in range(steps_per_frame): space.step(1/(frames_per_tick*steps_per_frame)) screen.fill((255, 255, 255)) space.debug_draw(draw_options) manager.tick() # processes changes in CDobjects pygame.display.flip() # argument is max framerate, which we'll probably never reach! clock.tick(50)