Map Array to File on Disk?

This is a discussion on Map Array to File on Disk? within the Game Programming forums, part of the General Programming Boards category; I have been coding a 2D RPG Engine with DirectX 7 for the last while, and all is going well. ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    118

    Map Array to File on Disk?

    I have been coding a 2D RPG Engine with DirectX 7 for the last while, and all is going well. The only problem I have is that I do not want to hard code my 2D map array. I was wondering how it would be possible to have the array read in from a file on disk. This way I could make the map as large as I want. Right now the map array is 100 by 100. That seems a little to large to me. What I want is the map to be much larger than this, but read in at 100 by 100 array size. Is there a problem with having an array this large, and are there any good tutorials you can direct me to that will answer my questions? Thanx in advance.
    "The distinction between past, present and future is only an illussion, even if a stunning one."
    -Albert Einstein

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    The way I see it, you could write in the text file some sort of code, like '1' means wall and '2' means enemy or something like that. Then just use something like this to read.
    Code:
    //Maybe you could create an enumerated type for the array...
    char c;
    ifstream file(map.txt, ios::in);
    i=0, j=0;
    while(c != '\n')
    {
       file.get(c);
       array[i][j] = atoi(c);
       i++;
    }
    //perhaps an outer loop to increase the value of j
    //when you've finished reading a line.
    That's just an idea though. Feel free to change.
    Use something like that to read for the size of the array.
    Not sure what you mean by rading in an array of 100*100 but storing a map much larger. There's a file reading tutorial in www.cplusplus.com
    Hope this answers your questions (or points you in the direction of them).
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 01:44 PM
  3. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 09:32 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21