Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: level loading

  1. #11

    level loading

    Well isn't that nice... I have solved half of my problem. The map is now loading. I just had to mingle with my array sizes and now it's working. But one problem is still folowing me... The map is not displayed correctly - many of the tiles are not bu the text file. that is still a mystery.

  2. #12

    level loading

    One problem is that your creating an array of 0..32, 0..24 and then in the lower loops accessing it as 0 to 25 and 0 to 32. Make sure that your indexing it properly or that you have sized it properly. I'm guessing that your indexing should be 0 to 24.

    You also index it as 0 to 31 (top loop).

    All of this combined will give you crazy results. Instead try using constants and making sure that your indexing to value-1.

    Now, as for your read char by char. Ditch that and go with a block read as your array is in order. So it goes from:[pascal]Stream:=tfilestream.Create(mapfile, fmopenread);

    try
    try
    for y:=0 to 24 do
    begin
    for x := 0 to 31 do
    begin
    stream.ReadBuffer(C, SizeOf(C));
    tempbuffer[x][y]:=c;

    end;
    end;
    except on e:exception do
    messagedlg(e.Message, mterror, [mbok], 0);
    end;
    finally
    stream.free;
    end;[/pascal]

    to:[pascal]Stream:=tfilestream.Create(mapfile, fmopenread);
    try
    try
    if stream.size <> COLS* ROWS then
    raise exception.CreateFmt('Data file "%s" size incorrect!', [MapFile]);
    stream.ReadBuffer(@tempbuffer[0][0], 25*32);
    except on e:exception do
    messagedlg(e.Message, mterror, [mbok], 0);
    end;
    finally
    stream.free;
    end;[/pascal]

    A final re-work of your entire source could be (This only works if there are no line breaks in the file):[pascal]const
    COLS = 25;
    ROWS = 24;

    procedure form22.SetupMap(MapFile:string);
    var
    Stream:TFilestream;
    C : Char;
    x, y : Word;
    tempbuffer : array[ 0..COLS-1, 0..ROWS-1 ] of Char;
    begin
    Stream:=tfilestream.Create(mapfile, fmopenread);
    try
    try
    if stream.size <> COLS* ROWS then
    raise exception.CreateFmt('Data file "%s" size incorrect!', [MapFile]);
    Stream.ReadBuffer(tempbuffer[0, 0], COLS*ROWS);
    except on e:exception do
    messagedlg(e.Message, mterror, [mbok], 0);
    end;
    finally
    Stream.free
    end;

    for y := 0 to ROWS-1 do
    for x := 0 to COLS-1 do
    case tempbuffer[x][y] of
    '0' : map[x][y].Tile:=0; //grass
    '1' : map[x][y].Tile:=1; //path
    '2' : map[x][y].Tile:=2; //Water
    end;
    end;[/pascal]

    BTW: For the love of god will you name your forms and use some spacing .

  3. #13

    level loading

    Well, I used your piece of code to load my maps, but strangely, I get all the same messed up map as before. Oh, and my file has to be just a one long line of chars, right?

  4. #14

    level loading

    Yes, it needs to be one long line of chars, no line breaks in it at all.

    Can you post up a zip file containing a simple sample application that shows the problem? That would make this much easier to try and debug, simply make it a single form that calls the loading method and then draws the map to a TImage (once). This way we can quickly look and see what you may or may not be doing wrong

  5. #15

    level loading

    Ah hell, I'll just post my whole project because I'm to lazy to create another project
    Here's the link to my problem:
    http://rapidshare.com/files/34477479...te_project.exe

    Cheers, leniz[/url]

  6. #16

    level loading

    Why not using ini files anyway?
    &quot;What we cannot speak about we must pass over in silence.&quot;

  7. #17

    level loading

    My bad, small typo on my behalf:[pascal]procedure TForm1.SetupMap(mapfile: AnsiString);
    var stream:TFilestream;
    C : Char;
    x, y : Word;
    tempbuffer : array[ 0..Rows-1, 0..Cols-1] of Char; // Typo was here
    begin
    Stream:=tfilestream.Create(mapfile, fmopenread);
    try
    try
    if stream.size <> cols* rows then
    raise exception.CreateFmt('Data file "%s" size incorrect!', [MapFile]);
    Stream.ReadBuffer(tempbuffer[0, 0], cols*rows);
    except on e:exception do
    messagedlg(e.Message, mterror, [mbok], 0);
    end;
    finally
    Stream.free
    end;


    for y := 0 to rows - 1 do
    for x := 0 to cols - 1 do
    case tempbuffer[y, x] of
    '0' : map[x][y].Tile:=0; //grass
    '1' : map[x][y].Tile:=1; //path
    '2' : map[x][y].Tile:=2; //Water
    end;
    end;[/pascal]

    Download a running example here: http://www.eonclash.com/PGD/leniz.zip

  8. #18

    level loading

    YES!! Oh what joy it is to see a fully functional map now comes the hardest part for me: combat mode developing and iteM creation. Oh well, wish me luck

  9. #19

    level loading

    Good luck.

    Before you go that far, might I suggest that you expand your mapping system a bit. Also when you get into combat and other try looking at a scripting language for support. They can be really helpful and make debugging/quick mods very fast. The final advantage is that its easy to convert a script file into raw source if you find you have a need .

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •