? making and loading a map onto the screen using data arrays (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

making and loading a map onto the screen using data arrays

  • #1 ✎ 425 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies before you start screaming at me, ive looked all over sbs and google and even gamefaqs and found nothing helpful to me. i just want to understand how to use an array variable to represent a bgtile/sprite so i can make a map using data. i also want to know how to load that onto the screen, ive also been trying to figure that out. please help! Posted
  • #2 ✎ 266 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength First, you create your bg texture (Can't remember how to do that, something about scsave?) and load the correct bg layer data file into a blank array (VAR A[0]). Then you BGLOAD the array. I think that's all there is to displaying a bg with BGLOAD, but their might be a little more to it. Another way to make a background with sprites is to SPSET ARR[anynumber] and the proper arguements for that function but that would take sprite "slots". If you type "bg" and press the ? button you can get some useful information on those functions. You can also look at the game manual available at the home screen of the 3ds. Posted
  • #3 ✎ 1061 randomous Owner Robot Hidden Easter Eggs Second Year My account is over 2 years old Website Drawing I like to draw! Hobbies I wouldn't use an array to represent the map. The BG is already an array, and BGCOORD converts all the coordinates (screen, bg pixels, bg tiles) to all the other coordinates. Instead, I would create the BG in a program like the Smile Tool, save all the layers, then load them with BGLOAD. Then when you need to access the map at a particular location, use a combination of BGCOORD and BGGET to figure out the map data at a point. If you're interested, I can come up with some code. The Smile Tool usually saves it as some weird binary format, but you can make it save as regular loadable layers using the file menu in the map editor. Posted
  • #4 ✎ 266 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Right forgot the BGGET part. What's BGCOORD for? Posted
  • #5 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website You can load data from an array into a BG layer using BGLOAD. BGLOAD Layer,X,Y,Width,Height,Array To get the data into the array, the easiest way is to use DATA and COPY: VAR DATAWIDTH=4,DATAHEIGHT=3 DIM ARRAY[DATAHEIGHT,DATAWIDTH] 'create array COPY ARRAY,@TILES 'copy DATA after @TILES into array BGLOAD 0,2,2,DATAWIDTH,DATAHEIGHT,ARRAY 'copy array onto BG layer @TILES DATA 2,1,1,2 DATA 1,0,0,1 DATA 2,1,0,1 Notice that ARRAY is backwards. if your data is 10 tiles wide and 4 tiles height, you make an array with dimensions [4,10]. And to access a tile in the array, you'd do ARRAY[Y,X]. This is just how 2D arrays work in SB. Posted
  • #6 ✎ 425 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Video Games I like to play video games! Hobbies
    You can load data from an array into a BG layer using BGLOAD. BGLOAD Layer,X,Y,Width,Height,Array To get the data into the array, the easiest way is to use DATA and COPY: VAR DATAWIDTH=4,DATAHEIGHT=3 DIM ARRAY[DATAHEIGHT,DATAWIDTH] 'create array COPY ARRAY,@TILES 'copy DATA after @TILES into array BGLOAD 0,2,2,DATAWIDTH,DATAHEIGHT,ARRAY 'copy array onto BG layer @TILES DATA 2,1,1,2 DATA 1,0,0,1 DATA 2,1,0,1 Notice that ARRAY is backwards. if your data is 10 tiles wide and 4 tiles height, you make an array with dimensions [4,10]. And to access a tile in the array, you'd do ARRAY[Y,X]. This is just how 2D arrays work in SB.
    thanks, are the numbers in the DATA just defining the bg tile number, or is it the map itself? if its the definition number, then it helps ALOT, otherwise, i dont really understand how to define. but thanks!
    Posted
  • #7 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website It's the bg tile number (Which you can check using the smile tool) You can also add #BGROT90, #BGROT180, or #BGROT270 to the tile number to change the rotation of the tile, and #BGREVV or #BGREVH to mirror it. Posted Edited by 12Me21
  • #8 ✎ 60 seggiepants You may want to have a look at the code for Find the Exit http://smilebasicsource.com/page?pid=820, it defines levels with data statements, which sounds about like what you are looking for. I do have code to load a binary level file somewhere if you need that instead (let me know). Unfortunately the level editor in smile tool is limited to 64x64 tile worlds only which is a shame. Anyway, you want to do things in roughly this order.
    1. Clear out any old junk, and set the screen mode (ACLS, XSCREEN)
    2. Load custom graphics if you have them (sprites/bg tiles)
    3. Resize the background for each layer you use using (BGSCREEN)
    4. Read in data (READ/DATA or LOAD) and write out bg tiles using BGPUT x, y, tile_number for each tile x, y coordinate on each layer you are using (tiles are 16x16 by default, but the tile map is measured in tiles not pixels)
    5. If the layers are larger than the screen position them using BGOFS.
    6. Use BGGET to figure out which tile is what on screen so you can do physics for the game and interact with the world. (Unless it is just a do nothing background)
    Hope that helps!
    Posted