LoginLogin

Make maps with DATA!

Root / Submissions / [.]

the_squat1115Created:
Hi, guys. I know some people had asked a lot about draw maps WITH DATA. If you want to do that, well, YOU are in the right place! Let's get started! First, you'll need to put some arrays. Think like this.
DIM BGTABLE[5]'Depending on the number of tiles you want, you will need to put the exact number as the number of tiles you have, but you will need to jump 1 number, otherwise will cause a type mismatch.
And we'll need the MAP$ variable. Why? Here is shown.
DIM MAP$[6]'You will want to put this, because it stores the number of DATA arrays you want.
Then, the AMAZING part is coming out.
FOR I=0 TO LEN(BGTABLE)
 READ BGTABLE[I]
NEXT
For what use is this? It reads the tiles you have asignned to your map.
FOR I=0 TO LEN(MAP$)
 READ MAP$[I]
NEXT
And this is for reading the complete map. The complex part is coming out. Get ready! Finally... To render the map, we will use this code:
DEF MAPRENDER
 FOR I#=0 TO LEN(MAP$)-1
  FOR J#=0 TO LEN(MAP$[I#])-1
   BGPUT 0,J#,I#,BGTABLE[(ASC(MID$(MAP$[I#],J#,1)))-48]
  NEXT
 NEXT
END
This is used to recompile the ASCII map and translate them to BG tiles. And, as the (pre-)final step, we will write the custom functions after we made the scripts.
MAPREAD [number of the map to read]
MAPRENDER
Now, you will want to make your ASCII map, now, how the format is used?
@MAP_0X'Label of the map to read and translate. NOTE: the โ€œXโ€ shown is a number of the map to use.
DATA X'The โ€Xโ€ is for the BG definition number to use. EXAMPLE: DATA 9'1
DATA "XXXXXXXXXXXXXXX"'Same as the DATA number to use. Read example above.
I actually donโ€™t know if you (the reader) understood what I wanted to mean on the example above. Credit to rando!

umm ok thas cool

Thank you for this base, the_squat1115! Maybe I'll be able to revise this so you could have massive maps beyond the 128x127 restriction. I'd need this for my jump'n'run game so I can make massive levels. โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” There is a mistake I saw however but I don't blame you as I do this mistake over and over again lol. This would result in Subscript out of range errors because these FOR instructions count beyond the length of the arrays. You need to append -1 to the LEN functions so no crashes will occur. EDIT: My sentence structure goes wring sometimes...

Replying to:CyberYoshi64
Thank you for this base, the_squat1115! Maybe I'll be able to revise this so you could have massive maps beyond the 128x127 restriction. I'd need this for my jump'n'run game so I can make massive levels. โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” There is a mistake I saw however but I don't blame you as I do this mistake over and over again lol. This would result in Subscript out of range errors because these FOR instructions count beyond the length of the arrays. You need to append -1 to the LEN functions so no crashes will occur. EDIT: My sentence structure goes wring sometimes...
yeah, like
FOR I=0 TO LEN(BGTABLE)-1
 READ BGTABLE[I]
NEXT

Please note: Smilebasic create up to 3 different DATA-typ before the Code is execute (like Variable $,%,#). If you type first time %-Values and second time $-values, you only can read this by typing the READ - code(s) in the same order or you get a Error. Of course you have to set the value of DATA after DIM and before you try to read. (Dont forget the Value-limits of $ and % typ )

Replying to:S_DE_Solutions
Please note: Smilebasic create up to 3 different DATA-typ before the Code is execute (like Variable $,%,#). If you type first time %-Values and second time $-values, you only can read this by typing the READ - code(s) in the same order or you get a Error. Of course you have to set the value of DATA after DIM and before you try to read. (Dont forget the Value-limits of $ and % typ )
yes

You can copy DATA to arrays using COPY, with the caveat that if the numbers of elements don't match, it will throw an error. DIM BGTABLE[5] COPY @BGTABLE, BGTABLE END @BGTABLE DATA 1,2,3,4,5

Replying to:hakke
You can copy DATA to arrays using COPY, with the caveat that if the numbers of elements don't match, it will throw an error. DIM BGTABLE[5] COPY @BGTABLE, BGTABLE END @BGTABLE DATA 1,2,3,4,5
Nice

Replying to:hakke
You can copy DATA to arrays using COPY, with the caveat that if the numbers of elements don't match, it will throw an error. DIM BGTABLE[5] COPY @BGTABLE, BGTABLE END @BGTABLE DATA 1,2,3,4,5
Something worth noting, even if resource is old: 1. I messed up. It's COPY BGTABLE, @BGTABLE 2. You can get away with the caveat by doing something like this:
RESTORE @DATA
READ ASIZE
DIM A[ASIZE]
COPY A,@DATA
@DATA
DATA 3
DATA 1,2,3
3. This obviously won't work with 2D arrays. So you can either use a 1D array and index it linearly like [X,Y]โ†’[X+Y*DIM_Y], or implement your own 2D array reading routine.

Replying to:hakke
You can copy DATA to arrays using COPY, with the caveat that if the numbers of elements don't match, it will throw an error. DIM BGTABLE[5] COPY @BGTABLE, BGTABLE END @BGTABLE DATA 1,2,3,4,5
[N3NJP3H3] Here's what I said in the comment above but in code and working.

Replying to:hakke
You can copy DATA to arrays using COPY, with the caveat that if the numbers of elements don't match, it will throw an error. DIM BGTABLE[5] COPY @BGTABLE, BGTABLE END @BGTABLE DATA 1,2,3,4,5
Yeah basically my problem with that method is that it's a bit harder to visually see the map in the code, with all of the commas, but that's just a theory me. I like the string array method the most, out of the methods I know. Just my opinion. Anyway yeah, that works.

is it possible to do a map border? like if you hit a wall of the map you can not continue walking?

Replying to:Sebu_programs
is it possible to do a map border? like if you hit a wall of the map you can not continue walking?
For that, you need another algorithm. This is trying to load maps, youโ€™re trying to interact with them. I previously asked about walking into walls, and seggiepants recommended a video. It helped me a ton, but I donโ€™t know your skill level or anything so Iโ€™ll just say that you should make sure you know the basics first. I recommend reading through randomousโ€™s tutorials here: http://old.smilebasicsource.com/page?pid=402 For the video about collision, this is the link: https://m.youtube.com/watch?feature=youtu.be&v=8JJ-4JgR7Dg