Vic's QBasic Programming Tutorial Basic Tutorial X RPG's!!! Role Playing Games ----------------------------------------------------------------------------- To make up for the last tutorial I plan to cover what almost every QBaisic programmer tries to make but don't ever seem to finish... RPG'S!!!! In my opinion there are Two types of RPG's. One that you walk around and out of nowhere you get in a fight (Like PokeMon) and one that you walk around freely and fight bad guys face to face (Like Zelda (My favorite)). The kind I will cover in this tutorial is the random fighting (PokeMon). These kinds are very easy to make and you can concentrate more on the actual game, Its reason for being... In a RPG a story is the most important thing. It is a ROLE PLAYING GAME, which means you are trying to accomplish something. If you don't know what you are trying to acomplish, why are you playing? If you think about it, Zelda and Pokemon have completely different stories. Try to make yours just as different. Although knights usually appear in RPG's remember, THEY DON'T HAVE TOO!!! Pokemon is the first RPG, that I have noticed, that doesn't use knights and princesses... I think Pokemon is more fun then the Legend of Zelda (maybe not the N64 version...). --- First things first, PICK A STORY... Lets see, Today is November 29, just a month from christmas. How about that? Lets come up with a quick story... The elves at the north pole are striking because they... Well... Just Because... They have mutinied and taken santa to a prison camp and will not let him go until their demands are met. Who do you play in this RPG? You will be a fellow Elf that does not like what the others are doing... Whats your goal? Your goal is to find and set santa free... ---- Ok ok... This will not be the next Pokemon, but it's a start!! GREAT!! We have our story... Now what? Well, since this is a tutorial I will tell you how to program your own RPG... We will use one great thing.. do you remeber it? It was in a past tutorial.. Say it with me! BITMAPS!!! --- Before I start with the tutorial I want you to know a few things... 1. I CANT DRAW!!! 2. There are probably a hundred different ways to program an RPG... 3. I CANT DRAW!!! 4. BITMAPS are a headache to work with when you make so many... 5. I will use only bitmaps in this tutorial, if I were you, I would use a image editor made in qbasic (theres tons), I even have one... 6. I CANT DRAW!!! thats it... HERE WE GO!!! ----------------------------------------------------------------------------- MAP DRAWING... If you read the tutorial on bitmaps this should be a breeze... In my RPG experience, I found that in screen 13 a map that is 21 x 15. and each tile should be about 15 x 13... not square in real life, but square in screen 13... before we draw the map we need a tile... lets draw one, or two, or three... lets use the GET and PUT commands with the tiles ... first we have to dim the sprites... DIM sprite1(50), sprite2(50), sprite3(50) Once thats done lets draw some pictures using bitmaps... !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOTICE: These are written by hand, I didn't use any kind of editor... You can make your own if you like... !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! '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 'In the map, 1 is the sprite for grass. 2 is the sprite for snow. 3 is the sprite for the tile... ----------- GREAT!! we have everything! now what do we do with it... first, we need to get our sprites... we allready dimed them, now we have to print them to the screen and get them with the get command... Remember how to do this from my bitmap tutorial? like this... FOR y = 1 TO 13 'remember, the tile is 15 x 13 (x=15 and y=13) FOR x = 1 TO 15 READ clr PSET (x, y), clr NEXT: NEXT GET (1, 1)-(15, 13), sprite1 'That prints the first sprite and gets it... 'same old same old... 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 '--- DONE!! Ok, now we have our background sprites. If you don't understand how I got them look over my bitmap tutorial... Now that we got our bkg sprites it is time to get your map... First, just like the sprites, we have to dim it into an array... do it like this... DIM map1(21,15) 'thats it... now, we have to get the map into the dimed array... do it somewhat the same way we used the sprites, only we won't use GET and PUT... Do it like this... FOR y = 1 TO 15 FOR x = 1 TO 21 READ map1(x, y) NEXT: NEXT 'DONE thats it, we now have the map and the sprites in an array... Now lets show you how to put it on the screen... Like this, Remember that 1 is grass, 2 is snow, and 3 is tiles... '--- FOR y = 1 TO 15 'Remember the map is 21 x 15, x=21 and y = 15 FOR x = 1 TO 21 'these look at the map and if it is a certain number, put a certain 'sprite at the x,y coords... 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 '--- DONE... The only thing I think that needs explaining is the commands IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1 IF map1(x, y) = 2 THEN ... I bet your wondering where I got the (x * 15 -15, y * 13 -13) from right? Each tile is 15 x 13... in order to space them out you must multiply the location by the tiles max x and max y values. That would be the 15 and the 13. And because The FOR i Y = 1 to 10 starts at ONE you need to put the space needed and subtract it by ONE x or y value... Confusing? I thought so, you will understand eventually... Lets put it all together... Copy this into Qbasic however you want. I would use the DOS Box tecnique... that means... 1. highlight all of the program below. 2. goto edit and then copy... 3. open QBASIC and Push ALT and ENTER to shrink the window... 4. go over to the title bar and push the paste button on the DOS Box window.. that should type the program for you... '--- Begin highlighting... DIM sprite1(50), sprite2(50), sprite3(50) DIM map1(21, 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 CLS FOR y = 1 TO 15 FOR x = 1 TO 21 READ map1(x, y) NEXT: NEXT '*****|***** this doesnt do anything, just for a reference point... 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 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 '--- STOP HIGHLIGHTING!!! Isn't it beutifull? Don't close this file yet!!! We will still use it... ----- Now it is time to put a moveable sprite in it!! first, Lets draw one... Remember to first dim it... We will use two sprites, one for the actual sprite and one for the sprites mask. If you don't understand this, look at my bit blt tutorial... Copy this at the top of the Qbasic file you just made... Dim guy(50), guysh(50) Now, copy this at the bottom of the file you just made. Right after your map bitmap... 'This is the actual bitmap DATA 00,00,00,00,00,00,10,10,10,10,00,00,00,00,00 DATA 00,00,00,00,00,10,10,10,10,10,10,00,00,00,00 DATA 00,00,00,10,10,66,10,10,10,10,10,66,00,00,00 DATA 00,00,15,00,00,66,66,66,66,66,66,66,00,00,00 DATA 00,00,00,00,00,00,66,00,66,00,66,00,00,00,00 DATA 00,00,00,00,00,00,66,66,66,66,66,00,00,00,00 DATA 00,00,00,00,00,00,00,66,00,66,00,00,00,00,00 DATA 00,00,00,00,00,00,02,02,02,02,02,00,00,00,00 DATA 00,00,00,00,00,02,00,02,02,02,00,02,00,00,00 DATA 00,00,00,00,00,02,00,02,02,02,00,02,00,00,00 DATA 00,00,00,00,00,66,00,02,02,02,00,66,00,00,00 DATA 00,00,00,00,02,00,00,07,00,07,00,00,02,00,00 DATA 00,00,00,00,00,02,02,02,00,02,02,02,00,00,00 'This is the mask for the sprite... DATA 255,255,255,255,255,255,10,10,10,10,255,255,255,255,255 DATA 255,255,255,255,255,10,10,10,10,10,10,255,255,255,255 DATA 255,255,255,10,10,66,10,10,10,10,10,66,255,255,255 DATA 255,255,15,255,255,66,66,66,66,66,66,66,255,255,255 DATA 255,255,255,255,255,255,66,00,66,00,66,255,255,255,255 DATA 255,255,255,255,255,255,66,66,66,66,66,255,255,255,255 DATA 255,255,255,255,255,255,255,66,00,66,255,255,255,255,255 DATA 255,255,255,255,255,255,02,02,02,02,02,255,255,255,255 DATA 255,255,255,255,255,02,255,02,02,02,255,02,255,255,255 DATA 255,255,255,255,255,02,255,02,02,02,255,02,255,255,255 DATA 255,255,255,255,255,66,255,02,02,02,255,66,255,255,255 DATA 255,255,255,255,02,255,255,07,255,07,255,255,02,255,255 DATA 255,255,255,255,255,02,02,02,255,02,02,02,255,255,255 Now, lets store these in an array... Put this after the part when you put the map into an array... it will be after the '******|******... FOR y = 1 TO 13 FOR x = 1 TO 15 READ clr PSET (x, y), clr NEXT: NEXT GET (1, 1)-(15, 13), guy FOR y = 1 TO 13 FOR x = 1 TO 15 READ clr PSET (x, y), clr NEXT: NEXT GET (1, 1)-(15, 13), guysh CLS 'Thats it... we have are guy... Now, lets give him a spot to start... How about at the point 20,8? after the SCREEN 13 Command put guyx = 20 guyy = 8 'Now we have a position to start... Lets put him on the screen... Right before the first bitmap (sprite one) put this PUT (guyx * 15 - 15, guyy * 13 - 13), guysh, AND PUT (guyx * 15 - 15, guyy * 13 - 13), guy, OR if you have read the tutorial on bit blt you know what this does... this puts the shadow down and then puts the guy over it so you can see the background... THATS GREAT! We have a character! now, how do we move him? first, like every game, we must use a program loop... Do you remember? after the Put (guyx... that you just put down, type this oldguyx = guyx oldguyy = guyy Do press$ = inkey$ loop until press$ = chr$(27) 'DONE the oldguyx = guyx... just records the charcters position.. you'll see why later... between the press$ = inkey$ and the LOOP UNTIL... write this IF press$ = CHR$(0) + CHR$(75) THEN guyx = guyx - 1 'These just move the IF press$ = CHR$(0) + CHR$(77) THEN guyx = guyx + 1 'guy... IF press$ = CHR$(0) + CHR$(72) THEN guyy = guyy - 1 IF press$ = CHR$(0) + CHR$(80) THEN guyy = guyy + 1 'This just looks at the old position and sees if it is different, 'If it is different, then redraw the screen and record the values again... if oldguyx <> guyx or oldguyy <> guyy then 'This redraws 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, pset IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2, pset IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3, pset NEXT: NEXT PUT (guyx * 15 - 15, guyy * 13 - 13), guysh, AND PUT (guyx * 15 - 15, guyy * 13 - 13), guy, OR end if 'OK stop... If you run the program you will notice you can move the guy!! The only problem is that you can also move him off screen... lets change the above to stop that... Before you copy this into QBASIC, delete what you just put in... Sorry about that... IF press$ = CHR$(0) + CHR$(75) AND map1(guyx - 1, guyy) <> 3 THEN IF guyx > 1 THEN guyx = guyx - 1 END IF IF press$ = CHR$(0) + CHR$(77) AND map1(guyx + 1, guyy) <> 3 THEN IF guyx < 20 THEN guyx = guyx + 1 END IF IF press$ = CHR$(0) + CHR$(72) AND map1(guyx, guyy - 1) <> 3 THEN IF guyy > 1 THEN guyy = guyy - 1 END IF IF press$ = CHR$(0) + CHR$(80) AND map1(guyx, guyy + 1) <> 3 THEN IF guyy < 14 THEN guyy = guyy + 1 END IF 'This just looks at the old position and sees if it is different, 'If it is different, then redraw the screen and record the values again... if oldguyx <> guyx or oldguyy <> guyy then 'This redraws 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, pset IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2, pset IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3, pset NEXT: NEXT PUT (guyx * 15 - 15, guyy * 13 - 13), guysh, AND PUT (guyx * 15 - 15, guyy * 13 - 13), guy, OR end if 'Ok, stop copying... Now, you can't go off the screen and you cant step on the tiles... how is this done? the program says if map(x+#,y+#) = 3 then don't go there.. that means, if the next tile you will walk on is a floor tile then don't let him walk there... If you change the <> 3 in the above part to <> 1, grass will stop you... TRY IT!! ----------- All together now! If somewhere you screwed up in copying just copy this in its entirety... '--- START COPYING DIM guy(50), guysh(50) DIM sprite1(50), sprite2(50), sprite3(50) DIM map1(21, 15) SCREEN 13 guyx = 20 guyy = 8 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 CLS FOR y = 1 TO 15 FOR x = 1 TO 21 READ map1(x, y) NEXT: NEXT FOR y = 1 TO 13 FOR x = 1 TO 15 READ clr PSET (x, y), clr NEXT: NEXT GET (1, 1)-(15, 13), guy FOR y = 1 TO 13 FOR x = 1 TO 15 READ clr PSET (x, y), clr NEXT: NEXT GET (1, 1)-(15, 13), guysh CLS 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 PUT (guyx * 15 - 15, guyy * 13 - 13), guysh, AND PUT (guyx * 15 - 15, guyy * 13 - 13), guy, OR DO press$ = INKEY$ IF press$ = CHR$(0) + CHR$(75) AND map1(guyx - 1, guyy) <> 3 THEN IF guyx > 1 THEN guyx = guyx - 1 END IF IF press$ = CHR$(0) + CHR$(77) AND map1(guyx + 1, guyy) <> 3 THEN IF guyx < 20 THEN guyx = guyx + 1 END IF IF press$ = CHR$(0) + CHR$(72) AND map1(guyx, guyy - 1) <> 3 THEN IF guyy > 1 THEN guyy = guyy - 1 END IF IF press$ = CHR$(0) + CHR$(80) AND map1(guyx, guyy + 1) <> 3 THEN IF guyy < 14 THEN guyy = guyy + 1 END IF IF oldguyx <> guyx OR oldguyy <> guyy THEN oldguyx = guyx oldguyy = guyy FOR y = 1 TO 15 FOR x = 1 TO 21 IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1, PSET IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2, PSET IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3, PSET NEXT: NEXT PUT (guyx * 15 - 15, guyy * 13 - 13), guysh, AND PUT (guyx * 15 - 15, guyy * 13 - 13), guy, OR 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 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 DATA 00,00,00,00,00,00,10,10,10,10,00,00,00,00,00 DATA 00,00,00,00,00,10,10,10,10,10,10,00,00,00,00 DATA 00,00,00,10,10,66,10,10,10,10,10,66,00,00,00 DATA 00,00,15,00,00,66,66,66,66,66,66,66,00,00,00 DATA 00,00,00,00,00,00,66,00,66,00,66,00,00,00,00 DATA 00,00,00,00,00,00,66,66,66,66,66,00,00,00,00 DATA 00,00,00,00,00,00,00,66,00,66,00,00,00,00,00 DATA 00,00,00,00,00,00,02,02,02,02,02,00,00,00,00 DATA 00,00,00,00,00,02,00,02,02,02,00,02,00,00,00 DATA 00,00,00,00,00,02,00,02,02,02,00,02,00,00,00 DATA 00,00,00,00,00,66,00,02,02,02,00,66,00,00,00 DATA 00,00,00,00,02,00,00,07,00,07,00,00,02,00,00 DATA 00,00,00,00,00,02,02,02,00,02,02,02,00,00,00 'This is the mask for the sprite... DATA 255,255,255,255,255,255,10,10,10,10,255,255,255,255,255 DATA 255,255,255,255,255,10,10,10,10,10,10,255,255,255,255 DATA 255,255,255,10,10,66,10,10,10,10,10,66,255,255,255 DATA 255,255,15,255,255,66,66,66,66,66,66,66,255,255,255 DATA 255,255,255,255,255,255,66,00,66,00,66,255,255,255,255 DATA 255,255,255,255,255,255,66,66,66,66,66,255,255,255,255 DATA 255,255,255,255,255,255,255,66,00,66,255,255,255,255,255 DATA 255,255,255,255,255,255,02,02,02,02,02,255,255,255,255 DATA 255,255,255,255,255,02,255,02,02,02,255,02,255,255,255 DATA 255,255,255,255,255,02,255,02,02,02,255,02,255,255,255 DATA 255,255,255,255,255,66,255,02,02,02,255,66,255,255,255 DATA 255,255,255,255,02,255,255,07,255,07,255,255,02,255,255 DATA 255,255,255,255,255,02,02,02,255,02,02,02,255,255,255 '---- STOP '---- STOP ----------------------------------------------------------------------------- OK!! Now you know how to move in your own world... Now what? BATTLE!!!!! This will be done using the random command (RND) first you must put this command RANDOMIZE TIMER what this does is reset everything so you won't get the same thing every time you use it... next, put this command in... rx = int(rnd* 1000000) if rx = 15 then print "TIME FOR A BATTLE" ' All together '--- copy this to a new qbasic file... RANDOMIZE TIMER DO rx = INT(RND * 1000000) IF rx = 153 THEN PRINT "TIME FOR A BATTLE": END LOOP '--- STOP... This is one way of making a random battle... This isn't the way I do it. When the world is drawn, I mark out certain tiles that hold a bad guy... that way I can control how many bad guys are in a certain level... I won't explain this, I am sure you can figure it out on your own... I will give you an example though... I will try to explain as I go along. !!!!!!!!!!!! NOTICE: This is a very crapy demo on fighting... There is no actual battle. !!!!!!!!!!!! '----- START DIM guy(50), guysh(50), enemyx(100), enemyy(100) DIM sprite1(50), sprite2(50), sprite3(50) DIM map1(21, 15) SCREEN 13 guyx = 20 guyy = 8 goodlife = 100 '!*!*!*!*!*!*!*!*! 'This is the amount of enemies in a game and randomizes the timer... RANDOMIZE TIMER enemies = 20 '!*!*!*!*!*!*!*!*! 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 CLS FOR y = 1 TO 15 FOR x = 1 TO 21 READ map1(x, y) NEXT: NEXT FOR y = 1 TO 13 FOR x = 1 TO 15 READ clr PSET (x, y), clr NEXT: NEXT GET (1, 1)-(15, 13), guy FOR y = 1 TO 13 FOR x = 1 TO 15 READ clr PSET (x, y), clr NEXT: NEXT GET (1, 1)-(15, 13), guysh CLS '!*!*!*!*!*!*!*!*! 'this gives a point to return to when the battle is over... 10 '!*!*!*!*!*!*!*!*! 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 PUT (guyx * 15 - 15, guyy * 13 - 13), guysh, AND PUT (guyx * 15 - 15, guyy * 13 - 13), guy, OR '!*!*!*!*!*!*!*!*! 'this gets random positions for each of the enemies... FOR i = 1 TO enemies enemyx(i) = INT(RND * 21) enemyy(i) = INT(RND * 15) NEXT '!*!*!*!*!*!*!*!*! DO press$ = INKEY$ IF press$ = CHR$(0) + CHR$(75) AND map1(guyx - 1, guyy) <> 3 THEN IF guyx > 1 THEN guyx = guyx - 1 END IF IF press$ = CHR$(0) + CHR$(77) AND map1(guyx + 1, guyy) <> 3 THEN IF guyx < 20 THEN guyx = guyx + 1 END IF IF press$ = CHR$(0) + CHR$(72) AND map1(guyx, guyy - 1) <> 3 THEN IF guyy > 1 THEN guyy = guyy - 1 END IF IF press$ = CHR$(0) + CHR$(80) AND map1(guyx, guyy + 1) <> 3 THEN IF guyy < 14 THEN guyy = guyy + 1 END IF IF oldguyx <> guyx OR oldguyy <> guyy THEN oldguyx = guyx oldguyy = guyy FOR y = 1 TO 15 FOR x = 1 TO 21 IF map1(x, y) = 1 THEN PUT (x * 15 - 15, y * 13 - 13), sprite1, PSET IF map1(x, y) = 2 THEN PUT (x * 15 - 15, y * 13 - 13), sprite2, PSET IF map1(x, y) = 3 THEN PUT (x * 15 - 15, y * 13 - 13), sprite3, PSET NEXT: NEXT PUT (guyx * 15 - 15, guyy * 13 - 13), guysh, AND PUT (guyx * 15 - 15, guyy * 13 - 13), guy, OR END IF '!*!*!*!*!*!*!*!*! FOR i = 1 TO enemies IF enemyx(i) = guyx AND enemyy(i) = guyy THEN GOSUB BaTtLes NEXT '!*!*!*!*!*!*!*!*! 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 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 DATA 00,00,00,00,00,00,10,10,10,10,00,00,00,00,00 DATA 00,00,00,00,00,10,10,10,10,10,10,00,00,00,00 DATA 00,00,00,10,10,66,10,10,10,10,10,66,00,00,00 DATA 00,00,15,00,00,66,66,66,66,66,66,66,00,00,00 DATA 00,00,00,00,00,00,66,00,66,00,66,00,00,00,00 DATA 00,00,00,00,00,00,66,66,66,66,66,00,00,00,00 DATA 00,00,00,00,00,00,00,66,00,66,00,00,00,00,00 DATA 00,00,00,00,00,00,02,02,02,02,02,00,00,00,00 DATA 00,00,00,00,00,02,00,02,02,02,00,02,00,00,00 DATA 00,00,00,00,00,02,00,02,02,02,00,02,00,00,00 DATA 00,00,00,00,00,66,00,02,02,02,00,66,00,00,00 DATA 00,00,00,00,02,00,00,07,00,07,00,00,02,00,00 DATA 00,00,00,00,00,02,02,02,00,02,02,02,00,00,00 'This is the mask for the sprite... DATA 255,255,255,255,255,255,10,10,10,10,255,255,255,255,255 DATA 255,255,255,255,255,10,10,10,10,10,10,255,255,255,255 DATA 255,255,255,10,10,66,10,10,10,10,10,66,255,255,255 DATA 255,255,15,255,255,66,66,66,66,66,66,66,255,255,255 DATA 255,255,255,255,255,255,66,00,66,00,66,255,255,255,255 DATA 255,255,255,255,255,255,66,66,66,66,66,255,255,255,255 DATA 255,255,255,255,255,255,255,66,00,66,255,255,255,255,255 DATA 255,255,255,255,255,255,02,02,02,02,02,255,255,255,255 DATA 255,255,255,255,255,02,255,02,02,02,255,02,255,255,255 DATA 255,255,255,255,255,02,255,02,02,02,255,02,255,255,255 DATA 255,255,255,255,255,66,255,02,02,02,255,66,255,255,255 DATA 255,255,255,255,02,255,255,07,255,07,255,255,02,255,255 DATA 255,255,255,255,255,02,02,02,255,02,02,02,255,255,255 END BaTtLes: CLS PRINT "TIME TO BATTLE!" PRINT "press a key..." SLEEP CLS badlife = 100 PRINT "Your life is "; goodlife PRINT "The badguys life is"; badlife PRINT "He hurt you 35" goodlife = goodlife - 35 PRINT "your life is now"; goodlife IF goodlife <= 0 THEN PRINT "You lost!!!": END SLEEP GOTO 10 '------ STOPP! ----------------------------------------------------------------------------- One more tecnique that I should tell you about is how to change from map to map... What I would do is make another map file and name it MAP2(21,15) and then map3(21,15) and so on and so on.. when you reach a certain point on the map it should change over to this map. and so on and so on... ----------------------------------------------------------------------------- ***************************************************************************** ----------------------------------------------------------------------------- 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... 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 December 2 1999 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)