|
-
Jul 1st, 2002, 11:09 PM
#1
Thread Starter
New Member
Tile Scrolling Questions
Ok, if any of you are familiar with Lucky's Tile Scrolling Tutorial, this will probably be fairly easy for you to awnser.
In the coding there is this part that generates a large, random map:
'Load the map array with random tiles
Randomize
For i = 0 To UBound(mbytMap, 1)
For j = 0 To UBound(mbytMap, 2)
mbytMap(i, j) = CByte(Rnd() * 3)
Next j
Next i
How can I edit this block of coding to instead load map data from a *.txt file with map data? IE, something like:
001G5
08392
589K6
3RD79
You dont have to give exact coding, just the theory on how to do it. Ive done a map loading function before that loaded map data into a game, but it doesnt apply here since I did it way too different than what I think this system can allow.
-
Jul 2nd, 2002, 12:40 AM
#2
Member
Use binary file access, makes things easier and faster.
VB Code:
'Write
Open Filename For Binary As Filenumber
For i = 0 To UBound(mbytMap, 1)
For j = 0 To UBound(mbytMap, 2)
Put Filenumber ,, mbytMap(i, j)
Next
Next
Close Filenumber
'Read
Open Filename For Binary As Filenumber
For i = 0 To UBound(mbytMap, 1)
For j = 0 To UBound(mbytMap, 2)
Get Filenumber ,, mbytMap(i, j)
Next
Next
Close Filenumber
I also recommend you to save the map dimensions just before the map data (so you have no fixed size). Note that you'll have to ReDim the map array before reading the data!
-
Jul 2nd, 2002, 02:34 PM
#3
Member
I Agree with Yhoko Binary works better
I think stepping through a text file would be very very slow...
Here is another tutorial that may help, they do it your way...
http://www.vbexplorer.com/VBExplorer/game_tutorials.asp
There is also the famous Fox tutorial.... he posts a link regularly.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Code:
'Place in a module
Type datafile
mapColumns As Integer
mapRows As Integer
mapdata() As Integer
End Type
Code:
'Place code where needed
Dim intfree As integer
Dim xcount As integer
Dim ycount As Integer
Dim maps As datafile
Dim tiles(1 to 2,1 to 2) as integer
intfree = FreeFile
'Go to file directory and get the file
Open App.Path & "\maps\" & "default.dat" For Binary Access Read
As #intfreee
'Open file
Get #intfree, , maps 'Class for storing and opening binary map files
'Number of rows and columns
ycount = maps.mapRows
xcount = maps.mapColumns
'Erase tiles
ReDim tiles(xcount, ycount) 'Array starts at zero
tiles() = maps.mapdata
'clean up
Close intfreee
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|