From 37622b8d30ee9b016f85f12abf00214a97ac8619 Mon Sep 17 00:00:00 2001 From: Brian Jordan Date: Mon, 03 Nov 2008 01:14:13 +0000 Subject: Added physics example, library (elements/pybox2d/box2d) --- (limited to 'data') diff --git a/data/physics/shapes b/data/physics/shapes new file mode 100644 index 0000000..111b22a --- /dev/null +++ b/data/physics/shapes @@ -0,0 +1,53 @@ +# physics + +import pippy, pygame, sys, math +from pygame.locals import * +from pippy import physics + +# initialize pygame first thing +pygame.init() +screen = pygame.display.set_mode((1200,900)) +clock = pygame.time.Clock() + +# set up the physics world (instance of Elements) +world = physics.Elements(screen.get_size()) +world.renderer.set_surface(screen) + +# set up initial physics objects +world.add.ground() +world.add.ball((600,0), 50) +world.add.rect((500,0), 25, 300, dynamic=True, density=1.0, restitution=0.16, friction=0.5) + +# add 20 more balls +balls = 0 +while(balls<20): + world.add.ball((balls*5+200,balls*5), 50) + balls+=1 + +# begin physics simulation +world.run_physics = True + +while pippy.pygame.next_frame(): + while world.run_physics: + + for event in pygame.event.get(): + if event.type == QUIT: + sys.exit() + + elif event.type == KEYDOWN: + sys.exit() + + # clear display with a color + # (r,g,b), where 0<=value<256 + screen.fill((80,160,240)) + + # update & draw physics world + world.update() + world.draw() + + # update the display + pygame.display.flip() + + # try to stay at 30 frames per second + clock.tick(30) + -- cgit v0.9.1