Vic's QBasic Programming Tutorial Basic Tutorial XX .5 SCROLLING REVISITED ARRRRGHHHH... ----------------------------------------------------------------------------- Do date, I have received 15 E-mails on my last tutor... Heres one (e-mail address not given) (but you know who you are...) A few words edited, but otherwise I have copied it letter for letter... To: Radiohands@aol.com From: ... Subject: You tutor sucks! Message: I h4ve b33n pr0gramming f0r 1 year 4nd h4ve b33n wanting to l3arn how to scr011 s1nce th3 b3ginning. A fri3nd p01nted 0ut you site and said th1er are tut0rs th4t m4y h3lp my c4use. 1 D0wnl0aded the Z1P fil3 containing 4ll 0f Y0u files. TH3Y SUCK!!! Th3y havn't answered a single question I had. I have been waiting for someone to cover fullscreen scrolling my whole life!! I finally had a chance to learn it. I THOUGHT! I didn't understand a single thing you said. So I said forget it!! Shitzu, I skipped all the forking words you said and went straight to the examps. I thought, that maybe if I looked at your forking examples i would figure out what the hork you were talking about. Your examps didn't show nothin but gibberish and many of them didn't werk to begin with. So I read what you said, word for forking word and it still didn't m4ke any s3nce. skr3w y0u 4and your stupid tutors. I bet you th1nk that you 4re a QB forking GOD. Ive l34rned more about QB from my forking DOG! St4rt mak1n more sence in your tutors I will H4ck you forking websight using my 3l337 haxing 4bilities, I can type 100 wps!!!. i hope you go to forking hork and i hope y0u g3t th4t one disease that you get fr0m typing too much!!!!!! 4nd if you know 0f any g00d W4rez sightes on th3 n3t let me know arse-holl!! END MESSAGE: ---- Wow huh? this e-mail in particular left me a bit sad, and more confused than anything First, I'm I supposed to feel scared so I write good tutors, or am I supposed to never touch NotePad again? (and did you notice how he got tired of writing in his 31337 typing style?) but, I allways ask for feedback, and I sent a reply to thank him/her... So, In order to destroy the Computer world, I will continue to write my supposed Half arsed tutors... ONLY IN THE NEW 31337 TYPING STYLE... 4n|) h3r3 w3 g0!!! translation: and here we go because I am an elite haxor!!! ha ha haaaa... ha ha hh, hh... Ok, I guess I'm babbling my gibberish again... --- Ok I'll get serious here... What was I thinking about when I tried to tackle the big subject of FULL-SCREEN SCROLLING? This can be a hard thing to understand... I can't plug my brain into the computer and shove THAT information up your arse... So, the best I can do is shove INFORMATION up your arse... and that is what tutor 20 was about... Getting out the information... Now, Its time to help you understand... Like taking a step out of yourself in order to more better understand yourself and what you are doing... ----- So, to get started... In order to understand scrolling, you must REALLY REALLY understand how bitmaps work... or in other words... How to take information from a map and use it... I taught that in my bitmapping tutor and RPG tutor... MAKE SURE YOU UNDERSTAND THESE BASIC SUBJECTS... they will greatly improve how you program... When I eventually tell you how to get a character on the screen, you must understand How that can be done withought my help... I didn't have help in scrolling... I DID have help on Bitmaps and reading map files... I pieced together the information needed to scroll something... I'm not saying that you have to do that, but it would help if, when I am telling you somethings, you understand where I am comming from... And, if you don't have any Idea where I am comming from you can look it up... so, I will reference my older tutorials when I cover the things that some people might have trouble understanding... HERE WE GO... ----------------------------------------------------------------------------- First, I will once again cover scrolling tile by tile... now, when you read a map file you read it like this... Startpoint ------ Endpoint When to start reading a verticle (verticle means up and down) tile set and when to stop... 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 so, pretend that this is the top line of the map... I want to start here (*) and end (#) here (*) (#) 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 So, since I start at the first value, I want to start at tile #1 and i want to end 7 tiles away wich is tile 8... but, if I wanted to forget the tile 1 ever existed, I would start at tile 2 and go to tile 9... the map printed to the screen will still be a total of 8 tiles long, but tile 1 will not be printed to the screen... it will now go here (*) to here (#) (*) (#) 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 istead of (*) (#) 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 so, now my starting tile is 2 and my ending tile is 9 instead of tiles 1 to 8... if I wanted to forget that tiles 1 & 2 exist, then i would start at tile 3 and end at tile 10... that is the basics of scrolling... the hard part is drawing the map, so if you want to forget 1 and 2 the map drawn to the screen will go from 3 to 10 that is where XSV comes in... This is the starting map value... if you want to read from tiles 1 to 8 then xsv would equall 1 if you want to read from tiles 2 to 9 then xsv would equall 2 if you want to read from tiles 3 to 10 then xsv would equall 3 if you want to read from tiles 4 to 11 then ... I think you get the picture... xsv is where the program will start reading the map to be printed to the screen... so, lets put this together in an example... first, we need a map file... 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 good... to print out the map, we need a starting value... lets put xsv at 1 right now.. that means that the program will start to read the map at 1... now we need a place for the map to stop reading... that is 7 tiles from the beginning... if the beginning is 1 then the ending value will be 8... (thats 7 tiles away from one...) so lets put another value in... XSTV X stop value and we know that the value we want to stop drawing the map is 8 right? so, if we allways want the stop value to be 7 tiles away no matter what number xsv is then we need to set xstv like this xstv = xsv + 7 that means, that no matter how High or low the start value is, the stopping value will be 7 tiles away from that tile... so we have our start value... xsv = 1 and our stopping value xstv = xsv + 7 so, in order to start reading the map at the start value and end at the Stop value you need a FOR LOOP... The for loop tells the program to do this as many times until it equalls this so, if you think about it, we need to start at xsv and end at xstv... so it would go like this for i = xsv to xstv next this will start at i equalling xsv (the starting value) and i will be added by 1 until it equalls xstv ( the stopping value) when i equals the stopping value, the loop will be canclled... now, to draw the tiles to the screen within the FOR LOOP in theory, it would look like this Loop until i goes from xsv to xstv print tile i to the screen next i (i = i + 1, and go back to the beginning of the loop)(unless i = xstv) sound correct? goooood... now, lets put that to work... First, we can't use the map with data statements alone... we need to store them into an array... If you are having trouble understanding arrays then read my tutor on arrays.. here is the map... DATA 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 now lets read the map and store it into an array... first, lets set up the array to be used... DIM map(19) why 19? because, there are 19 numbers in the map... going from the first (13) to the last (11) so we are going to read all the numbers from here (*) to here (#) (*) (#) 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 Now, lets get those numbers into an array... For i = 1 to 19 read map(i) next in this, we set up a loop to go from 1 to 19... we then READ the map file one by one and store them into the correct map place... (read map(i)) so, if we did this... print map(1) this would print out the first number in the map, which is 13... right here (*) (*) 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 if we said print map(12) then it would print the number 44 to the screen... because the 12th number is 44 here (*) (*) 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 and if we said print map(13) the thirteenth number would be printed out... here (*) (*) 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 .... We now have the map into an array, so we don't have to keep rereading the map itself... So, we now need to set up the loop that will print the tiles to the screen... (for the sake of a simpler tutor, I will use Pixels instead of tiles) If you really really think about it, the for loop would look like this... for i = xsv to xstv pset (z,50),map(i) z = z + 1 next you might ask what the z,50 means... z goes up by one each time, and we want each pixel to be one away from each other... so... think about it... the 50 is just a random number... a random y value, wich will not change... and what about the map(i)? that will print a color for the pixel... it reads what current tile its reading and prints the color to the screen... lets put this all together... 'begin example DIM map(19) 'we dim the map array... SCREEN 13 ' We need screen 13 to plot pixels... xsv = 1 ' we are starting at the first tile... xstv = xsv + 7 ' the stop value will be 7 from the first tile 'we now need to store the map into the map array... For i = 1 to 19 read map(i) next 'the above reads the map file in the data statments below... 'Now, lets print this all to the screen for i = xsv to xstv pset (z,50),map(i) z=z+1 next 'Lets now show the computer what the map is using data statments 'that will be read into the array... DATA 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 'END EXAMPLE and thats it... If you change the xsv then the map will be read from that point on... so, lets make an example where xsv will go up when you push a button... first, what I added was a loop so that the program doesn't end until we want it to... 'begin example DIM map(19) 'we dim the map array... SCREEN 13 ' We need screen 13 to plot pixels... xsv = 1 ' we are starting at the first tile... xstv = xsv + 7 ' the stop value will be 7 from the first tile 'we now need to store the map into the map array... FOR i = 1 TO 19 READ map(i) NEXT 'the above reads the map file in the data statments below... 'Now, lets print this all to the screen DO: press$ = INKEY$ FOR i = xsv TO xstv PSET (z, 50), map(i) z = z + 1 NEXT z = 0 IF press$ <> "" THEN xsv = xsv + 1: xstv = xsv + 7 LOOP UNTIL press$ = CHR$(27) END 'Lets now show the computer what the map is using data statments 'that will be read into the array... DATA 13,13,13,14,15,14,13,13,12,12,12,44,55,23,22,22,22,11,11 'END EXAMPLE The most important part in this example is the If press$ <> "" Then xsv = xsv + 1: xstv = xsv + 7 what this does is say... if any key is pressed then change the value of the start value and the finish value... so, whenever you press the spacebar, the map is scrolled... sounds easy... but it may take a few looks to get it... --------- Well, I'm sorry to say, that this is it for this tutor... To keep it short and simple, I will save the Pixel by pixel scrolling tutor next... in the same kind of context... until then... g00db7e f00lz ... 8/8/2000 http://members.aol.com/radiohands