After messing with other peoples’ extensions, it’s high time I made my own! I’ve always had fun messing with the underlying data structure of tilemaps, so now block users can too!! Now, don’t get me wrong, this is not a perfect extension, but I can use it to do all the stuff that I want to do, so hopefully you can too!
WoofWoofCodes/Pxt-TilemapGen
Demo!!
It’s mainly called tilemapGen because by using it, you can create tilemaps of any size you want in runtime, using an array of numbers to specify which tile goes where. This could be used for things like saving tilemaps and generating them using algorithms for random worlds and stuff. I’m just going to go down the list of blocks, because I can’t really decide where else to start. Also, let it be known that I didn’t really organize the blocks very much, so they are kinda all over the place
Blocks:
Get normal tilemap ( ) tilelist
Allows you to grab the list of blocks used in a normal tilemap, in the form of an array of images. As @richard explained here, it is not possible to just grab a list of all the tiles that have been defined, but it is most certainly possible to steal that list from a tilemap that uses them! So yeah, that’s the purpose of this block. It is important to note that the tilemap must be using all the tiles you want to grab, so you can’t just use a blank tilemap, unless you just want transparency16, which is a 16 x 16 blank image.
(tilelist)
This stores a list of tiles for you. This is just the little block that lets you Get that list. Nothing special.
set tilelist to image array ( )
You put an array of images in there and you can access it with the little “(tilelist)” block above. This array is also used by other blocks later. It is important to note that this does not add to the array, it overwrites it. Keep that in mind.
add tile (image) to tilelist
Self explanatory.
add tilemap with id ( ) width ( ) height ( ) data array ( array of [] ) wall image (image)
Now we’re getting somewhere! I made a sorta kinda maybe convenient(?) way to store tilemaps that you make using an ID system. If you make multiple with the same ID, the one found when you search (block that comes later) will be the one created first. The width and height fields are obvious. The data array is what you use to hold the locations of each tile. For example, if I made the first number of this array 0, the top left corner of my tilemap would be whatever tile is in the first (0) index of the tilelist array. Usually, in a built in tilemap, this would always be the transparency16 tile, but you can do whatever you want! If you make the data array too short to cover every tile, the rest will be filled in with 0s for you. The list defines tiles going left to right, top to bottom.
The wall image is another thing! Drawing red in this image will make walls on the corresponding tiles. (That’s color #2 for all the color palette changers out there) You should probably make this image the same size as your tilemap, but who am I to judge? Do whatever you want lol.
< map with id ( ) exists >
Self explanatory. It’s a Boolean, so it’s either true or false. You put them in If statements or whatever, idk.
( map with id ( ) )
This is how you access your stored, id having tilemaps! Now, you can’t just put this into a “set tilemap to ( tilemap )” block just yet, you will have to use the “( (tilegenMap) [tilemap] )” block to do that. It’s down below in the Saved Maps section. Just replace the “(tilegenMap)” variable with the “( map with id ( ) )” bit!
generate tilemap with (tilelist) width ( ) height… etc
Now this one you can put into a “set tilemap to ()” block! These tilemaps aren’t saved, unless you save the data yourself of course! If you want to, you can take out that little “(tilelist)” variable bit and put in whatever image array you want! Have fun!
Saved Maps section:
(“TilemapGen” shortened to “tmg”, and I will only be covering the Set half of the Get/Set blocks because the Gets are pretty much self explanatory)
set (tmg) wall image to (image)
I would say this one’s self explanatory enough.
set (tgm) tilemap to ( )
I honestly don’t know why you would use this one, because the other variables don’t change when you use it, so everything ends up all wrong and stuff. This element just saves a pre-packaged version of all the tilemap data so that it doesn’t have to re-compile it all every time you use it to set the tilemap.
The Get part, on the other hand, you really need that. It’s how you put the “map with id ( )” block into the “set tilemap to ()” block, so it’s very important.
set (tgm) map data array to (number array)
You use this to change that. Yup. That’s it.
set (tgm) width/height/id ()
The first two, width and height, are obvious. Fair warning though, messing with these will mess with all sorts of squishy wishy stuff with your tilemap, especially messing with the width, which would lead to your blocks and everything sliding all around. This also does not change the wall image at all. Also, you’ll probably get very confused if you start changing around IDs, so unless you know what you’re up to, maybe don’t touch any of these.
Yay! That’s all the blocks! If I missed one, it’s because I added it after this was posted, so check the replies to find an explanation.
Hope you all enjoy!!