pymunx : a simplification class for pymunk

Share your projects and Chipmunk enhancements.
Post Reply
crazy-chris
Posts: 7
Joined: Tue Mar 04, 2008 3:40 am
Contact:

pymunx : a simplification class for pymunk

Post by crazy-chris »

Hey all,

I'm getting more and more familiar with pymunk (thanks Victor!) and enjoy the chipmunk physics a lot! I'm doing a few demos to get some experience, and started to write a simplification class for pymunk, to make it's easier to implement pymunk in pygame for example. As a working name I picked pymunx.

It's a good demo for me and maybe for others too, so I decided to write a very little documentation and post it here. It's very simple at the moment, but I'll add functions very quickly :) The idea would be, to provide developers easy to use, basic commands like add_wall, add_ball, add_square, ... so they do not have to worry about anything more :)

I'll post my updates at http://www.linuxuser.at/pymunx. Have a look at the very slim pymunx_demo1.py, or pymunx.py.

The typical usage in pygame looks like this:

Code: Select all

	import pygame
	from pygame.locals import *
	from pygame.color import *	

	from pymunx import *
	
	pygame.init()
	screen = pygame.display.set_mode((800, 800))
	clock = pygame.time.Clock()

	world = pymunx()
	world.add_wall((100, 200), (300, 200))
   	
	# Main Game Loop:
	while running:
		# Event Handling
		# Maybe calling world.add_ball(event.pos) or world.add_square(event.pos)
		# ...

		screen.fill((255,255,255))

		# Update & Draw World
		world.update()
		world.draw(screen)

		# Flip Display
		pygame.display.flip()
		
		# Try to stay at 50 FPS
		clock.tick(50)   		
Here's the overview of the class pymunx:

Code: Select all

class pymunx:
	def __init__ (self)
	def flipy (self, y)
	def autoset_screen_size (self)  # Gets screensize from pygame. Call this by hand only on resize

	def update (self, fps=50.0)	  # Updated thy physics
	def draw (self, surface)	     # Iterates through all elements and calls draw_shape with each
	def draw_shape (self, surface, shape)	# Draws a given shape (circle, segment, poly) on the surface

	def add_wall (self, p1, p2)	  # Adds a fixed wall between points p1 and p2
	def add_ball (self, pos, radius=15, mass=10.0, inertia=1000, friction=0.5)	# Adds a ball at pos. Other parameters are optional
	def add_square (self, pos, a=18, mass=5.0, friction=0.2)	# Adds a square at pos.
Post Reply

Who is online

Users browsing this forum: Metager [Bot] and 31 guests