Qbasicnews.com

Full Version: Map loading from files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
My SUB to load map files is this:
Code:
SUB loadmap (filename$)
IF LEN(filename$) > 0 THEN
  OPEN filename$ FOR INPUT AS #1
  FOR y = 1 TO 25
   FOR x = 1 TO 40
    INPUT #1, tile
    map(x, y) = tile
   NEXT
  NEXT
  CLOSE #1
END IF
END SUB
Where the format of the map files is:
1,1,1
1,2,3
3,7,3
etc. etc., with comma-seperated values across, 25 down (I'm using SCREEN 13, 40x25).
And my SUB that prints the map:
Code:
SUB setscreen
FOR y = 1 TO 25
  FOR x = 1 TO 40
   IF x = 40 THEN
    PRINT CHR$(177)
    ELSE
     IF map(x, y) = blank THEN PRINT " ";
     IF map(x, y) = tile THEN PRINT CHR$(177);
     IF map(x, y) = smiley THEN PRINT CHR$(1);
     IF map(x, y) = enemy THEN PRINT "*";
     IF map(x, y) = points THEN PRINT "$";
     IF map(x, y) = endlevel THEN PRINT "#";
   END IF
  NEXT
NEXT
END SUB
Alright, and I declared a SHARED map(1 TO 40, 1 TO 25), adn the blank, tile, smiley, etc. are CONSTS.
The problem is, when I run the program, it doesn't print exactly what the map says...Most of it is OK, but there is a streak of blanks diagonally where in the file it's almost completely tiles (CHR$(177)s), and some things are out of place, like some of the "$"s are where they shouldn't be.
I suspect that the problem lies within the loadmap SUB, but I can't see a problem.
Any ideas?
maybe tile and blank variables have the same value? Smile
yea i think the blank = tile... did you share them?
Nope - CONST blank=0 and CONST tile=1.
I'll post the whole program, if you need.
Quote:Nope - CONST blank=0 and CONST tile=1.
I'll post the whole program, if you need.
ah, ok i get it. well maybe you should post it. becuase i have no clue whats wrong

edit: the way you are loading your map is making me think about how i load mine. it's currently unreadable. i need to change that.
edit2: hehe, nevermind, it's a lot like yours but i combined the sub of loading them and the sub of print them to the screen
I'll post my code soon...but I think this might be the problem:
There are newlines all over the file. I don't print the map all on one line, I print one row, then enter, then another, then enter...Will INPUT #1 get confused from that?
i use LINE INPUT when getting the input stuff
LINE INPUT is for strings, though, right?
i think. try turning the const to strings and input them thjat way

how i load my map...
Code:
FOR mapposy = 1 TO 18
LINE INPUT #1, line1$
FOR mapposx = 1 TO 38
LOCATE mapposy + 1, mapposx + 1
curmap$(mapposx, mapposy) = MID$(line1$, mapposx, 1)
SELECT CASE MID$(line1$, mapposx, 1)
CASE "b": COLOR 0: PRINT CHR$(219)
CASE "w": COLOR 1: PRINT CHR$(219)
CASE "g": COLOR 2: PRINT CHR$(219)
CASE "W": COLOR 8: PRINT CHR$(219)
CASE "d": COLOR 6: PRINT CHR$(219)
CASE "f": COLOR 7: PRINT CHR$(219)
CASE "v": COLOR 14, 7, 7: PRINT CHR$(2)
CASE "t": COLOR 10, 2, 2: PRINT CHR$(5)
CASE "1": COLOR 15: PRINT label$(1): mapposx = mapposx + LEN(label$(1)) - 1
CASE "2": COLOR 15: PRINT label$(2): mapposx = mapposx + LEN(label$(2)) - 1
CASE "3": COLOR 15: PRINT label$(3): mapposx = mapposx + LEN(label$(3)) - 1
END SELECT

NEXT mapposx
NEXT mapposy
Hmm, I'll try modding my map loader like that.
Pages: 1 2