Version 0.2-- Reconfigured repeating pattern object types for adjustable pattern size, added level delete option to editor menu, and changed a few design elements to improve usability
This is a graphical map editor that allows creation of large game worlds hundreds of screens in size that fit in a single Pico-8 cart. It does this using a version of metatiles, a compression technique used commonly with retro systems like the NES. Basically, levels are stored more efficiently by being built from groups of tiles instead of single tiles, just as images are stored more efficiently when built from tiles rather than single pixels.
To give you an idea of how efficient the scheme is, I built a playable demo of all Super Mario Bros. level maps with an earlier version, and they fit in just 3.9KB, about 1/3 of the storage space the system makes available.
I've worked hard to minimize the system's footprint so it's easy to add to game carts. It's very CPU-efficient and well-suited to 60fps games since map decompression is done only when loading a new level, and the core functions take about 650 tokens and 9% of compressed file size with comments, or about 6% without. You can use it in any project you want and modify the code to fit your application, just be sure to include attribution somewhere in your cart. Hopefully this will enable people to make some cool larger-scale games like platformers and action-adventures.
The editor lets users create levels from metatile "objects", like a tree, a hill, or a building, each of which is basically a reference to a rectangle of tiles in Pico 8's map area. In the editor, levels are stored as lists of objects in string form, but when exported to a separate cart, these are condensed into raw binary data and stored in its spritesheet and map areas. Meanwhile, three strings are output to the clipboard, ready to be pasted into the code area--compressed sprite and map area data strings, and a string-based lookup table for the location of each level's data in cart memory.
When the destination cart is run, the binary level data is transferred to a table in Lua RAM and the spritesheet and map area data are decompressed to the proper areas in cart memory. On loading a level, a second table is created to contain its map, and this is filled using instructions from the main table. A portion of the level table slightly larger than one screen is then copied to the top right corner of Pico-8's map area once each frame and mapped to the display. This allows each level to be any width or height, and up to 256 screens in size.
Left Mouse btn.-----Select or place object/bring up object placement preview
Right Mouse btn.---Click and hold to drag view (turns off object placement preview)
Directional keys----Move view
Scroll Wheel--------Select object number
Z--------------------Toggle object editor screen
X--------------------Delete object when mousing over its top left corner (a white 'x' will appear)
--Editor shortcut keys
V-------------------Change variance type (when in obj.editing mode)
M-------------------Change mapping pattern type (when in obj.editing mode)
S-------------------New level string submenu
Q-------------------Previous level map
W------------------Next level map
E-------------------Export level map to cartridge
A-------------------Export all level maps to cartridge
Directional keys---Move camera
Z-------------------Previous level map
X-------------------Next level map
Using the editor
Creating a new level
Once you've started the editor, if you want to create a new level string, open the menu and click on the 'new level map' icon. Select your desired background color, level type (work in progress), level width and height in screens, and press the checkmark icon to create the new level string.
Since your maps will be made from tile patterns in Pico-8's map area, you'll need to draw each object type there before you can use it. Due to the way the system works, you'll need to keep a couple of limitations in mind.
To create objects to populate your level map, select the object category using the icons on the top right, then the object number either by clicking the thumbnail and selecting a slot from the drop down menu, or by using the mouse wheel. To create an object, go into object editing mode by pressing 'Z' and outline the rectangle of tiles that defines the object's default (minimum) size.
Each object type can be made to have a variable size. This is done by changing two properties, its variance and mapping pattern. These are represented by icons in the lower right corner of the editor, next to the object's ID number.
An object's variance type tells how its size can be altered when it's being placed in a level.The box that's highlighted defines the default (or minimum) size of an object, but if its size is variable along an axis, the size can be extended up to 15 tiles larger than the default size in that direction. Fixed-size objects take 2 bytes each, while ones whose size can vary on one or two axes take 2.5 and 3 bytes respectively (though it'd be possible to limit this to 2.5 bytes max via lookup tables if you only need certain types in a given level).
This property controls the pattern of how map tiles are used to build objects in your level. This can allow objects to be made much larger than their representations in Pico-8's map area while still keeping their intended traits.
To change these settings for an object, go into the object editing mode and click on the buttons in the bottom right hand corner, or press the 'V' key to cycle through variance types and the 'M' key to cycle through mapping types.
The system continuously outputs the level you're working on and the list of definitions for all the objects you've defined to the clipboard as strings. To save these to the cartridge, just paste the contents of the clipboard over the current strings in the "data strings" tab, and save the cart.
Once you've made some levels, you can export them to a separate viewer cartridge, suitable to be incorporated into a game. To do this, first open a new cart and paste the functions from the "Game Cart Functions" tab in the editor there, and uncomment them. Then save the cart with the same name as the "export_cart_name" variable in the editor cart's _init() function, and save and close the new cart.
Next, run the editor, open the system menu, and click on one of the cartridge icons to export either the current level map, or all level maps to your new cart. Now open the viewer cart, make sure "puny font mode" is enabled by pressing Ctrl+P, and paste the contents of the clipboard into it. Now you can run the cart and view your levels.
As this is an early version of the editor, it's missing a few features and may have some kinks to work out, and the code's kind of messy. Please let me know about any issues you encounter, as well as any improvements you might think of. Thanks.
Well, one that some people have been waiting for at least. ;)
It's been up and running for a little while, but I spent some time on the little tutorial that explains the main workings, since I know asking people to switch to a new piece of software can be a tricky thing. I also tried to copy some of Pico-8's appearance and user interface elements to make things feel familiar. Hopefully people won't find it hard to understand or use.
Thanks, figuring out how to implement the delete feature and make it work with the undo button took a while, but I think it should help avoid headaches with managing level strings manually. The redesign of the object types should add a lot more versatility and save storage space as well. If you've made some maps it could mess up parts of them, but I updated the tutorial to show how the adjustable pattern-size objects work now.
The next revision I'm working on will let you layer metatile maps on top of each other for multiple parallax scrolling layers. =)
[Please log in to post a comment]