Log In  


Previously when making games in LOVE2D, I made use of a simple 2D axis-aligned physics library called bump.lua. I especially enjoyed the versatility (e.g. different collision types and outcomes based on custom filtering) and the simple, intuitive API. I wanted to see how effectively it could work in PICO-8, so I forked it.

pico8-bump.lua

The main obstacle to running bump was that PICO-8 has no access to the math lua module and uses 16-bit ints, so all math.floor etc. calls were replaced with their PICO-8 equivalents. math.huge did not have a standard PICO-8 analog, so the 16 bit int max (32767) was hardcoded instead. Likewise, PICO-8 lua does not parse 10e-10 style numbers, so DELTA was changed to a regular decimal value. In addition, PICO-8 does not have access to the table module, so a separate sort function was added to replace table.sort.

I also deleted portions of the library that I didn't consider necessary for my own uses to save on tokens and characters:

  • bounce and touch collision types
  • anything involving querying segments (note: querying rects and points are unchanged)
  • all sanity checks and assertions that bump would normally make e.g. assertIsPositiveNumber or assertIsRect. While these are useful for debugging and avoid weird inconsistent states, they eat up precious tokens. I've used bump enough in other games to feel comfortable enough without these safeguards.
  • public bump.rect and bump.responses tables. I honestly never used them anyway.

What's left is still a robust physics library for rectangles and points. Here's a quick demo platformer using bump.

Cart #bumpdemo-0 | 2020-08-30 | Code ▽ | Embed ▽ | No License
10

Naturally, the primary concern with any library in PICO-8 is tokens and characters. Here's what it clocks in at:

Usage Max %
Tokens 2646 8192 32.3%
Characters (unminified) 17390 65535 26.5%
Characters (minified) 9366 65535 14.3%

I haven't quite figured out just how big that footprint is. Obviously 32.3% is a sizeable number of tokens to give away, but, like I mentioned, bump's interface is pretty simple, which saves tokens later down the road (every attempt to move an object within the world can use as few as 11 tokens). In addition, it's possible to go back and delete more from the library before releasing if the functionality is unused (e.g. for the demo above, anything involving querying the world is unused and could be deleted). I'm sure bump would be overkill for any game that doesn't require anything beyond simple collision detection with overlapping rectangles, but I'm optimistic it could still be beneficial for more complex use cases. I plan to find out.

10



[Please log in to post a comment]