http://pymunk.googlecode.com/svn-histor ... tformer.py
I mimic this in my code as follows:
Initiation of the moving platform:
Code: Select all
if x[2] == 2:
platform.image = IMAGESDICT['MovingDanger']
platform.initposx = platform.position_x
platform.initposy = platform.position_y
platform.lx = x[4]
platform.ly = x[5]
platform.sx = x[6]
platform.sy = x[7]
platform.ox = x[8]
platform.oy = x[9]
platform.xxx = 0
platform.yyy = 0
platform.bound = Rect(x[0], x[1], 168, 22)
platform.body = pymunk.Body(pymunk.inf,pymunk.inf)
platform.body.position = from_pygame(Vec2d(platform.position_x, platform.position_y), DISPLAYSURF)
xp, yp = platform.bound.topleft
width = platform.bound.width
height = platform.bound.height
platform.shape = pymunk.Poly(platform.body, [from_pygame(Vec2d(xp,yp), DISPLAYSURF), from_pygame(Vec2d(xp+width,yp), DISPLAYSURF), from_pygame(Vec2d(xp+width,yp+height), DISPLAYSURF), from_pygame(Vec2d(xp,yp+height), DISPLAYSURF)])
platform.shape.friction = 2.4
space.add(platform.shape)
self.platforms.append(platform)
self.movingplatforms.append(platform)
Here is how I update the platform every step:
Code: Select all
for platform in my_map.movingplatforms:
oldpos = platform.body.position
platform.body.position.x += platform.lx * math.sin(platform.sx * platform.xxx + platform.ox) #* dfps
platform.body.position.y -= platform.ly * math.sin(platform.sy * platform.yyy + platform.oy)
platform.body.velocity = platform.body.position - oldpos
platform.yyy += 1
platform.xxx += 1
Here's a pastebin of my entire code: http://pastebin.com/KQJxWszC
Don't hesitate to point out obvious stuff, I'm a noob in regards to chipmunk. I just can't get my head around this problem!