Box2d integration

I want to make a game with polygonal collisions and physics, and I looked for any ways to implement chipmunk or box2d, but I never found any way to do it. I'm curious, did I do bad research, or will I have to code my own? Either way, will it actually run with only about 20 objects, each ranging from 6 to 20 polygons?

Chipmunk2d has been implemented in Play.date. It requires a bit of fiddling around to get it going, and I could only get it building under a Linux box, rather than Windows (due to requiring an ARM cross compilation, and issues with my Windows environment, ymmv).

See this older forum post: Chipmunk2D Physics demo

I'm messing around with trying to create a simple Pinball machine for the Play.date, starting with the sample code from that demo. The hardware seems capable of running 6 to 20 objects, although I'm only using spheres and static polygon bodies.

Thanks! I am a linux user so that will be no issue. I'll ser how the perforamce is.

Box2d is also available... see: https://devforum.play.date/t/playbox2d-port-of-box2d-lite-physics-engine-to-c-and-playdate-sdk/1656

That is better since I won't have to make Lua bindings

It's far, far less elegant than the Playbox2d implementation, but I did cobble together a set of proof-of-concept Lua bindings for Chipmunk2D a while ago before life really got in the way, largely by cribbing from work done by Dustin and maximile. Box2d lite is beautifully simple, but it was a little too simple for what I wanted. Chipmunk is much more extensive (for better or worse), which for my purposes meant it could do efficient circles and arbitrary convex polygons.

I haven't had the chance to pick it back up owing to a combination of life events and my tendencies as a, uh, generalist, but I think this demo could be a useful start, and shows a simple way to implement Playdate sprites that are backed by Chipmunk bodies. I found it pretty handy as a scratchpad for performance expectations and mockups of what might be fun physics toys, and I kind of like my editor UI.

It doesn't have Lua bindings for everything (or even most of the things) in Chipmunk, but if you look at luaglue.c you can see a pretty straightforward way to grind out whatever extra Chipmunk methods you need to expose.

Major limitations:

  • Builds fine with make on Mac, but it doesn't have a functioning Windows CMake build. I didn't have fun engaging with the CMake docs or the Windows build toolchain, so I stopped. I assume it's easy if you understand CMake; I just didn't want to understand CMake. The linked forum post does have a built pdx file to play around with.

  • Collision detection/callbacks aren't yet implemented in the Lua wrappers, so while collisions work on their own, you can't query them to, say, trigger sound effects or scoring events, or implement a meaningful sort of "kick"/"jump" action.

Chipmunk handles collision event hooks via callbacks; it'd be pretty cool to be able to register Lua callbacks that get triggered by the Chipmunk runtime with all the relevant data converted, but I'm not smart/energetic enough to really know if that's feasible or desirable. My plan was just to have the C wrapper maintain queriable lists of current collisions based on cpCollisionType, so your Lua code could just ask for those lists and respond to any changes as appropriate.

2 Likes

while I totally get that it's janky, but as long as I can make custom shapes I would totally love to use it!

Less janky than incomplete. Try out the compiled pdx, see if you can build it successfully, and if you have questions about extending or using the wrapper you can feel free to DM me. Iā€™d be delighted if someone got use out of this work.