Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pygame.init()
screen = pygame.display.set_mode((width,height))
clock = pygame.time.Clock()
font = pygame.font.SysFont("Arial", 16)
# We will draw two versions of the Pymunk Space, each on a separate surface
# to make it easy to show both at the same time.
surf1 = pygame.Surface((300,300))
surf2 = pygame.Surface((300,300))
# Setup the base Pymunk Space.
space1 = pymunk.Space()
space1.gravity = 0,-1000
space1.sleep_time_threshold = 0.5
draw_options1 = pymunk.pygame_util.DrawOptions(surf1)
draw_options2 = pymunk.pygame_util.DrawOptions(surf2)
box = [(5,5), (295,5), (295,295), (5,295)]
for i,p1 in enumerate(box):
if i+1 >= len(box):
p2 = box[0]
else:
p2 = box[i+1]
l = pymunk.Segment(space1.static_body, p1, p2, 5)
l.elasticity = 0.5
l.friction = 1
space1.add(l)
template_box = pymunk.Poly.create_box(pymunk.Body(), (20,20))
template_box.mass = 1
# Space
self._space = pymunk.Space()
self._space.gravity = (0.0, -900.0)
# Physics
# Time step
self._dt = 1.0 / 60.0
# Number of physics steps per screen frame
self._physics_steps_per_frame = 1
# pygame
pygame.init()
self._screen = pygame.display.set_mode((600, 600))
self._clock = pygame.time.Clock()
self._draw_options = pymunk.pygame_util.DrawOptions(self._screen)
# Static barrier walls (lines) that the balls bounce off of
self._add_static_scenery()
# Balls that exist in the world
self._balls = []
# Execution control and time until the next ball spawns
self._running = True
self._ticks_to_next_ball = 10
def main():
pygame.init()
screen = pygame.display.set_mode((1000,700))
clock = pygame.time.Clock()
font = pygame.font.SysFont("Arial", 16)
space = pymunk.Space()
captions = shapes_for_draw_demos.fill_space(space)
### Draw it
screen.fill(pygame.color.THECOLORS["white"])
options = pymunk.pygame_util.DrawOptions(screen)
space.debug_draw(options)
#pymunk.pygame_util.draw(screen, space)
# Info
color = pygame.color.THECOLORS["black"]
screen.blit(font.render("Demo example of pygame_util.DrawOptions()", 1, color), (205, 680))
for caption in captions:
x, y = caption[0]
y = 700 - y
screen.blit(font.render(caption[1], 1, color), (x,y))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == QUIT or \
event.type == KEYDOWN and (event.key in [K_ESCAPE, K_q]):
screen = pygame.display.set_mode((width,height))
clock = pygame.time.Clock()
font = pygame.font.SysFont("Arial", 16)
# We will draw two versions of the Pymunk Space, each on a separate surface
# to make it easy to show both at the same time.
surf1 = pygame.Surface((300,300))
surf2 = pygame.Surface((300,300))
# Setup the base Pymunk Space.
space1 = pymunk.Space()
space1.gravity = 0,-1000
space1.sleep_time_threshold = 0.5
draw_options1 = pymunk.pygame_util.DrawOptions(surf1)
draw_options2 = pymunk.pygame_util.DrawOptions(surf2)
box = [(5,5), (295,5), (295,295), (5,295)]
for i,p1 in enumerate(box):
if i+1 >= len(box):
p2 = box[0]
else:
p2 = box[i+1]
l = pymunk.Segment(space1.static_body, p1, p2, 5)
l.elasticity = 0.5
l.friction = 1
space1.add(l)
template_box = pymunk.Poly.create_box(pymunk.Body(), (20,20))
template_box.mass = 1
template_box.friction = 1