View Full Version : Making a map editor
CiNiMoDZA
19-10-2007, 11:56 AM
I am trying to make a map editor for one of my games. I have never done this before so I have absolutely no idea what to do! What Im going to try do is store all the data of where all the objects are in a text file, and then when you want to play the map, it will just draw all the data from in there! First off, is this possible, and then, how? If anyone has a better idea, please share ;)
Tr00jg
19-10-2007, 12:25 PM
Yes, this is a very viable way! I have done it when I wanted to port my Roach Toaster levels from Game Maker to XNA, but there is a much easier way in fact.
Just use Game Maker's save and load feature. Peanuts.
After you finished making the map, save the game in a separate save file that user specifies, ie "John_level".
When you want to load that map, the ask the user to type in the name of the map, and then let Game Maker load that save file.
Understand?
Gazza_N
19-10-2007, 12:37 PM
I've always done it via text files myself. As an example: When I did the editor for Overseer Assault, I decided on numbers to represent my three tile types - wall tiles (1), empty space(0), and spawn points(2). All I did then was set up an interface to place the different tiles, then, when saving, used a pair of FOR loops to iterate across the map. I used collision_point checks to see what tile was at the coordinates my loops were pointing to, and depending on the tile (there's a function to determine what object type an instance is, I forget it right now), I shunted the corresponding number into the text file. To load the level, I just ran the same thing in reverse, reading the numbers from the level file and doing instance_create accordingly.
The most complex thing in doing a map editor is really deciding what info you need to store, and how you're going to store it. That's the trick. If you want another example, open up one of the .RKT files from Rockets! in a text editor to see how I did it for that game. ;)
CiNiMoDZA
19-10-2007, 01:06 PM
Ok, well what Im doing to Read from the file is use a FOR loop! But now how do I stop the loop if there is no next line??? For example, say I have this
for(i=1;i<=10;i+=1)
{
line[i] = file_text_read_string(mpread)
file_text_readln(mpread)
show_message(line[i])
if (line[1] = ' ')
{
i = 10
}
}
But I only have three objects, how do I stop the loop from continuing! Also then, with the instance create thing, how do I make x=line[i], y=line[i], bearing in mind that the y's line[i] is not the same as the x's??
Ok, nvm! Im such a dumbass!!! I got it now! I just need to know how to kill a loop when it gets to a blank string!!
CiNiMoDZA
19-10-2007, 01:13 PM
Ok, wait! So now when I create an object, it writes
'instance_create('+create+', '+string(x)+', '+string(y)+')') into the "map file". Now how do I run this code from the file???
Korax
19-10-2007, 01:35 PM
Using XML will be a good bet if you are going to save/load to and from text.
That saves you having to write your own parsing code.
CiNiMoDZA
19-10-2007, 01:39 PM
Um, whats XML :P
dislekcia
19-10-2007, 02:10 PM
Ok, wait! So now when I create an object, it writes
'instance_create('+create+', '+string(x)+', '+string(y)+')') into the "map file". Now how do I run this code from the file???
From the helpfile:
execute_string(str,arg0,arg1,...) Execute the piece of code in the string str with the indicated arguments.
execute_file(fname,arg0,arg1,...) Execute the piece of code in the file with the indicated arguments.
-D
ShadowMaster
19-10-2007, 02:31 PM
Using XML will be a good bet if you are going to save/load to and from text.
That saves you having to write your own parsing code.
Korax that is over kill and will result in neciasseryly large map files as XML is very verbose. Seriously it is easy enough to read integers from a file in most languages.
@CiNiMoDZA: XML-Extensible Markup Language.
It is basicly very much like html and creates easily human readable and editable files. I suggest using it for game tweaking as you don't have to recompile every time you change something.
Here's a example:
<recipe name="bread" prep_time="5 mins" cook_time="3 hours">
<title>Basic bread</title>
<ingredient amount="3" unit="cups">Flour</ingredient>
<ingredient amount="0.25" unit="ounce">Yeast</ingredient>
<ingredient amount="1.5" unit="cups" state="warm">Water</ingredient>
<ingredient amount="1" unit="teaspoon">Salt</ingredient>
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 350? for 30 minutes.</step>
</instructions>
</recipe>
Read this wikipedia article for more info: http://en.wikipedia.org/wiki/XML
CiNiMoDZA
19-10-2007, 03:04 PM
Thanks guys, its working and its really kick@$$ Now people will be able to download mpas for my game and they'll only be like 200kb! If the map is really big!!!! Thanks hey!
CiNiMoDZA
19-10-2007, 04:14 PM
Um, ok! Hopefully last problem!!! How do I change my room size while already running the game? room_set_height and room_set_width dont seem to be working?
Powered by vBulletin® Version 4.2.4 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.