simple level editor advice
I'm looking for advice on the best method to place enemies in my scrolling shooter. Basically, I have a level that is 30 screens long (640x480 rez, so 19,200 pixels long). Currently I have code that creates a spawner object and spawns enemies based on a variable called "enemy type" that is set when I create the spawner in code.
I want to make a file that is the size of my level and place objects in it that represent the different enemy variables. (obj01 = enemy type1, obj02 = enemy type2, etc) Then I want to export the x,y pos and enemy type to a file (array?). When I run my game, I do a check for the screen's right edge X pos (since the game auto scrolls 1 pixel per frame). I want to spawn enemies when the spawner x positions from the file equal the right edge x position.
In my head, this all seems like a simple approach, but I have no idea where to start here. I have looked at Nifflas' level editor example, but I think it might be overkill for what I am trying to do. Can someone offer any advice on how I might approach this? Array? Ini? List object? I have no experience with writing data out to files, so any help with this would be greatly appreciated.
Mobichan
Re: simple level editor advice
I would NOT use array for this, for such things as enemy locations; a more dynamic approach is generally better.
for example, plain text; you could have a file which looks like this: 1,200,120,15:1,220,200,15
if we used a string parser or tolkeniser we could cut it up in to 1,200,120,15 by using ":" as a delimiter then cut that up using :,: so if we had a fastloop which read each section and put it into an object lets say the first section is 'type' and the second 'x' so forth, see where i'm going with this?
Anyway if I'm not making any since ( because it's to early :tired: ) i can make you an example.
Re: simple level editor advice
I am confused by most of what you said regarding string parsing and using a tolkeniser (tokeniser?). ^_^' Sorry. I understand the concept of laying out the information with commas or colons, but not how I would go about applying this in MMF2. Also, what is a delimiter? An Example would be awesome though, as I tend to learn better from them.
Thanks in advance,
Mobichan
Re: simple level editor advice
Actually the array is a good choice. It can save and load files with a simple action. No need to parse or tokenize anything (this is really slow in MMF anyway).
Just store your data into the array. E.g.:
Y is the number of the enemy
X = 0 is the type of enemy
X = 1 is the X position
X = 2 is the Y position
At the start of the frame you can load the array. Use "add 1 to y dimension index" to trace through the array:
If X Right Frame + 30 is > than ValueAtX( "Array", 1)
Then create enemy of type StringAtX( "Array", 0) at position X = ValueAtX( "Array", 1), Y = ValueAtX( "Array", 2)
And then add 1 to y dimension index
Of course the enemies have to be sorted by X position in this example.
So what happens is that the indexer waits at the current enemy in the array until it comes into view - then it is created and the indexer goes to the next enemy.
To store the enemies into the array, use a loop that runs once per x coordinate:
> Run loop "save enemies" frame width times
+ on loop "save enemies"
+ enemy's pos X = loop index "save enemies"
> Array: Write string to X=0: enemy's type
> Array: Write value to X=1: x position of enemy
> Array: Write value to X=2: y position of enemy
> Array: Add 1 to Y index
Hope this makes sense.
Re: simple level editor advice
SEELE, I respect your opinion, but why are you always saying not to use arrays in your posts?
Re: simple level editor advice
yeah, 2D arrays were almost designed for this purpose
using strings and delimiters is more confusing and probably slower
Re: simple level editor advice
well if you remove a single 'Element'; you either need an Index or to rescan the whole data base after every entry, this will also mean that your max enemys are limited and that even if you don't use all the enemy slots it will still be a sizable file.
I did'nt clarify verywell earlier; The idea is actually really simple, I'll make you an example when i get home.
Re: simple level editor advice
If you load / save in one go, and don't operate on the array, it's no problem if you add or remove items.
What I mean is - in your editor you have AOs representing the object - and you don't have them in the array until you save.
if you don't want a limitation on the number of enemies, you can use the Store X extension (although it does not have an iterator, so use a counter or alterable value for that). It can save binary and ini files (go for binary).
Or even better - use (ooh, one of my favorites) the MagicDeque extension. It can add and remove lines anywhere in the array and even save encrypted files, so the user can not tamper with the levels. Plus it got some very handy extra functionality like foreach loops and searching. In fact I'd most definitely go for this one.
Re: simple level editor advice
Random has the write thinking, I suggested parsing so he could get a grasp of dynamic data.
and yes, if you keep the array buffed while you use it it's possible... but that complicates things pretty far.
Good Luck.
Re: simple level editor advice
Wow. I really appreciate all the feedback on this. Since I have the sample code on using the array, I will try that first. Alot of these other concepts are over my head, so I am getting a little confused from the other suggestions.
To clarify, I will need to store around 100 enemy spawn points per level. Does this limit my options? I also don't plan to add to the array during the level, just read down it one entry at a time until the level ends.
And SEELE, I would still like to see an example if you have time to make one. :)
Re: simple level editor advice
Random: I am trying to set up the exporting side of using the array. I assume that in your example you left out the portion that actually writes out the array to a file. Can you elaborate on how I might approach that? I am using the standard Array object in MMF2 just so I can keep all this simple.
Re: simple level editor advice
Easy. The array has an action "save to file". Just use that and it will nicely save all its content into a file. Same for loading.
I left it out because it's so simple :)
And keep in mind, if you don't want the user to tamper with the file, better use the MagicDeque instead of the array, because it can save the file encrypted.
Re: simple level editor advice
Well, I found that action, but I am using the following condition and it doesn't seem to be working:
+Is the index to the Y dimension at end:
-->save array to file XXXX
-->end application
I am assuming this would translate to "if the array has reached the last value defined in the y dimension (under object settings) then write a file and end the app." This would mean I need to set the array's y dimension to equal the total number of enemy spawners in my level.
I also tried to write the file on a "when spacebar is pressed" condition and it writes a file, but the file is empty when I try to read it in a text editor.
Is there an optimal condition that will basically end the program once the array has filled up?
EDIT: I figured out my issue: I had the loop start on frame start, not always. My bad.
Re: simple level editor advice
I got it working. Thanks so much for all the advice and examples.
Mobichan
Re: simple level editor advice
No problem. Glad you figured it out.
PS: I looked at your stuff. Dude, you're good :D
Re: simple level editor advice
Quote:
Originally Posted by Random
PS: I looked at your stuff. Dude, you're good :D
I agree. Your stuff's great mobichan!
Re: simple level editor advice
Thanks for the votes of confidence. I hope I can continue to make great stuff with MMF2. No offense to the geniuses on the Clickteam staff, but I really would have given up on learning MMF2 by now if it weren't for the phenominal people in the forums. You can be certain my games wouldn't exist without your help. ;) Now to start actually making my levels...
Re: simple level editor advice
Quote:
Originally Posted by mobichan
but I really would have given up on learning MMF2 by now if it weren't for the phenominal people in the forums.
and you're also doing things that most people wouldn't try/learn until they've used MMF for a few years... unless they've already have some programming background beforehand
Re: simple level editor advice
sorry i haven't been on for a while..
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=88898#Post88898