I have started a new game, and I was wondering if anyone knew of a tutorial on reading data commands, or give me some assistance, Thanks.
Data
BlitzPlus Forums/BlitzPlus Programming/Data There's a perfect explanation in the help. Other than that, I advice not to use data statements; use external files. This way you can change gamedata without the need to recompile your code.
I would like an example that shows how to make the tiles move and respond to the character.
uh, for what kind of game? Be more precise.
A mouse voider game where the map moves and you must stay in a certain area to win. *Please don't take my idea!!!!!
Have you looked in the \tutorials section ? There are some examples that might be helpful: sidescroller and tilemaps. I haven't tried them, but they might help you a bit further.
Thank you, if anyone has any other tutorials, they would be appreciated, but I have got what I need.
I thought that this code worked, but it doesn't, why can't you change what data is being read. I want to be able to change the level.
Graphics 800,600 Const LeftKey=203 Const RightKey=205 Const UpKey=200 Const DownKey=208 Map_Length=49 Map_Height=49 Dim Map$(Map_Length,Map_Height) Restore MapData For i=0 To Map_Length Read Value$ For x=0 To Map_Length Map(x,y)=Mid(Value$,x+1,1) Next y=y+1 Next Const screencenterw = 400 Const screencenterh = 300 Global offsetx = screencenterw - 250 Global offsety = screencenterh - 250 SetBuffer BackBuffer() While Not KeyHit(1) If KeyHit(1) Restore MapDatatwo For i=0 To Map_Length Read Value$ For x=0 To Map_Length Map(x,y)=Mid(Value$,x+1,1) Next y=y+1 Next EndIf For x=0 To Map_Length For y=0 To Map_Height If Map(x,y)="0" Color 0,0,0 Rect x*10+offsetx,y*10+offsety,10,10,1 EndIf If Map(x,y)="1" Color 0,255,0 Rect x*10+offsetx,y*10+offsety,10,10,1 EndIf If Map(x,y)="2" Color 255,0,0 Rect x*10+offsetx,y*10+offsety,10,10,1 EndIf Next Next Color 255,255,255 Rect screencenterw - 250,screencenterh - 250,500,500,0 Color 0,0,0 Rect 0,0,800,50 Rect 0,0,150,600 Rect 0,550,800,600 Rect 650,0,800,600 If KeyHit(RightKey) Then offsetx = offsetx + 10 If KeyHit(LeftKey) Then offsetx = offsetx - 10 If KeyHit(DownKey) Then offsety = offsety + 10 If KeyHit(UpKey) Then offsety = offsety - 10 Color 0,0,0 Line MouseX(),MouseY(),MouseX()+11,MouseY()+11 Line MouseX(),MouseY(),MouseX(),MouseY()+16 Line MouseX(),MouseY()+16,MouseX()+4,MouseY()+12 Line MouseX()+7,MouseY()+11,MouseX()+11,MouseY()+11 Line MouseX()+4,MouseY()+12,MouseX()+8,MouseY()+20 Line MouseX()+7,MouseY()+12,MouseX()+10,MouseY()+19 Plot MouseX()+9,MouseY()+20 ConfineCursor(150,50,500,500) Flip Cls Wend End Function ConfineCursor(x%,y%,w%,h%) Local r%=(CreateBank(16)) PokeInt(r,0,x%):PokeInt(r,4,y%):PokeInt(r,8,x%+w%):PokeInt(r,12,y%+h%) api_ClipCursor%(r) FreeBank(r) Return(True) End Function .MapData Data "10000011111111111111111000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000001000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000200000000000000000000000000000000000" Data "00000000000002020000000000000000000000000000000000" Data "00000000000020002000000000000000000000000000000000" Data "00000000000002020000000000000000000000000000000000" Data "00000000000000200000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000101000000000000000000" Data "00000000000000000000000000000010000000000000000000" Data "00000000000000000000000000000101000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000001" .MapDatatwo Data "10000011111111111111111000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000001000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000001000000101000000000000000000000000000" Data "00000000000100001000100000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000100000000000010010000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000200000000000000000000000000000000000" Data "00000000000002020000000000000000000000000000000000" Data "00000000000020002000000000000000000000000000000000" Data "00000000000002020000000000000000000000000000000000" Data "00000000000000200000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000101000000000000000000" Data "00000000000000000000000000000010000000000000000000" Data "00000000000000000000000000000101000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000000" Data "00000000000000000000000000000000000000000000000001"
You should not use Escape to read the second map, because it will end the program, use for instance the "Q" key instead.
And y should be reset to zero before reading the second data block:
And y should be reset to zero before reading the second data block:
While Not KeyHit(1) If KeyHit(16) Restore MapDatatwo y=0 For i=0 To Map_Length Read Value$ For x=0 To Map_Length Map(x,y)=Mid(Value$,x+1,1) Next y=y+1 Next EndIf
That was just a typo on the posted code, the problem is the loop below it, when I tyr to change the data that is being read. That is were it gets glitchy.
Maybe I don't understand you correctly, but this is the 2nd loop?
However, maybe it is better to use a different approach: Use a Select..Case statement to switch between the different Restore calls, and put the part that reads the level into a separate Function. Something like:
Then, at the start of the program, call "LoadLevel 1"
Later on (at a keypress o.s.) call "LoadLevel 2"
After looking at it again, I noticed the mouse cursor, which is nice :) But you should use MouseX() and MouseY() only once, because they change all the time. So at the start of the loop, store them into variables and use those variables throughout the loop:
msX = MouseX()
msY = MouseY()
However, maybe it is better to use a different approach: Use a Select..Case statement to switch between the different Restore calls, and put the part that reads the level into a separate Function. Something like:
Function LoadLevel(levelnum) ;select the right restore Select levelnum Case 1 Restore MapData Case 2 Restore MapData2 End Select ;read map data here into Dim For y = 0 to height read ..etc etc .. End Function
Then, at the start of the program, call "LoadLevel 1"
Later on (at a keypress o.s.) call "LoadLevel 2"
After looking at it again, I noticed the mouse cursor, which is nice :) But you should use MouseX() and MouseY() only once, because they change all the time. So at the start of the loop, store them into variables and use those variables throughout the loop:
msX = MouseX()
msY = MouseY()
I had not tried the y=0 suggestion. It works, I just read too fast.
Is there a way to use the restore command on a variable?
Yes, use the Select..Case command
Thanks, I havn't tried that.