Creating Levels. cross platform.

Monkey Forums/Monkey Programming/Creating Levels. cross platform.

Paul - Taiphoz(Posted 2012) [#1]
Sup all. just me your local forum spammer :)

I have progressed my project to the point where I actually want to see nice levels flying past as I mess with the player code, so I have decided its time to tackle the pain that is creating a level structure and level editor.

Now, in anything else I would just loop my array and write the values out to file.

But I assume thats not going to be possible for all platforms, so considering at least 1 array 500 in size, possibly more, what would you guys suggest for saving levels.

Keeping in mind that any level I create, needs to be available on all platforms.

My initial thought is that it needs to be plain text, I recall reading some where that mobiles only read xml or txt files, but im not sure so any suggestions and or thoughts on that would be cool.


GC-Martijn(Posted 2012) [#2]
My first idea is using plain text file stream.
I dunno how big your levels are, but each level a seperate file.
Or you split each level file, into level sectors files.

like
level01_x0_y0.txt
level01_x500_y500.txt

if the player is between (0,0) and (500,500) then they use the first file.

Filesystem works on every device (i hope)


Paul - Taiphoz(Posted 2012) [#3]
Yeah file system its hinky tho, you can only load xml and text files, as far as I know.

and I'm unsure about how you write to and read from the file, I dont think we have access to commands like writeline or readline.

the doc's are terrible.


dawlane(Posted 2012) [#4]
My initial thought is that it needs to be plain text, I recall reading some where that mobiles only read xml or txt files.
At the moment as far as I know Monkey can only handle any files that use proper ASCII or Unicode characters. Gfk did write some code that could code integer and floats into strings, but the class for strings in ios spat the dummy out at those strings. I don't know if he found a work around. But it is possible to write platform specific code to handle raw data. Just don't expect that raw data to work from one platform to another e.g. 32bit floats and 64bit floats.


AdamRedwoods(Posted 2012) [#5]
txt and xml only.

I feel there are binary file load routines for every platform, but monkey doesn't tap into those. I'm surprised the 'OS' module doesn't do this for desktop at least.

Another option would be to use the base64 module to convert data into strings:
http://monkeycoder.co.nz/Community/posts.php?topic=56#139


Paul - Taiphoz(Posted 2012) [#6]
God I am having such a bad programming day, almost nothing I set myself to get done today has gotten done, thanks to crap documentation, a debugger that seems to think every error has something to do with an array, and the fact that im still trying to learn the language and its difference.

kinda getting close to face mashing my keyboard.

Currently I am fighting with String.Split("")

Now the doc's say that String.Split(",") returns an array


Paul - Taiphoz(Posted 2012) [#7]
OH HOLY GOD.. nvm... damn this debugger to hell.


Paul - Taiphoz(Posted 2012) [#8]
in case anyone is wondering, a missing letter in a file name meant that LoadString was not actually loading anything so mu subsequent String.Splits and the rest of my code was getting array index out of bounds and or Null values.

Can the debugger not throw an error if the resulting string or return from LoadString is null ? would have saved me bloody ages of head scratching if it just said, OI dumb ass you spelled the file name with an 0 (ZERO) instead of an o "The letter o".. file name was caps as well which made it almost freeking impossible to spot.

I'll never do that again.


Paul - Taiphoz(Posted 2012) [#9]
First, sorry for the little nerd rage there.. lol. feeling better now.

@ Adam. m8 here is my loading method which loads my game array from file.

	Method LoadStage(stage:Int=1)
		Self.StageSpeed=.7
		Local tmpImage:Image	
		
		Local LevelIN:String
		LevelIN = LoadString("Stage_"+String(stage)+".txt")
	
		game.images.LoadAnim("StageTiles_"+String(stage)+".png", 128, 128, 60, tmpImage)
		Self.StageTiles = game.images.Find("StageTiles_"+String(stage))		

		Local loop:Int = 0		
		For Local NewGrid:String = Eachin LevelIN.Split(",")
			If loop<500
				Self.grid[loop]=Int(NewGrid)
				loop+=1
			End If
		Next	
		
	End Method


My levels are in a Grid array, and they hold the tile or frame number to be displayed, so the file the array is saved out to is just tons of comma separated numbers.


matty(Posted 2012) [#10]
Two things to think of...

you can check if the string returned by loadstring is null simply do this:

mystr:String
mystr = LoadString("filename.txt")
if mystr then
     'put code in here since mystr is not null
endif 


Secondly - I've followed your thread on the blitz forum (nice graphics) and you may already know this but monkey doesn't have pixel perfect collisions so you may have to come up with an interesting way to determine collisions between your ship and the scrolling background....


wiebow(Posted 2012) [#11]
The difficulties with serialization (well, and a proper debugger) is what is causing me to not use monkey yet for new bigger projects.


Paul - Taiphoz(Posted 2012) [#12]
matty, yeah I noticed that.

I have two options as I see it at the moment, the first is to simple not have collisions with the map, assume the ship is flying over the ground as opposed to flying through something.

The other is to create a second map file that lists a box(x,y,x2,y2) for each tile in the tile set, which will be used for collision checking, I will simply load those positions into an array the same depth as the map array, and then in the collision method check where the ship is in the map array, then compare the ships box collision with the box for that tile.

Means it's not going to be pixel perfect but I think that should work, specially for mobile games.


Have to admit tho I was kinda bummed tho when I realized this, because I was planning for this game to be XBox as well and better collisions are deff needed for that platform..

I actually have a third option but its not one I fancy taken on as its bucket loads more work, and a bit much considering im still getting my feet wet with the language, and thats to actually create the maps and ships with lines/vectors and then do cirlce to line checks, but I really dont wana do that.


Paul - Taiphoz(Posted 2012) [#13]
I think, yeah I have descided that collisions will only be checked between the ship, aliens, and bullets, powerups .. the map is ground, and your flying over it so that reduces the work a little.

Also means I can, or should be able to get away with radius collision detection which actually fits well with my ship design.