Vic's QBasic Programming Tutorial Basic Tutorial XX!! SCROLLING!! I'm tired of making 100's of map files!!! Why can't I just combine them into one? ----------------------------------------------------------------------------- The moment many of you have been waiting for... One thing I want to explain before I get into programming... Although QBasic and its original commands can be set up to do scrolling, Using a library (this one will use DQB) will greatly improve the games speed and quality... so, what you will need for this tutor is... 1.) qbasic 4.5 2.) the DQB library (read my tutor #19) 3.) this tutor... NOTE: if any of you have ever had trouble getting DQB to work, or had had a hard time finding qb 4.5 read my last tutor... Since Reading others programs and learning from them is hard work, I have come up with my own scrolling type engine... from my own brain... so... My way is not the fastest/easiest scrolling engine, but it gets the job done... ---------- So, first... Before I go into PIXEL BY PIXEL srolling (toward the end of this tutor) I must explain basic scrolling from a map file... This will scroll tiles (not pixel by pixel) this will be chunky scrolling, but it will explain the basics... For right now, You will not need Direct QB... Just your own version of QBASIC (1.1 if you want even!!) First, we have to get some tiles... I will do it the OLD Fashioned way by using DATA statements.. If you read my First RPG tutor, you should get the IDEA... (and I will use those tiles...) heres the data we will be using... (I copied these from the RPG Tutor #10... 'This sprite is for grass... It contains two shades of green DATA 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,02,10,10,10,10 DATA 10,10,10,02,10,10,10,02,10,10,02,10,10,10,10 DATA 10,10,10,10,02,10,02,10,10,10,10,10,10,10,10 DATA 02,10,10,10,02,10,02,10,10,10,02,10,10,10,10 DATA 10,02,10,10,02,10,02,10,10,02,10,10,02,10,10 DATA 10,10,02,02,10,02,10,10,10,02,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,02,10,02,10,10,10 DATA 02,02,10,10,02,10,10,10,02,02,02,10,10,10,10 DATA 10,10,02,02,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,02,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,10,10,10,10,10,10,10,10 'This (considering its the north pole) will be the snow... DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,29,29,29,15,15,15,15,15,15,15,15,15 DATA 15,15,29,07,07,07,15,15,15,29,29,15,15,15,15 DATA 15,15,29,07,15,15,15,15,29,07,07,15,15,15,15 DATA 15,29,07,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,29,15,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,15,29,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,29,07,07,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,29,07,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,29,07,07,07,29 DATA 15,15,15,15,15,15,15,15,15,15,15,29,29,29,15 'For the third, floor tiles... DATA 07,08,08,08,08,08,08,08,08,08,08,08,08,08,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,00,00,00,00,00,00,00,00,00,00,00,00,00,07 '--- Ok thats done... lets make a map ( 21 x 15 ) 'HERE IS THE MAP! labled MAP1.. DATA 3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3 DATA 3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,3,3 DATA 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,3 DATA 3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,2,3 DATA 2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,2 DATA 2,2,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,2 DATA 2,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2 DATA 3,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,2,3 DATA 3,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,2,3 DATA 3,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3 DATA 3,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3 DATA 3,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,3,3 DATA 3,3,3,3,3,3,3,2,2,2,1,1,1,1,1,3,3,3,3,3,3 Ok theres the data we will be using... But, if you notice, the map above only fits the screen... (21x15) so, lets make the map a bit longer... DATA 3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 DATA 3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 DATA 2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,1,2,2,1,2,2,2,2,3,3 DATA 2,2,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,2,1,1,2,2,2,2,2,3,3 DATA 2,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,1,1,2,2,3,2,2,3,3 DATA 3,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,2,3,2,2,2,3,1,3,2,3,3 DATA 3,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,3,2,2,3,3 DATA 3,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,3,3,2,2,2,2,2,2,2,3,3 DATA 3,3,3,3,3,3,3,2,2,2,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 There, The map is now 30 x 15... Now lets get all the sprites... DIM sprite1(50), sprite2(50), sprite3(50) DIM map1(30, 15) 'NOTE THAT THE MAP IS NOW 30 X 15 (NOT 21 X 15) SCREEN 13 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite1 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite2 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite3 'THIS IS THE MAP... 30 X 15 (REMEMBER?) FOR y = 1 TO 15: FOR x = 1 TO 30: READ map1(x, y): NEXT: NEXT '*****|***** this doesnt do anything, just for a reference point... CLS 'THIS DRAWS THE MAP... 'EVEN THOUGH THE MAP IS 30 X 15, YOU CAN 'ONLY FIT 21 X 15 ON THE SCREEN... FOR y = 1 TO 15 FOR x = 1 TO 21 IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3 NEXT: NEXT DATA 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,02,10,10,10,10 DATA 10,10,10,02,10,10,10,02,10,10,02,10,10,10,10 DATA 10,10,10,10,02,10,02,10,10,10,10,10,10,10,10 DATA 02,10,10,10,02,10,02,10,10,10,02,10,10,10,10 DATA 10,02,10,10,02,10,02,10,10,02,10,10,02,10,10 DATA 10,10,02,02,10,02,10,10,10,02,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,02,10,02,10,10,10 DATA 02,02,10,10,02,10,10,10,02,02,02,10,10,10,10 DATA 10,10,02,02,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,02,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,10,10,10,10,10,10,10,10 'This (considering its the north pole) will be the snow... DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,29,29,29,15,15,15,15,15,15,15,15,15 DATA 15,15,29,07,07,07,15,15,15,29,29,15,15,15,15 DATA 15,15,29,07,15,15,15,15,29,07,07,15,15,15,15 DATA 15,29,07,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,29,15,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,15,29,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,29,07,07,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,29,07,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,29,07,07,07,29 DATA 15,15,15,15,15,15,15,15,15,15,15,29,29,29,15 'For the third, floor tiles... DATA 07,08,08,08,08,08,08,08,08,08,08,08,08,08,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,00,00,00,00,00,00,00,00,00,00,00,00,00,07 'The map file... 30 x 15 now... DATA 3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 DATA 3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 DATA 2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,1,2,2,1,2,2,2,2,3,3 DATA 2,2,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,2,1,1,2,2,2,2,2,3,3 DATA 2,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,1,1,2,2,3,2,2,3,3 DATA 3,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,2,3,2,2,2,3,1,3,2,3,3 DATA 3,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,3,2,2,3,3 DATA 3,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,3,3,2,2,2,2,2,2,2,3,3 DATA 3,3,3,3,3,3,3,2,2,2,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 Ok, now we can print up the map in qb... But, how do we get this to scroll¿ its pretty easy... naturally, when the map is read and printed to the screen, it starts at the number 1 (the x value)... if it started at #2 x value and stayed a 2 everytime you go to a new X row,,, everything would be printed 1 off and would stop 1 off... it used to go from here to here... * * 3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2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,1,1,1,1,2,2,2,2,1,1,2,2,3,2,2,3,3 3,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,2,3,2,2,2,3,1,3,2,3,3 3,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,3,2,2,3,3 3,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 3,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 3,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,3,3,2,2,2,2,2,2,2,3,3 3,3,3,3,3,3,3,2,2,2,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 everything else is ignored... Do you understand? I hope so... ------- Now how would we apply this? easy... We need a new variable... This variable will be called The X START VALUE I will shorten this to XSV This is where on the map X will start drawing the map... Now, we have to make sure that when the map is drawn, it is drawn from the x start value... So, lets look at the code that draws the map... FOR y = 1 TO 15 FOR x = 1 TO 21 IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3 NEXT: NEXT If we want the map to draw from a predetermined X start value... we have to tell it what that will start from... so... xsv = 1 This will tell it to start at the first tile in the x line... this will tell it to read the tiles from 1 to 21... if xsv = 2... then it would read tiles from 2 to 22... tile 5? xsv = 5 reads from tiles 5 to 25... Get it? --- Now we have to edit the draw map routine to use this information... FOR y = 1 TO 15 FOR x = 1 TO 21 IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3 NEXT: NEXT The first thing we must change is the FOR y = 1 TO 15 FOR x = 1 TO 21 since we are only scrolling left to right, the y value will allways be the same... since we want x to start at the xsv we start of by changing it like this... FOR y = 1 TO 15 FOR x = xsv TO ... Now, if you think about it... If it started at tile 5 and went to 21 the map would be very short... So, we have to change the xsv to XXX part... What would that value be? xsv + 21 right? NO!!!! since the lowest XSV can get is 1... and not 0 you have to subtract that one... so, it would look like this... xsv to xsv + 20 everytime the xsv value changes, it will change both automatically!! So, the new FOR y = 1 TO 15 FOR x = 1 TO 21 will look like this... FOR y = 1 TO 15 FOR x = xsv TO xsv + 20 DONE!!! And, you might think that that would fix everything... but it won't we have to edit the part where the tiles are put down... IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3 because each x value is different the farther you go down the line... so x value two won't be 15... it will be 30!! so you would draw it at 15 instead of 1!!! and if that is done, the tiles toward the end of the map will be drawn off screen and an error will show... So, if you want to draw the sprites on the screen in a new location, one that is lower... you have to subtract that value until it is 1 do you notice this...? IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3 PUT (x * 15 - 15, that part tells the tile to be put at 1... but if that value is 30... it will be put at 15! how would we fix it so that 30 is subtracted to 1 and 45 is made 1 when xsv is equal to 3? easy if you think about it... instead of PUT (x * 15 - 15, PUT (x * 15 - xsv * 15 instead of subtracting 15, you subtract the tile value * 15... so, it is now equall to 1 no matter what the value is!!! thats it... do you understand??? This can seem very complicated, but the information is all there.. It is just a matter of getting used to the information being given out... --- so all together it will now look like this... FOR y = 1 TO 15 FOR x = xsv TO xsv + 20 IF map1(x, y) = 1 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite3 NEXT: NEXT HA HA HA HAAA!!! thats it... whatever value xsv is equall to, the map will be drawn!!!! lets put this all together!!!!! DIM sprite1(50), sprite2(50), sprite3(50) DIM map1(30, 15) 'NOTE THAT THE MAP IS NOW 30 X 15 (NOT 21 X 15) SCREEN 13 xsv = 1 'HERES THE XSV VALUE!!! CHANGE IT AND SEE WHAT HAPPENS FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite1 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite2 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite3 'THIS IS THE MAP... 30 X 15 (REMEMBER?) FOR y = 1 TO 15: FOR x = 1 TO 30: READ map1(x, y): NEXT: NEXT '*****|***** this doesnt do anything, just for a reference point... CLS 'THIS DRAWS THE MAP... 'EVEN THOUGH THE MAP IS 30 X 15, YOU CAN 'ONLY FIT 21 X 15 ON THE SCREEN... FOR y = 1 TO 15 FOR x = xsv TO xsv + 20 IF map1(x, y) = 1 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite3 NEXT: NEXT DATA 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,02,10,10,10,10 DATA 10,10,10,02,10,10,10,02,10,10,02,10,10,10,10 DATA 10,10,10,10,02,10,02,10,10,10,10,10,10,10,10 DATA 02,10,10,10,02,10,02,10,10,10,02,10,10,10,10 DATA 10,02,10,10,02,10,02,10,10,02,10,10,02,10,10 DATA 10,10,02,02,10,02,10,10,10,02,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,02,10,02,10,10,10 DATA 02,02,10,10,02,10,10,10,02,02,02,10,10,10,10 DATA 10,10,02,02,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,02,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,10,10,10,10,10,10,10,10 'This (considering its the north pole) will be the snow... DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,29,29,29,15,15,15,15,15,15,15,15,15 DATA 15,15,29,07,07,07,15,15,15,29,29,15,15,15,15 DATA 15,15,29,07,15,15,15,15,29,07,07,15,15,15,15 DATA 15,29,07,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,29,15,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,15,29,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,29,07,07,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,29,07,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,29,07,07,07,29 DATA 15,15,15,15,15,15,15,15,15,15,15,29,29,29,15 'For the third, floor tiles... DATA 07,08,08,08,08,08,08,08,08,08,08,08,08,08,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07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,2,3,3 DATA 3,3,3,3,3,3,3,2,2,2,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 ......... Now, if you change the XSV value declared at the beginning, you can see what happens... Now, lets make it so you can see it in action... In this program, you press the SPACE BAR to scroll the screen... DIM sprite1(50), sprite2(50), sprite3(50) DIM map1(30, 15) 'NOTE THAT THE MAP IS NOW 30 X 15 (NOT 21 X 15) SCREEN 13 xsv = 1 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite1 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite2 FOR y = 1 TO 13: FOR x = 1 TO 15: READ clr: PSET (x, y), clr: NEXT: NEXT GET (1, 1)-(15, 13), sprite3 'THIS IS THE MAP... 30 X 15 (REMEMBER?) FOR y = 1 TO 15: FOR x = 1 TO 30: READ map1(x, y): NEXT: NEXT '*****|***** this doesnt do anything, just for a reference point... CLS 'THIS DRAWS THE MAP... 'EVEN THOUGH THE MAP IS 30 X 15, YOU CAN 'ONLY FIT 21 X 15 ON THE SCREEN... FOR y = 1 TO 15 FOR x = xsv TO xsv + 20 IF map1(x, y) = 1 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite3 NEXT: NEXT '********** '********** 'this is the beginning of the loop 'if you press the space bar, the xsv value goes up by one and 'the map is redrawn DO: press$ = INKEY$ 'if the space bar is pressed... IF press$ = " " THEN xsv = xsv + 1 'clear the screen and REDRAW the map... CLS FOR y = 1 TO 15 FOR x = xsv TO xsv + 20 IF map1(x, y) = 1 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite2 IF map1(x, y) = 3 THEN PUT (x * 15 - xsv * 15, y * 13 - 13), sprite3 NEXT: NEXT 'end the if... huh huh... END IF LOOP UNTIL press$ = CHR$(27) DATA 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,02,10,10,10,10 DATA 10,10,10,02,10,10,10,02,10,10,02,10,10,10,10 DATA 10,10,10,10,02,10,02,10,10,10,10,10,10,10,10 DATA 02,10,10,10,02,10,02,10,10,10,02,10,10,10,10 DATA 10,02,10,10,02,10,02,10,10,02,10,10,02,10,10 DATA 10,10,02,02,10,02,10,10,10,02,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,02,10,02,10,10,10 DATA 02,02,10,10,02,10,10,10,02,02,02,10,10,10,10 DATA 10,10,02,02,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,02,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,10,10,10,10,10,10,10,10 'This (considering its the north pole) will be the snow... DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,29,29,29,15,15,15,15,15,15,15,15,15 DATA 15,15,29,07,07,07,15,15,15,29,29,15,15,15,15 DATA 15,15,29,07,15,15,15,15,29,07,07,15,15,15,15 DATA 15,29,07,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,29,15,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,15,29,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,29,07,07,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,29,07,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,29,07,07,07,29 DATA 15,15,15,15,15,15,15,15,15,15,15,29,29,29,15 'For the third, floor tiles... DATA 07,08,08,08,08,08,08,08,08,08,08,08,08,08,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,00,00,00,00,00,00,00,00,00,00,00,00,00,07 'The map file... 30 x 15 now... DATA 3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 DATA 3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,2,3,2,2,2,2,2,2,2,3,3 DATA 2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,1,2,2,1,2,2,2,2,3,3 DATA 2,2,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,2,1,1,2,2,2,2,2,3,3 DATA 2,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,1,1,2,2,3,2,2,3,3 DATA 3,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,2,3,2,2,2,3,1,3,2,3,3 DATA 3,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,2,3,2,2,2,2,3,2,2,3,3 DATA 3,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,2,2,2,2,2,2,3,3 DATA 3,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,3,3,2,2,2,2,2,2,2,3,3 DATA 3,3,3,3,3,3,3,2,2,2,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 ----- Look at that... cool huh?... Remember, that if you run out of the map, an error shows up... if you want, you can make a larger map... But don't forget to change the 30 x 15 values everywhere in the program it showes up... Actually,,, here... I have made a new map file... instead of the 30 x 15 one... erase the old 30 x 15 map and paste this into your program... (don't forget to erase the old map!!!) It is your job now, Make this map work... change what you need to... 'The map file... 45 x 15 now... DATA 3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 DATA 3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3 DATA 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,3,3,1,1,3,3,3,1,1,3 DATA 3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,1,2,2,2,2,2,2,2,1,3,1,1,1,3,3,1,1,3,1,3,1,1,3,1,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,1,3,1,1,1,3,3,1,1,3,1,3,1,1,3,1,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,2,1,2,2,2,2,2,2,2,1,3,1,1,1,3,3,1,1,3,1,3,1,1,3,1,3 DATA 2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,1,2,2,1,2,2,2,2,1,3,1,1,1,3,3,1,1,3,1,3,3,3,1,1,3 DATA 2,2,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,1,1,1,2,2,2,2,2,1,1,3,1,3,1,3,1,1,3,1,3,1,1,3,1,3 DATA 2,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,1,1,1,2,2,1,2,2,1,1,3,1,3,1,3,1,3,3,1,3,1,1,3,1,3 DATA 3,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,2,1,2,2,2,1,1,1,1,1,1,1,3,1,1,1,3,3,3,1,3,1,1,3,1,3 DATA 3,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,2,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,1,1,3 DATA 3,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3 DATA 3,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,3 DATA 3,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,3,1,2,2,2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3 DATA 3,3,3,3,3,3,3,2,2,2,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,3 ------------------------------ ****************************** ------------------------------ Now, here comes the REALLY HARD PART... Getting this to scroll ONE pixel at a time instead of one tile at a time... There are two known (by me) methods of scrolling the screen 1.) using GET & PUT and move the entire screen to the left or right... 2.) using DQB or another library with the Scroll function... I prefer the later... Since using GET & PUT is very very slow... So, to conclude this tutor, I will teach you to use the Scroll function from the DQB library (read last tutor)... With the Scroll function the screen is moved a sertain amount to the left right, up, or down... But, when the screen moves, the part that is to the left or whatever direction will be black... You have to put the new tiles there,,, But, you can't just put the tiles down, you have to put part of the tile down... But, since we have total control of every pixel in the tiles, this is pretty easy,,, What's that you say? you don't think you have total control of the tiles? oh yeah thats right... Instead of using GET & PUT, you will have to store each of the tiles... every pixel of the tiles that is... to do this, you will have to use the information given by my Array tutor... you will use arrays like this... DIM tile1(15, 13) for y = 1 to 13 for x = 1 to 15 read tile1(x,y) next:next so instead of printing them to the screen and using GET... you will store them into that array... But, to some of you, you might ask how the H* you put down the tile like using the PUT command... Easy... Just reverse it... for y = 1 to 13 for x = 1 to 15 pset tile1(x,y) next:next That (whats above) will do the same as using the PUT command... ------- If you think about it, you draw the new tile the same way you would draw a map... you have to give it an X value to start and end on... (if you just scroll 1 pixel, you don't really have to worry about where it will end...) this way, you will only draw part of the tile and not the entire tile... Unless that is, if you want to scroll the screen more than 1 pixel at a time.... If you scroll it two or three at a time, you might end up having to draw parts of more than just one tile... and knowing when you have to do that can get really complicated... But, I won't cover that... With the information given above, you should be able (with a bit of experementing) you should be able to create your own pixel by pixel scrolling engine... But, if you are still confused, I will run you through the way I do it... (wich, once again, is not the best or fastest method...) I might suggest to you to look over someone elses source and attemt to see whats going on, BUT.. DO NOT COPY MY OR ANYONE ELSES SOURCE CODE WORD FOR WORD!!!!!! Look at the source and try to understand how it is done and do it for yourself!!! And, if you do learn from thier source, put them in your game credits... How much could it hurt to add an extra name¿¿?? (((ohh, and by the way my name is Vic Luce... or Radiohands))) nudge nudge... ahem... excuse me... -------------------------- Ok, here we go... Try your best to understand (it can sometimes be hard to explain your own work...) Ok, First, First, start up Qb 4.5 with Direct QB support... run the command... c:\dqb\qb /ldqb (your directory may be different...) and if you have no Idea what I'm talking about, READ MY LAST TUTOR!!! --- Before I continue, there is one dqb function I need to explain... DQBScroll (layer, x, y) this command is kind of simple... (if you read the DQB.doc that came with DQB) with this command, you can scroll the screen Up Down Left Right ... First, you have to tell it what layer to scroll (if you want it to scroll the actual screen use VIDEO) then, the X and Y if you want the screen to go.. Right call dqbscroll (video, -1, 0) Left call dqbscroll (video, 1, 0) Down call dqbscroll (video, 0, 1) Up call dqbscroll (video, 0, -1) K'ay... 'nuf said... -------------------------------------- In order to scroll one pixel at a time, and (in a way) scroll 1 tile every 15 pixels, you need to introduce another variable... we will call this new variable XSVS x start value (second) So, this will take care of the pixels to be printed in the tile... While XSV will take control of what Tile we are currently working on... Do you understand? Let me explain this a bit easier... XSV takes care of the X value in the Map file correct? XSVS takes care of the X value for each individual tile correct? yes,,, thats not a trick question... So, first... We need to know What tile we are currently working on... Thats what XSV is for... Then, we need to know what part of the tile to print to the screen... That is XSVS... If you think about it, XSV allways goes up no matter what... (that is if you are scrolling ONLY right like we are currently...) So, how would we controll XSVS? Instead of making xsv go up everytime we push a button, we make XSVS go up by one every time... But, how will we change XSV? (maybe you wern't thinking that, but you should of!!!) since The tile is only 15 accross... We can only have xsvs go up to 15... If it goes higher, it will screw up... So, when XSVS gets up to 15, we have to go to a new Tile... Right? ... yes... (if you were wondering...) To go to a new tile, you have to change the XSV value... Easy... IF XSVS > 15 then XSV = XSV + 1 simple... But, don't forget to change the XSVS value back to zero... or one... so, it would look like this... IF XSVS > 15 then XSV = XSV + 1 XSVS = 0 ' or one... depending on where you start you loops... ' I'll explain,,, don't worry... END IF ----------------- Ok, I hope that makes sence... (and yes, I know that asking that question doesn't make you understand anymore than before...) Let me simplify... You need TWO values to scroll one pixel at a time... XSV ' this controls what Tile you are on... XSVS ' this controls what pixel (x) you are on on the current tile... In order to be on the correct tile, you need to make XSV go up by one everytime... So, since the tiles max x value is 15, every time XSVS goes above 15, you need to reset it and make XSV go up by one... ----------------------------------------------------------------------------- Were not done with the math yet!!! Remember how to put the tile down after you stored it in an array? well, if you don't here it is again... for y = 1 to 13:for x = 1 to 15 dqbpset 1,x,y,tile1(x,y) next:next If you really want, you could just put the tile down like this... for y = 1 to 13:for x = 1 to 15 if y+xsvs < 320 then dqbpset... next:next this way, you put the entire tile down, until it starts to go off screen... but, the more you PSET, the more time this takes... So, you only want to pset what you have to... and once again... This can get very complicated... so stay with me... since, we are only goint to scroll left & right and not up and Down, we really don't have to worry where x starts and ends... we only have to worry about where y starts and ends... heres code directly from my pixel x pixel scrolling engine... xsv = 22 FOR i = 1 TO 15 FOR y = 1 TO 13 IF map1(xsv, i) = 1 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite1(xsvs, y) IF map1(xsv, i) = 2 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite2(xsvs, y) IF map1(xsv, i) = 3 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite3(xsvs, y) NEXT NEXT First, look over the code... (ok let me first explain the XSV = 22...) Before you start the loop, you first have to draw the map... that is, from x point 1 to 21 so, if you start xsv at 1 then you would start to draw the map from the first x point... and not from where you left off... so, we need to start the xsv at 22 because when we finished drawing the initial map, we ended at 21... so the new tiles to the Right will start at 22... Once again I remind you that I am giving out the information Quite Frankly... and I really really don't expect you to get the Idea directly at first... it could take a few looks at this tutor to figure it all out... '''' You know what... This tutor is starting to get me nausiateed and you know what... I don't care if I spelled that wrong... What else is making me sick is that It might take you (the reader) longer to understand this because I'm not explaining it to the best of my ability... ohh, yeah and the fact that this tutor will only be seen by about 10 people including 1.) me 2.) myself 3.) I 4.) Fred,,, (the lonely internet guy that has vowed to read everything on the internet...) but halfway through gets bored and falls dead... 5.) Hacker trying to end the misery that is my website... But also falls dead with bordom... 6.) Microsoft dude... Trying to end qbasic support... 7.) Second MS dude that was told by the first what a hilarious attempt at a tutor this was... 8.) FBI dude, in an attempt to find out what killed Fred and the hacker... 9.) 2nd hacker trying to carry on in his friends footsteps... 10.) And of coarse (most importantly) you... The most wonderfull, well read and coolest of all hopefull Qbasic Programmers... But it's allmost over... keep trying fred... Where was I? ... ohh yeah... About 50,000,000 words into this tutor... lets look at this... FOR i = 1 TO 15 FOR y = 1 TO 13 IF map1(xsv, i) = 1 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite1(xsvs, y) next:next how the fudge does this work? look at the this part... IF map1(xsv,i) = 1 do you remember what xsv is? it is what Tile you are currently on... right? took the words right out of your mouth right? but what about the i? it is the current y value on the map... since we are only going left and right, the y value will allways be the same,,, only the x value of the map needs to be used and changed... So, we go through all the y sections of the tile... and there are 15 tiles up and down... so, to go through all of the Y tiles we have to go from 1 to 15... Although, you could do it like this... for y = 1 to 15... I chose to use this for i = 1 to 15... why... because y is allready declared, and i is just a generic for loop variable so, i is the variable of the current y value for the tile... IF map1(xsv, i) = 1 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite1(xsvs, y) now, what about the dqbpset 1, 315, i * 13 - 13 + y, sprite1(xsvs, y) ? dqbpset 1, is self explainitory... we want to put the pixel on virtuall screen 1... now the , 315, part... why start a 315? Because, when we first draw the map, it ends at 315... so, when the screen is moved to the left by 1 pixel, this is where we need to start the new line of pixels... If you only scroll one pixel at a time this will NEVER change... so, the x value for the new pixel will allways be 315... what about the y value now? we have dqbpset screen , x... now we need the y section... which looks like this... i * 13 - 13 + y, interesting... remember, that i is the current y value of the map tile we are working on... and, remember that each tile is 13 pixels going up and down... so the tile will go by 13... but, since the lowest value will be 1, if we want the tile at the zero point and not 13 ahead we have to subtract that 13... if it went from 0 to 12, you wouldn't need the - 13... but to simplify the FOR LOOP it starts at one... Now, what about the + y? if you look at the current for loop... FOR i = 1 TO 15 FOR y = 1 TO 13 you remember that i is the map tile value... and, that must mean that the y is the current tile value... (the individual pixel y value...) so, by adding this (knowing that y changes 13 times) you adjust it to go down ONE pixel at a time, until the tile is drawn 13 pixels down, then i changes to the next tile and the proccess starts all over again until all the tiles (i) are drawn to the screen... but, before you can draw the pixel at the appropriate location, you have to find out what color that current pixel is... thats where the sprite1(xsvs, y)comes into play... I hope you remember what xsvs is... (its the current x value of the tile we are working on...) and the current x value for the tile never changes... (until xsvs = xsvs + 1 is used before the FOR LOOP...) but during the FOR LOOP this xsvs value will not change... so, sprite1(xsvs, is a given... the , y part is allready declared in the FOR LOOP and changes everytime a new pixel is drawn... so, the current pixel color is found in the tile array (or sprite1) in this case... -------- OK!! the for loop draws a strip of pixels down the screen in the correct new empty space that was scrolled, and with the correct tile color... There is no more information that you need to know to scroll the screen... one pixel at a time that is... (and thats all this tutor will cover... --- So, lets put all this information together into ONE program... but, to clean up the code to get this to run SMOOTHLY, there are a few thing that you need to know... (don't panic, this all should be very easy to understand...) 1.) by printing each pixel to page 1, and copying it to the video screen (actual screen) when all the pixels are drawn, will help speed up the program and lose any flickering that would occur... 2.) by using DQB's keyboard function, you will not have to wait for the keyboard to repeat a key, and make it run smooth and not choppy... 3.) by using DQBWAIT (1) you wait a quick screen retrace before copying making the program run at an appropriate speed... (getting rid of DQBWAIT (1) the program will run way to fast!!!) ------------ Now, since we have those few things out of the way, I will now walk you through how to put this alltogether in a program... First, we need to 1.) setup direct qb... 2.) dim the correct variables 3.) set the xsv and xsvs values... like so... '$INCLUDE: 'directqb.bi' DIM sprite1(15, 13), sprite2(15, 13), sprite3(15, 13) DIM map1(45, 15) 'NOTE THAT THE MAP IS 45 X 15 x = DQBinit(1, 0) dqbinitvga xsvs = 0 xsv = 1 (note:) xsvs starts at one, because when you press a button to go right, xsvs = xsvs + 1 will be called and if you set it to one, it would now equall 2 to start out!!! xsv equals 1, because that is what we want to start when we draw the first initial map... (it will go from 1 to 21) but, remember, when the loop starts, this will be changed to 22... --- Now, we need to get our sprites (can also be called tiles) and, we also need to get our map to be stored into thier own individual arrays... (that were just dimmed...) (note, that I allready covered this, but I want to make sure you understand ... FOR y = 1 TO 13: FOR x = 1 TO 15: READ sprite1(x, y): NEXT: NEXT FOR y = 1 TO 13: FOR x = 1 TO 15: READ sprite2(x, y): NEXT: NEXT FOR y = 1 TO 13: FOR x = 1 TO 15: READ sprite3(x, y): NEXT: NEXT 'THIS IS THE MAP... 30 X 15 (REMEMBER?) FOR y = 1 TO 15: FOR x = 1 TO 45: READ map1(x, y): NEXT: NEXT this all reads the DATA file statements at the end of the program... I think that this all should be self explainitory... --- Now, we need to draw our initial map... wich is 21 x 15... FOR y = 1 TO 15 FOR x = xsv TO xsv + 20 IF map1(x, y) = 1 THEN FOR iy = 1 TO 13: FOR ix = 1 TO 15 dqbpset 1, x * 15 - xsv * 15 + ix, y * 13 - 13 + iy, sprite1(ix, iy) NEXT: NEXT END IF IF map1(x, y) = 2 THEN FOR iy = 1 TO 13: FOR ix = 1 TO 15 dqbpset 1, x * 15 - xsv * 15 + ix, y * 13 - 13 + iy, sprite2(ix, iy) NEXT: NEXT END IF IF map1(x, y) = 3 THEN FOR iy = 1 TO 13: FOR ix = 1 TO 15 dqbpset 1, x * 15 - xsv * 15 + ix, y * 13 - 13 + iy, sprite3(ix, iy) NEXT: NEXT END IF NEXT: NEXT This prints the map to screen # 1... so you have to copy this to the screen with the command... dqbcopylayer 1, video --- so, we have our initial map printed to the screen... now is a good time to install the Direct QB keyboard... dqbinstallkeyboard and, before we start the main loop, we have to make sure we are printing tiles at the end of the current Initial map that we just printed to the screen... Remember how? xsv = 22 now I bet you remember... --- Now, lets start our DO LOOP wich is the MAIN Program LOOP... DO easy huh? now, we need something in the loop to find out when the right arrow button is pushed to move the map... IF DQBkey(KEYRIGHT) AND xsv < 45 THEN and the first thing we need done is to make the xsvs current tile value to go up by one... xsvs = xsvs + 1 --- We now have a new xsvs variable, but, what if xsvs is equal to the maximum x value of the current sprite which is the value 15... that means that the new xsvs value will go to sixteen... which means that we have to reset the xsvs value and the xsv value... xsvs will go back to one (it won't go to zero, because there is no current tile x zero value declared) and xsv will go up by one, changing the current x tile we are on in the map IF xsvs > 15 THEN xsv = xsv + 1 xsvs = 1 END IF easy... now what? --- We need to scroll the initial map one to the left... use the dqbscroll command like this... dqbscroll 1, -1, 0 that will (if you remember) scroll the screen to the left... and leave a blank spot at 315 x screen value... and, to clean up the mess that can sometimes happen with the scroll function we need to make sure that anything comming from the right when the map is scrolled is now blank... to do this, draw a line up and down the screen at the edge where something could show up... draw the line with this command... dqbline 1, 319, 0, 319, 200, 0 this will make sure the new scrolled screen is clear from any invading unwanted pixels... but, this is not neccessary... --------- Now, lets create the FOR LOOP that will print the vertical pixels from the map and tiles... (we just covered that...) FOR i = 1 TO 15 FOR y = 1 TO 13 IF map1(xsv, i) = 1 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite1(xsvs, y) IF map1(xsv, i) = 2 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite2(xsvs, y) IF map1(xsv, i) = 3 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite3(xsvs, y) NEXT NEXT This will read the map and put the proper pixel... (once again, we just covered this...) and before we copy the current layer to the video, we need to put in that dqbwait(1) command... do it like this... dqbwait (1) huh huh... and then (of course) after that, we need to copy layer 1 to the video screen so we can see what happened... dqbcopylayer 1, video and then of coarse, we need to close the if that started when we used the command IF DQBkey(KEYRIGHT) AND xsv < 45 THEN ... do it like this END IF huh huh huh... Then, we need to close the MAIN Do Loop... LOOP UNTIL DQBkey(KEYESC) dqbclose this means that the MAIN Do Loop will continue looping until you press the ESCAPE key... and then, when you exit the main loop you shut down DQB... this is important, if you don't shut down DQB you can't use your keyboard!!! then, at the end of the file you have your DATA statments of the tiles and map file... ---------------------------- Lets put this all together... DON'T FORGET TO START QB 4.5 WITH THIS COMMAND!!!! C:\DQB\QB /ldqb this is very important (read my last tutor...) 'HERE WE GO!!!!!! '$INCLUDE: 'directqb.bi' DIM sprite1(15, 13), sprite2(15, 13), sprite3(15, 13) DIM map1(45, 15) 'INITALIZE DQB AND THE DQB VGA SCREEN(S) x = DQBinit(1, 0) dqbinitvga 'INITIAL START XSVS AND XSV VALUES... xsvs = 0 xsv = 1 'GET THE TILES AND MAP... FOR y = 1 TO 13: FOR x = 1 TO 15: READ sprite1(x, y): NEXT: NEXT FOR y = 1 TO 13: FOR x = 1 TO 15: READ sprite2(x, y): NEXT: NEXT FOR y = 1 TO 13: FOR x = 1 TO 15: READ sprite3(x, y): NEXT: NEXT FOR y = 1 TO 15: FOR x = 1 TO 45: READ map1(x, y): NEXT: NEXT 'DRAW THE INITIAL MAP... FOR y = 1 TO 15 FOR x = xsv TO xsv + 20 IF map1(x, y) = 1 THEN FOR iy = 1 TO 13: FOR ix = 1 TO 15 dqbpset 1, x * 15 - xsv * 15 + ix, y * 13 - 13 + iy, sprite1(ix, iy) NEXT: NEXT END IF IF map1(x, y) = 2 THEN FOR iy = 1 TO 13: FOR ix = 1 TO 15 dqbpset 1, x * 15 - xsv * 15 + ix, y * 13 - 13 + iy, sprite2(ix, iy) NEXT: NEXT END IF IF map1(x, y) = 3 THEN FOR iy = 1 TO 13: FOR ix = 1 TO 15 dqbpset 1, x * 15 - xsv * 15 + ix, y * 13 - 13 + iy, sprite3(ix, iy) NEXT: NEXT END IF NEXT: NEXT 'MAKE THE MAP VISIBLE... dqbcopylayer 1, video 'INSTALL THE DQB KEYBOARD HANDLER... dqbinstallkeyboard 'MAKE SURE XSV STARTS AT THE END OF THE INITIAL MAP... xsv = 22 'START THE MAIN LOOP DO 'IF YOU PRESS THE RIGHT ARROW BUTTON... IF DQBkey(KEYRIGHT) AND xsv < 45 THEN xsvs = xsvs + 1 'MAKE SURE XSVS DOESN'T GO HIGHER THAN 15... IF xsvs > 15 THEN xsv = xsv + 1 xsvs = 1 END IF 'SCROLL THE SCREEN AND CLEAN UP ANY CRAP... dqbscroll 1, -1, 0 dqbline 1, 319, 0, 319, 200, 0 'IF THE RIGHT ARROW BUTTON IS PRESSED, AND THE MAP IS SCROLLED, 'DRAW A STRIP OF PIXELS IN THE NEW AREA AT X SCREEN VALUE OF 315... FOR i = 1 TO 15 FOR y = 1 TO 13 IF map1(xsv, i) = 1 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite1(xsvs, y) IF map1(xsv, i) = 2 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite2(xsvs, y) IF map1(xsv, i) = 3 THEN dqbpset 1, 315, i * 13 - 13 + y, sprite3(xsvs, y) NEXT NEXT 'MAKE SURE THE PROGRAM RUNS AT AN APPROPRIATE SPEED... dqbwait (1) 'MAKE THE NEW MAP VISIBLE... dqbcopylayer 1, video END IF 'RUN THE MAIN LOOP UNTIL THE ESCAPE KEY IS PRESSED... LOOP UNTIL DQBkey(KEYESC) 'CLOSE THE VGA AND KEYBOARD HANDLER... dqbclose 'TILE AND MAP DATA STATMENTS... DATA 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,10,02,10,10,10,10 DATA 10,10,10,02,10,10,10,02,10,10,02,10,10,10,10 DATA 10,10,10,10,02,10,02,10,10,10,10,10,10,10,10 DATA 02,10,10,10,02,10,02,10,10,10,02,10,10,10,10 DATA 10,02,10,10,02,10,02,10,10,02,10,10,02,10,10 DATA 10,10,02,02,10,02,10,10,10,02,10,02,10,10,10 DATA 10,10,10,10,10,10,10,10,10,02,10,02,10,10,10 DATA 02,02,10,10,02,10,10,10,02,02,02,10,10,10,10 DATA 10,10,02,02,10,10,10,10,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,02,10,10,10,10,10,10,10 DATA 10,10,10,10,10,10,02,10,10,10,10,10,10,10,10 'This (considering its the north pole) will be the snow... DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,29,29,29,15,15,15,15,15,15,15,15,15 DATA 15,15,29,07,07,07,15,15,15,29,29,15,15,15,15 DATA 15,15,29,07,15,15,15,15,29,07,07,15,15,15,15 DATA 15,29,07,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,29,15,15,15,15,15,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,15,29,29,07,15,15,15,15,15,15 DATA 15,15,15,15,15,29,07,07,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,29,07,15,15,15,15 DATA 15,15,15,15,15,15,15,15,15,15,29,07,07,07,29 DATA 15,15,15,15,15,15,15,15,15,15,15,29,29,29,15 'For the third, floor tiles... DATA 07,08,08,08,08,08,08,08,08,08,08,08,08,08,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,07,07,07,07,07,07,07,07,07,07,07,07,07,00 DATA 08,00,00,00,00,00,00,00,00,00,00,00,00,00,07 'The map file... 30 x 15 now... DATA 3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 DATA 3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3 DATA 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,3,3,1,1,3,3,3,1,1,3 DATA 3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,1,2,2,2,2,2,2,2,1,3,1,1,1,3,3,1,1,3,1,3,1,1,3,1,3 DATA 3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1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! HA HA AH HA HA HAAAA!!! Thank you for bearing with me as I plow throught the programming world with bad spelling and horible grammar!!! ---------------------------------------------------------------------------- **************************************************************************** ---------------------------------------------------------------------------- File Edit View Search Run Debug Calls Options Help +--------------------------------- Untitled -------------------------------¦+-+ ¦Thats it for this tutorial, If I didn't get into enough detail in the  ¦explanations then just look at the source code and try to figure it out ¦on your own. All else fails E-Mail Me... I want to make these tutorials _ ¦as easy to understand as posible!!! _ ¦ _ ¦My current E-Mail address is RADIOHANDS@AOL.com _ ¦ _ ¦If you are using this tutorial on your page, please leave the tutorial _ ¦exactly as it is... please don't change anything, unless its spelling _ ¦errors... Theres alot of them! I don't like using the backspace key... _ ¦ _ ¦The original website that these were on is _ ¦ _ ¦http://members.aol.com/radiohands/index.html _ ¦ _ ¦Thank you _ ¦Vic Luce _ ¦Finished _ ¦August, 4 _ ¦2000 _ ¦  ¦ ___________________________________________________________________________¦ ¦ N 00001:008 ... If you want to be notified when a new tutorial is out.. Send An E-mail to RADIOHANDS@AOL.com with the subject saying VQBLIST and then your E-mail address(check website)