def on_mouse_press(self, x, y, button, modifiers): #Clear the stored dx and dy self.clicked_dx = 0 self.clicked_dy = 0 #If there is an item under the pointer, remove it from bodies, #keep track of it by itself, and zero out all forces for body in self.world.bodies: if is_in_polygon(body.entity.get_screen_relative_vertices_vectors( self.scene.top_left['x'], self.scene.top_left['y'], self.scene.height), Vector2(x=x, y=y)): self.world.remove_body(body) self.clicked_object = body self.clicked_object.zero_forces() return #If there was no object under the pointer, create a new object but #keep it free from physics for now if self.gen_entity == 'CIRCLE': entity = Circle(radius=self.gen_size / 2, position=Vector2( x=x + self.scene.top_left['x'], y=self.scene.height - y + self.scene.top_left['y'])) elif self.gen_entity == 'SQUARE': entity = Square(size=self.gen_size, position=Vector2( x=x + self.scene.top_left['x'], y=self.scene.height - y + self.scene.top_left['y'])) self.scene.entities.append(entity) self.clicked_object = RigidBody(entity=entity, mass=self.gen_mass)
def on_mouse_press(self, x, y, button, modifiers): ''' This method overwrites the same method in the superclass. It adds in the checking for a click on the shape or on the size/mass sliders ''' for entity in self.entities: if is_in_polygon(entity.get_screen_relative_vertices_vectors( 0, 0, 500), Vector2(x=x, y=y)): self.clicked_object = entity if self.clicked_object is self.entities[2]: self.parent.gen_entity = 'SQUARE' self.clicked_object = None elif self.clicked_object is self.entities[3]: self.parent.gen_entity = 'CIRCLE' self.clicked_object = None