Results 1 to 7 of 7

Thread: Storing Maps ... Simple Question

  1. #1

    Thread Starter
    Member Keger's Avatar
    Join Date
    Jun 2001
    Location
    Detroit (Hell)
    Posts
    57

    Storing Maps ... Simple Question

    I am planning on storing game maps to a text file. Each
    of my hexes has a value (1024 possible for each) .
    So, the map will have a height and width in hexes and
    then I will read the map array one value at a time to
    the text file.

    There will be any number of maps available with different
    sizes. The player can choose, edit or create them.

    How do you guys go about this?

    Thanks

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Easiest as well as most efficient way to go is to store the maps binary as a single type,ex:
    Code:
    Type mapfile
      map() as mapdata
    end type
    Type mapdata
      data() as integer
    End type
    ...
    dim data as mapfile
    ...
    put#1,,data
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Member Keger's Avatar
    Join Date
    Jun 2001
    Location
    Detroit (Hell)
    Posts
    57
    Thanks kedaman

    I was trying to do that earlier but was failing miserably.
    I need to get the hang of random file access.
    Anyway, I'll figure it out. Just need to find a few more
    examples. How come its only the simple things that
    beat me up?

    Thanks again
    Its good to know what the proes do.

  4. #4
    Member
    Join Date
    Jul 2001
    Location
    Minneapolis, MN USA
    Posts
    32
    Keger ... Look up info on "Binary Files", not "Random Access" ...

    In its most basic form, you open one for writing like this:
    Code:
    Dim FileNum as Integer
    FileNum = FreeFile
    Open "myfile.dat" for Binary Access Write as #FileNum
    There's info in the VB help file about how to lock the file as well as other options.

    Then, to write data to the file, you simply use
    Code:
    Put #FileNum,  1, Data
    That number (1, in the above example) is what byte of the file to start writing ... The nice thing about it is that you can write entire arrays of whatever type you wish with a single statement.

    Then, to read the file open it with "Access Read" and use Get # to retrieve things ...

    Hope that gets you started.

    -Bryk

  5. #5

    Thread Starter
    Member Keger's Avatar
    Join Date
    Jun 2001
    Location
    Detroit (Hell)
    Posts
    57
    Thanks Brykovian

    You would have thought that I could figure that out .

    Ok...
    So you said something about arrays
    can I put a whole array in, in one shot or ????

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You can put an array in one shot, but the dimensions won't store, unless you do it manually. As I suggested carefully planning a tree of UDT's as a header for the file contents, you can put the whole UDT in one shot without any fuss about other datatypes.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Member Keger's Avatar
    Join Date
    Jun 2001
    Location
    Detroit (Hell)
    Posts
    57
    Thanks
    I got it !
    Everything works ! ! !


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