This has been my little baby over the past week or so. It started with jotting down the train game by @PROGRAM_IX from the Pico-8 zine #1, and then making it my own. I ended up using over half my tokens, two sprite banks, and the entire map space. I will leave it to you to discover its mysteries. Playing alongside a warm beverage recommended.
v1.1: Small update to effectively double the rate you gain resources.
function mchk(x, y) return mget(flr(x/8),flr(y/8)) end function move(x, y, w, h, dx, dy, col) w-=1 h-=1 if dx < 0 and mchk(x+dx, y) != col and mchk(x+dx, y+h) != col then x += dx elseif dx > 0 and mchk(x+w+dx, y) != col and mchk(x+w+dx, y+h) != col then x += dx end if dy < 0 and mchk(x, y+dy) != col and mchk(x+w, y+dy) != col then y += dy elseif dy > 0 and mchk(x, y+h+dy) != col and mchk(x+w, y+h+dy) != col then y += dy end return x, y end |
As an exercise, I wrote a small general-purpose collision script and thought I'd offer it up for folks new to P8 or relatively inexperienced with programming.
This is purposefully not a one-stop solution, but it may get you going. It is probably more in the spirit of PICO-8 to come up with specified collision routines yourself. At the very least, there's some study value here.
Things to consider:
- This was built to collide bodies <= 8 pixels wide and tall. With some thoughtful fiddling you can get it to accommodate bodies of any size, but I kept it this way for brevity.
- It takes up 226 memory.
- This is made for colliding against maps only.