Sooo... I cant seem to do data style tile maps...
Monkey Forums/Monkey Beginners/Sooo... I cant seem to do data style tile maps...
| ||
so, like in BlitzMax I can do something like this:Graphics 240,160 readMap() Flip WaitKey() Function readMap() RestoreData map For y=0 To 9 For x=0 To 14 ReadData a If a=1 Then DrawRect x*16,y*16,16,16 If a=2 Then SetColor 255,0,0 DrawRect x*16,y*16,16,16 SetColor 255,255,255 Next Next End Function #map DefData 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1 DefData 2,0,0,0,0,0,0,0,0,0,0,0,0,0,2 DefData 1,0,2,0,2,0,2,2,2,0,0,0,0,0,1 DefData 2,0,2,2,2,0,0,2,0,0,0,0,0,0,2 DefData 1,0,2,0,2,0,2,2,2,0,0,0,0,0,1 DefData 2,0,0,0,0,0,0,0,0,0,0,0,0,0,2 DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 DefData 2,0,0,0,0,0,0,0,0,0,0,0,0,0,2 DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 DefData 2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 but most of these features appear to be missing from monkey. I kinda need them now to develop a simple intro map for my game. What can I do as a simple alternative? |
| ||
| Take a look here: http://www.monkeycoder.co.nz/Community/posts.php?topic=4474 |
| ||
| @MisterBull: What can I do as a simple alternative? You could use Arrays. Strict
Import Mojo
Class Program Extends App
Field _map1:Int[][] = [ [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1],
[2,0,0,0,0,0,0,0,0,0,0,0,0,0,2],
[1,0,2,0,2,0,2,2,2,0,0,0,0,0,1],
[2,0,2,2,2,0,0,2,0,0,0,0,0,0,2],
[1,0,2,0,2,0,2,2,2,0,0,0,0,0,1],
[2,0,0,0,0,0,0,0,0,0,0,0,0,0,2],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[2,0,0,0,0,0,0,0,0,0,0,0,0,0,2],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[2,1,2,1,2,1,2,1,2,1,2,1,2,1,2] ]
Method OnCreate:Int()
SetUpdateRate 30
Return 0
End
Method OnRender:Int()
Cls 128,128,128
For Local y:Int = 0 To 9
For Local x:Int = 0 To 14
If _map1[y][x] = 1 Then DrawRect x*16,y*16,16,16
If _map1[y][x] = 2 Then
SetColor 255,0,0
DrawRect x*16,y*16,16,16
Endif
SetColor 255,255,255
Next
Next
Return 0
End
End
Function Main:Int()
New Program
Return 0
EndMore like ReadData: Strict
Import Mojo
Global _map1:Int[] = [ 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,
2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,
1,0,2,0,2,0,2,2,2,0,0,0,0,0,1,
2,0,2,2,2,0,0,2,0,0,0,0,0,0,2,
1,0,2,0,2,0,2,2,2,0,0,0,0,0,1,
2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 ]
Class Program Extends App
Method OnCreate:Int()
SetUpdateRate 30
Return 0
End
Method OnRender:Int()
Local index:Int = 0
Local a:Int
Cls 128,128,128
For Local y:Int = 0 To 9
For Local x:Int = 0 To 14
a = _map1[index]
index += 1
If a = 1 Then DrawRect x*16,y*16,16,16
If a = 2 Then
SetColor 255,0,0
DrawRect x*16,y*16,16,16
Endif
SetColor 255,255,255
Next
Next
Return 0
End
End
Function Main:Int()
New Program
Return 0
End |
| ||
| thanks a bunch!, that made things a bit easier for me :) |
| ||
| Arrays or strings both work. Strings need a bit of conversion but are easier and more visual for writing in the data. |