If you have a game in C++, but you can't be bothered going through all the sections to design the game map, (Ive seen some C++ maps that are more than 100x100), i have made a GML code that will create a 2D array of numbers, containing the objects in each position.
Intructions: (after you have opened game maker and made a new game)
1) Create a number of sprites, maybe one for a platform, one for a box, one for the player, two or three for different enemies, basically, one for each object in your game.
All of those sprites have to be the same size, and square. 16x16 or 32x32 is recommended, i always use 16x16.
2) Create an object called
obj_pieces MAKE SURE IT IS SPELT JUST LIKE THAT!!!
3) Then you create an object for each of the sprites, assigning them a name and their corresponding sprite.
Then make obj_pieces their parent!!!4) Make an object called
obj_coder.
In its create event, put this code:
| | |
| Code: totaltext="" txtname=get_string("Enter the name that you want this to be saved under.","Level_Details") + ".txt"; grid=get_intege("What is the grid size?",16) fileid=file_text_open_write(txtname) xxx=room_width/grid yyy=room_height/grid file_text_write_string(fileid,"int map[" + string(xxx) +"][" + string(yyy) + "] = {") file_text_writeln(fileid); totaltext="int map[" + string(xxx) +"][" + string(yyy) + "] = {"+ chr(13) + chr(10) for (yy=0;yy<room_height;yy+=grid) { file_text_write_string(fileid,"{") totaltext+="{" for (xx=0;xx<room_width;xx+=grid) { ins=instance_position(xx,yy,obj_pieces); if ins = noone { str = "0" } else { switch (ins.object_index) { case obj_platform: str = "1";break; case obj_ladder: str = "2";break; case obj_player: str = "3";break; case obj_enemy: str = "4";break; case obj_box: str = "5";break; default: str = "?" } } file_text_write_string(fileid,str); totaltext+=str if xx+16<room_width { file_text_write_string(fileid,",") totaltext+="," } } file_text_write_string(fileid,"}"); file_text_writeln(fileid); totaltext+="},"+ chr(13) + chr(10) } file_text_write_string(fileid,"};") totaltext+="};" show_message("Complete"); clipboard_set_text(totaltext) game_end() | |
| | |
Where i have:
You change it for each of your objects. Make sure the default: str = "?" is at the end though, that will inform you (by putting a question mark in the grid) if an object (with
obj_pieces as its parent) isn't listed. Basically, on each new line you put:
case objectname : str = "value"; break;
NOTICE THAT THE VALUE IS IN QUOTATION MARKS! IT HAS TO BE A STRING! each object should have its own unique number.
Once you have done that, you are done. It is pretty simple to add or remove objects, but if it is all for the same game, i strongly disadvise removing objects. Adding new ones is fine.
Now to start making the room and turning it into code!Click new room.
Start placing the objects around the room. Make sure you make it remove underlying objects, this is because the
obj_coder will only check one object per grid section, and it reduces the chance of picking up the wrong object. Try holding down shift, it makes drawing platforms much easier.
Once you have made the level,
add obj_coder into the room, in a blank spot.Save the file to the place you want the txt files to be created. I advise you make a folder, so it is not mixed up with other files.
Then click run! The program goes through these steps:
-Asks you for a name. The default is Level_Details, you can put what ever you want. This will be the name of the text file (you don't put .txt at the end, just the name)
-Asks you for a grid size. This is the size of all your sprites, so for me, it is always 16.
-A message appears saying complete. Click ok.
-All the code is now in the file Level_Details.txt (or what ever name you put .txt)
-Also, the code has been copied to your clipboard
-Now the game ends.
IF YOU WANT TO HAVE MORE THAN ONE ROOM IN YOUR PROGRAM, REMEMBER IT ONLY DOES THE FIRST ONE, SO REARRANGE THE ORDER TO DO A DIFFERENT LEVEL.
If you use this, credit would be cool, but i don't really care, i made it for myself to save time, but decided other people might want it too.