Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_mouse_press(self, x, y, button, modifiers):
if button == 1:
self.last_mouse_position = x, y
# See if we clicked on anything
shape_list = self.space.point_query((x, y), 1, pymunk.ShapeFilter())
# If we did, remember what we clicked on
if len(shape_list) > 0:
self.shape_being_dragged = shape_list[0]
elif button == 4:
# With right mouse button, shoot a heavy coin fast.
mass = 60
radius = 10
inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
body = pymunk.Body(mass, inertia)
body.position = x, y
body.velocity = 2000, 0
shape = pymunk.Circle(body, radius, pymunk.Vec2d(0, 0))
shape.friction = 0
self.space.add(body, shape)
def testSegmentQueryFirstSensor(self):
s = p.Space()
c = p.Circle(s.static_body, 10)
c.sensor = True
s.add(c)
hit = s.segment_query_first((-20,0), (20,0), 1, p.ShapeFilter())
self.assertIsNone(hit)
shape.collision_type = 2
space.add(body, shape)
coins.append(shape)
del body
del shape
for coord in coord_red:
body = pymunk.Body(COIN_MASS, inertia)
body.position = coord
shape = pymunk.Circle(body, COIN_RADIUS, (0, 0))
shape.elasticity = COIN_ELASTICITY
shape.color = RED_COIN_COLOR
mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories
sf = pymunk.ShapeFilter(mask=mask)
shape.filter = sf
shape.collision_type = 2
space.add(body, shape)
coins.append(shape)
del body
del shape
return coins
# player
body = pymunk.Body(5, pymunk.inf)
body.position = 100,100
head = pymunk.Circle(body, 10, (0,5))
head2 = pymunk.Circle(body, 10, (0,13))
feet = pymunk.Circle(body, 10, (0,-5))
# Since we use the debug draw we need to hide these circles. To make it
# easy we just set their color to black.
feet.color = 0,0,0,0
head.color = 0,0,0,0
head2.color = 0,0,0,0
mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories
sf = pymunk.ShapeFilter(mask=mask)
head.filter = sf
head2.filter = sf
feet.collision_type = 1
feet.ignore_draw = head.ignore_draw = head2.ignore_draw = True
space.add(body, head, feet,head2)
direction = 1
remaining_jumps = 2
landing = {'p':Vec2d.zero(), 'n':0}
frame_number = 0
landed_previous = False
while running:
grounding = {
def init_pockets(space):
pockets = []
for i in [(44.1, 44.1), (755.9, 44.1), (755.9, 755.9), (44.1, 755.9)]:
inertia = pymunk.moment_for_circle(0.1, 0, POCKET_RADIUS, (0, 0))
body = pymunk.Body(0.1, inertia)
body.position = i
shape = pymunk.Circle(body, POCKET_RADIUS, (0, 0))
shape.color = POCKET_COLOR
shape.collision_type = 2
shape.filter = pymunk.ShapeFilter(categories=0b1000)
space.add(body, shape)
pockets.append(shape)
del body
del shape
return pockets
def group(self, value):
if type(value) == int:
if type(self.shape) is list:
for shape in self.shape:
shape.filter = pymunk.ShapeFilter(group=value)
else:
self.shape.filter = pymunk.ShapeFilter(group=value)
else:
print("Group value must be an integer")
body.apply_impulse_at_local_point((-6000,0))
if event.type == pygame.USEREVENT+2:
reset_bodies(space)
elif event.type == KEYDOWN and event.key == K_r and is_interactive:
reset_bodies(space)
elif event.type == KEYDOWN and event.key == K_f and is_interactive:
r = random.randint(1,4)
for body in bodies[0:r]:
body.apply_impulse_at_local_point((-6000,0))
elif event.type == MOUSEBUTTONDOWN and is_interactive:
if selected != None:
space.remove(selected)
p = from_pygame(Vec2d(event.pos))
hit = space.point_query_nearest(p, 0, pm.ShapeFilter())
if hit != None:
shape = hit.shape
rest_length = mouse_body.position.get_distance(shape.body.position)
ds = pm.DampedSpring(mouse_body, shape.body, (0,0), (0,0), rest_length, 1000, 10)
space.add(ds)
selected = ds
elif event.type == MOUSEBUTTONUP and is_interactive:
if selected != None:
space.remove(selected)
selected = None
elif event.type == KEYDOWN:
running = False
elif event.type == MOUSEBUTTONDOWN:
running = False
def on_mouse_press(self, x, y, button, modifiers):
""" Handle mouse down events """
if button == arcade.MOUSE_BUTTON_LEFT:
# Store where the mouse is clicked. Adjust accordingly if we've
# scrolled the viewport.
self.last_mouse_position = (x + self.view_left, y + self.view_bottom)
# See if we clicked on any physics object
shape_list = self.space.point_query(self.last_mouse_position, 1, pymunk.ShapeFilter())
# If we did, remember what we clicked on
if len(shape_list) > 0:
self.shape_being_dragged = shape_list[0]
def init_pockets(space):
pockets = []
for i in [(44.1, 43.1), (756.5, 43), (756.5, 756.5), (44, 756.5)]:
inertia = pymunk.moment_for_circle(0.1, 0, POCKET_RADIUS, (0, 0))
body = pymunk.Body(0.1, inertia)
body.position = i
shape = pymunk.Circle(body, POCKET_RADIUS, (0, 0))
shape.color = POCKET_COLOR
shape.collision_type = 2
shape.filter = pymunk.ShapeFilter(categories=0b1000)
space.add(body, shape)
pockets.append(shape)
del body
del shape
return pockets
inertia = pymunk.moment_for_circle(STRIKER_MASS, 0, STRIKER_RADIUS, (0, 0))
body = pymunk.Body(STRIKER_MASS, inertia)
if player == 1:
body.position = (action[0], 145)
if player == 2:
body.position = (action[0], BOARD_SIZE - 136)
body.apply_force_at_world_point((cos(action[1]) * action[2], sin(
action[1]) * action[2]), body.position + (STRIKER_RADIUS * 0, STRIKER_RADIUS * 0))
shape = pymunk.Circle(body, STRIKER_RADIUS, (0, 0))
shape.elasticity = STRIKER_ELASTICITY
shape.color = STRIKER_COLOR
mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories
sf = pymunk.ShapeFilter(mask=mask)
shape.filter = sf
shape.collision_type = 2
space.add(body, shape)
return [body, shape]