Results 1 to 3 of 3

Thread: Tile Scrolling Questions

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    1

    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.

  2. #2
    Member Yhoko's Avatar
    Join Date
    May 2002
    Posts
    47
    Use binary file access, makes things easier and faster.

    VB Code:
    1. 'Write
    2. Open Filename For Binary As Filenumber
    3.    For i = 0 To UBound(mbytMap, 1)
    4.       For j = 0 To UBound(mbytMap, 2)
    5.          Put Filenumber ,, mbytMap(i, j)
    6.       Next
    7.    Next
    8. Close Filenumber
    9.  
    10. 'Read
    11. Open Filename For Binary As Filenumber
    12.    For i = 0 To UBound(mbytMap, 1)
    13.       For j = 0 To UBound(mbytMap, 2)
    14.          Get Filenumber ,, mbytMap(i, j)
    15.       Next
    16.    Next
    17. 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!
    - Yhoko


    Try my Games
    * [VB6] YDK - Yhoko's Development Kit
    * [VB6] HackV1 - two-player puzzle/strategy
    * [VB6] Xen - extended Gen

  3. #3
    Member Keger's Avatar
    Join Date
    Jun 2001
    Location
    Detroit (Hell)
    Posts
    57
    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
  •  



Click Here to Expand Forum to Full Width