![]() Because we have three level-related objects, there are three cases. When there’s a match, the script stops its execution and returns an object. The code block takes argument0, our character, and checks it against all the different cases. Otherwise, if you try running your game you’ll get an error telling you the script doesn’t exist. You can go ahead and create an empty generator_import_levels script for the time being. This script, which we have yet to write, will read the levels.txt file and populate the level_data array. If the choice of 64 width and height seem arbitrary, refer to the fact that these are the dimensions of my sprites.įinally, we’ll end the Create Event with a call to script generator_import_levels. Objects will be placed in the room at intervals of 64 pixels. ![]() In other words, each character we write in our text document will correlate to 64圆4 pixels of in-game real estate. Variables cell_width and cell_height are the base width and base height of cells in our grid. We should, in theory, be able to design a limitless number of levels in a single text file. When our game reads through the text and comes across this string, it knows that the end of the level is reached and a new level follows. Level_separator is a string of text that’s used to denote the end of a level’s data in the text file. To keep track of the current level that’s being played, we can use variable current_level. It’ll be an array soon, but we’ll initialize it as -1. ![]() We’ll store the data of the levels in the aptly-named variable, level_data. You’ll read more about this in the upcoming level loading section. Creating instances on a particular layer allows us to destroy them later using a simple call to GameMaker function layer_destroy_instances. We'll create instances of obj_wall, obj_player, and obj_coin on this layer later. In the Create Event of obj_generator, add the following code.įirst, let’s create a new layer called layer_level. This will be the only time you’ll use the vanilla room editor for this project! Drag an instance of obj_generator into the first room of your game so it’ll initialize itself as soon as possible. It doesn’t need a sprite assigned to it because it doesn’t need to be seen the generator will do the behind-the-scenes magic.Ĭheck the “persistent” box on the object so it’ll be ever-present throughout your game, regardless of what room the player travels to. Because this controller object will eventually read a text file and generate levels, it can be named obj_generator. We’ll need to create a fourth object that acts as a controller. It’ll be up to you to add in player movement, wall collision, and coin collecting if you choose to turn this sample into a fully-fledged game. For more ambitious games, like large platformers, you might feel restricted.įor simplicity’s sake, I won’t assign any code to the three objects. For mazes and puzzles, this isn’t a problem. You’ll come to realize that one of the major limitations to designing levels this way is that you’re restricted to uniform grid size. You’ll quickly come to realize that writing levels is less of a feat when rows and columns of symbols line up.Īll of my sprites have dimensions of 64圆4. Consolas is Notepad’s default font and it’s monospace. ![]() txt file extension saving.Ī typeface being monospaced means that each of the font’s characters are the same width. My reasoning is two-fold: monospace typefaces and easy. I recommend a code-oriented text editor like Sublime Text or Notepad++ over something like Microsoft Word. It’s similar to Notepad.Īt the end of the day, all you need is a text editor. Mac users, your device comes bundled with TextEdit. If you’re developing a maze game or puzzle game, I implore you to consider this approach. It’s the perfect tool for mass-producing tiny levels. This Windows-specific software is arguably the epitome of “bare bones” and “simplistic”. If you’re on a Windows machine, chances are you’ve used Notepad before. Writing your GameMaker levels in Notepad or TextEdit When GameMaker reads the text file, it will create the associated object at an (x, y) coordinate relative to the row and column of the respective character. In the image above, all “X” characters represent wall objects, all “P” characters represent player objects, and all “C” characters represent coins.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |