ArrowLeft Designing Your Level ArrowUp Table Of Contents Code Translation Lists ArrowRight

Code Details: IntroEdit

Original research by Superyoshi. Updated by Doram

You may be asking yourself, "Why do I need to know about the code if there's a graphical interface?" The answer is that there are so many more cool things that you can do, if you know how to edit the code directly. Section 5, Tricks & Glitches details all of the cool things you can do by editing the code directly in certain ways. This section will give you the info you need to understand how and where to use the tricks you'll be reading about, and also why they happen (and maybe you can use this to figure out new tricks and glitches of your own).

The way this section is organized is by walking you through the process of writing a level from scratch. The sections are laid out logically, but the examples flow along in order. Examples are colored the same as the section. The way this all works is fairly simple, but you have to pay attention and be careful. Follow the guide in this page all the way through, and you will know how to build levels from scratch in Notepad as well as Suyo and Runouw himself. Good luck.


Basic Code Format:Edit


The code for each level is split into 4 sections separated by tilde(~) characters.

Level SizeEdit

The level size is the size of the tile grid, measured in tiles. The smallest grid possible is 25 tiles wide by 17 tiles tall, and the largest grid is 999x999 (though there isn't a computer in the world that would be able to load it, yet). The default size of the grid (for example, if the "Reset Course" Option in the menu is chosen) is 50x30.

We will be making a level of the smallest size of 25x17. To start our level, we simply put the size and a tilde:




The Tiles Section contains all of the Tiles in the level. They are shown in a grid in the graphical interface, but in the code they are listed in columns, starting at the top-left of the level, and continuing down each column and to the right across the level.

To understand the grid, look at this image. In this example we are making the smallest grid possible of 25x17. If you want to think of the grid like a coordinate plane, we can start at the top-left with 0,0 and proceed to the bottom right at 24,16 (the Y-axis being inverted in this case). (For those of you who are too young to know about Algebra or the Coordinate Plane, there is some info here. A google search on Coordinate Plane will help too.) This will be useful if you are planning your level out on graph paper. The complicated bit is that the code is a continuous string of tiles starting at the first tile (0,0) and finishing with the 425th tile (24,16). Also useful at this point is the table on TILEIDs on the next page. Keeping all of this in mind, we move on...

There are two ways to make a tile.Edit

  • Single Tile
  • Tile With Multiplier

Single TileEdit

The single tile is simply entered as the TILEID, and nothing else.

For example, the TILEID for the first tile (1 Jungle Tile Top) is 2K. So, returning to our 25x17 grid, and putting 2K in the first space of 0,0, including the size from the first section, our code begins like this:


Now, let's make the land a little bigger, by adding in the next logical tile - 3 Jungle Ground. It's TILEID happens to be 2M. Adding a tile is as simple as adding the Tile ID, so:


As we remember, the tiles run top to bottom and left to right, so our second tile is put directly under the first in the grid at 0,1.

Tile With MultiplierEdit

Placing more than one tile at a time requires the Tile With Multiplyer notation. This consists of the TILEID and a MULT surrounded by asterisks (*) like this: TILEID*MULT*

This is most important with empty space, as it is necesary for empty levels and the END of the Tiles Section.

Back to our example, our tiles have no room above them for Mario to stand on, so we are going to move them down with some empty space. The TILEID for empty space is zero (0). You can supposedly use 100 as well, but why type 2 extra characters if you don't have to, right? Since our level is 17 tall, and we already have 2 tiles in place, we need 15 tiles of empty space. We will also put our new code in front of our code for 2 tiles so that our empty tiles are above our solid land tiles in the resulting grid. So, our code for 15 empty tiles is 0*15*, and it goes in our code like this:


Now let's say we want to make a bit of flat land for Mario to stand on. We would like to continue our two tile pattern across the next 5 columns. Now, the tiles are laid out starting at 0,0, continuing to 0,16, and continuing further from 1,0 to 1,16 and so on. So, if the next column simply comes after the first, we can copy the code for our first column and place it right after the code for the first column. This will result in Empty, Empty, Empty ...(15 times)... Tile1, Tile3, Empty, Empty, ... (15 times)... Tile1 Tile3. Our code now looks like this:


And repeat 3 more times for 5 columns:


And, just to be fancy, let's replace those last 2 tiles with the proper edge tiles of 8 Jungle Corner Right and 16 Jungle Wall Right, with TILEIDs of 2R and 2Z respectively, so we don't have any cutoff:


End of Tile SectionEdit

The END of the Tile Section is taken up with the number of remaining empty tiles in the level. This will be in the format of a Tile With Multiplyer of Empty Tiles: 0*MULT*

Now, let's say that we want there to be no more tiles in our level. That's as much land as we need. To finish the Tiles Section, we need to account for all of the tiles in the level, otherwise we will end up with glitch tiles. This is where END comes in. We will put empty tiles in the rest of the level. In our case, we have a 25x17 level which amounts to 425 tiles. We've placed 5 columns worth of tiles, and that's 17x5 = 85 tiles. Take those away from the total and 425 - 85 = 340. We need 340 empty tiles, and that goes in our code like this:


Add a tilde to close the Tiles Section, and our level is half done:


Now hold on a second, you might say. What if my tiles run right up till the very last position? Well, in that case, don't worry friend. You can just skip the END entirely and put your tilde in. You're done!


The Items Section contains all of the Items in the level. Items are placed on the same grid as tiles are, but have more freedom.

That freedom exists because Items work a little differently than tiles. Items are positioned on the grid in pixels. Remember that a tile is 32x32 pixels? Well, that trivia comes in handy now. Our 25x17 tile grid is now an 800x544 pixel grid. Want another curveball? Ok. the pixel grid's 0,0 point is NOT in the upper left corner. It is one tile (32 pixels) to the right, and one tile down. That means that items positioned on the very top-left corner of the level are at -32,-32. One of the reasons for this (There's a reason?!?) is that items are placed by their center point. Yes, you heard right. The exact center of the item. Don't ask me why any of this is the way it is. I didn't make the game, I just play it.

Anyways, Items, or as they are known in the industry, sprites, are placed in the level by their pixel position, and have a different number of settings for each item. Since the length of the code for each item will be different, the pipe (|) is introduced as an end marker character for specifying where the code for one item ends and the next begins.

All items start the same, with their SPRITEID, XPOS, and YPOS, one after the other, separated by commas, with no spaces in between parameters. All other settings are added in the same way, with commas and no spaces.

There is only one required item, and that is the Start Position.

So, to place an Item we need the SPRITEID, which is MUCH easier to calculate than TILEIDs (see the table on SPRITEIDs on the next page). The SPRITEID of 1 Start Position happens to be 1, and it only takes a few settings. The settings common to all Items are of XPOS and YPOS, and they are simply the coordinates on the grid for the center of the item. The three other settings that this particular item takes are Xspeed, Yspeed and Direction. Xspeed and Yspeed are what they sound like - it's true, you can start the level moving. Just remember the pixel grid we're dealing with - Postitive X is to the right and negative X to the left, and positive Y is down and negative Y is up. Direction is another very common setting that just determines whether the item is "facing" right or left (the dialogs for some items list this as "Mirror").

All of that out of the way, we want our Start Position to be above the ground, and the traditional spot for that is 1 tile above the surface (so that you aren't starting the level in the ground and thus glitched). So, we have a 17 tile tall level, minus 2 tiles for land, and minus another 1 tile for the center of the item, we have a Y value of 14 tiles x 32 pixels = 448 pixels. Now, remember that our y scale starts at -32, so let's take that off our result. 448 - 32 = 416 pixels. Let's go easy on ourselves and place it at 0 for the X position, putting us at 0,416. Let's also not get crazy with the speed and leave both of those settings at 0. The default Direction is Right, which is fine by us.

Now the particular syntax we'll use for the Start Position is SPRITEID,XPOS,YPOS,XSPEED,YSPEED,DIRECTION (see the Individual Sprite Syntax List on the next page for more info), so putting it all together, and we have 1,0,416,0,0,Right. Remember the tilde to signify that we are starting the Items Section, and then put that at the end of our code, and it looks like this:


Now, what is a level without a Shine Sprite to finish it off. Now we look at our 6 Shine Sprite and get our SPRITEID of 6. And, since the Shine Sprite doesn't do anything except end the level, the only settings we need to know are it's position in the level (XPOS and YPOS).

Now, we already did the math for where Mario is, so we have the Y figured out already (we might as well put it at the same level as Mario for simplicity's sake). So, we need to figure out where horizontally we want the Shine Sprite placed. Let's say that we want it right on the edge of our little bit of land, like 4 tiles from the left edge. So, we have 4 tiles x 32 pixels = 128 pixels. Now, remember that our x scale starts at -32, so let's take that off our result: 128 - 32 = 96.

So, we have done the math for the x axis (96), and we are taking our math for the y axis from before (416), and we are putting it together with our SPRITEID of 6 in the syntax of SPRITEID,XPOS,YPOS to get 6,96,416. Add a pipe at the beginning to signify that this is starting a new item, and add that at the end of our code, and it looks like this:


Course SettingsEdit

The Course settings consist of the IDs for the Music (MUSICID) and Background (BGID), and the name of the level. All parameters are separated with the Tilde (~) character and have no spaces between them. Level names are limited to 32 characters, and can consist of any ASCII character.

Ok. This is cake. We're going for a simple level, so let's just go with defaults. The default music is Mushroom Kingdom with a MUSICID of 1. The default background is Hills and Clouds with a BGID of 1.

The default level name is "My Level", and if you have read about ASCII anywhere else in this guide, you already know that it is a hexadecimal representation of letters, numbers, and symbols, consisting of the percent symbol and two hex digits, and that the LD code uses it for any character that isn't a letter or number. What this means is that you need to look up things as simple as spaces and periods in something like the ASCII Codes List. For this example, we'll just use space, which happens to be %20. That takes the place of the space in the level name, giving us "My%20Level".

Putting all of that together, with a tilde to start the section, and tildes in between each setting, we have ~1~1~My%20Level. Add that at the end of our code, and it looks like this:



So, from our initial structure of:


We get our final level of:


Go ahead. Paste it into the LD. It works. Congratulations! You are now a Code Master. Go forth and design levels!

If you came here first, you might want to check the Designing a Level section for some more specific info on designing a level using the graphic interface of the LD. You can also check out the Focused Guides, and Tricks & Glitches for more in-depth coverage of good practices and general level design theory. The next page has tables of info on the variables used by the LD. Have fun!

ArrowLeft Designing Your Level ArrowUp Table Of Contents Code Translation Lists ArrowRight