Chipmunk and Jumping

BlitzMax Forums/BlitzMax Programming/Chipmunk and Jumping

SSS(Posted 2008) [#1]
I've recently been programming a small "game" with the excellent chipmunk API. Everything has been going very well so far but I've run into a problem.

I want to be able to have an object "jump" upon hitting the up key. Clearly, though, the object should only jump when it is in contact with the ground. The obvious way to do this would seem to be by setting a collision function. However, the way I am programming this makes things a little harder.

The code to control objects is structured so that any external influence on an object extends a base controller type that holds information on the body that it is controlling. For example, a controller that would allow a keyboard to roll a circle back and forth would be given by this:
Type CirclePlayer Extends Controller
	Method New()
		Name = "CirclePlayer"
	End Method
	
	Method Render()
	
	End Method
	
	Method Update()
		If KeyDown(KEY_RIGHT)
			Body.ApplyImpulse(Vec2(-20,0),Vec2(0,1))
			Body.ApplyImpulse(Vec2(20,0),Vec2(0,-1))
		EndIf
		If KeyDown(KEY_LEFT)
			Body.ApplyImpulse(Vec2(-20,0),Vec2(0,-1))
			Body.ApplyImpulse(Vec2(20,0),Vec2(0,1))
		EndIf
	End Method
End Type 

Furthermore, any controller may be applied to any number of dynamic objects. So you could apply this to three circles, for example, and have them all roll together.

Now, the problem is that I need jumping to work for as many objects at a time as I need. So if I have five instances of this controller running the jumping code needs to be applied to all of them. I'm just not quite sure how to get this working in the chipmunk architecture.

Thanks a lot. If I haven't been clear enough let me know and I'll try harder.


SSS(Posted 2008) [#2]
I sorted it out by using the collision function and then setting the collision data to the shapes. However, this is a bitlimiting and so I'd still appreciate any advice that you all could give me.