100 Days of Code Day 5
Today’s exercism exercise is Lasagna Master and is about declaring and using functions.
I am going beyond the top-down movement exercise for a moment. For today I added some map-building primitives. We already had the mset pico-8 shim that lets you plot a tile. I added several more one to draw a nine-patch, one for a frame/rectangle (basically a nine-patch with no fill in the center), and one to fill a rectangular region with a tile. Also one more to draw a meta-tile.
If you haven’t heard of a nine-patch think of it like the grid below. You fill the edges of the rectangle with the top-center, middle-left, middle-right, and bottom-center tiles. The corners have their own tiles and fill everything in the middle with center.
| top-left | top-center | top-right |
| middle-left | center | middle-right |
| bottom-left | bottom-center | bottom-right |
We sort of already had meta-tiles on the old map layout those are the large grass blocks. They are a 2 by 2 grid of tiles that make up the image. It looks like one thing but it is made up of four tiles. Previously all four tiles were set manually, now we can stamp them as a group on the map. In Link’s Awakening, Link is also made up of a 2×2 set of sprite tiles.
With those functions in place we should be able to build the map with some draw commands which will hopefully be a lot less code space than keeping large tile arrays around. If you have a lot of similar locations you could even put those commands in a function, then for a similar but not exact location, call that function to build a template, then fill in the differences (something like a poke-center in 2D Pokemon games).
