05-08-2003, 08:57 AM
One of the things I've found writing games in QBasic is that you can run out of room for stuff really fast. The more text you have in your program, i.e. every single
and every
uses up space in your program. Eventually, bad things will start happening.
So I suggest that if you're ever planning on writing game in QBasic, keep as much stuff out of the actual code as humanly possible!
Some things I did:
1. As early as possible, write a subroutine to print your text for you. Pass this routine a filename, and it will print the file. That way, ALL of your game text can be external to the program. Here's an example of one I used:
This may look a bit confusing, but here's what it essentially does:
1. opens up the file whose name is passed to it (filename$)
2. reads in the first line of text from the file (line input #9, text$)
3. goes through text$ one letter at a time, doing the following:
if the letter = "^" then change the COLOR of the text to whatever the two digits immediately following the "^" are. For example, "^01this will be in blue ^04but this will be in red"
if the letter = "&" then read in the three characters immediately after it, and print some value out. For example, &GPC will print the amount of gold your player is carrying. &NAM will print the character's name. &MON will print the name of the monster you're fighting. &NUM will print the number (n) that gets passed to the TT routine. This is useful for those random numbers, such as damage:
damagetaken = INT(RND * 10) + 1
TT "yourehit", damagetaken
and the file "yourehit" might look like this:
=================================
^04&MON ^07hits you for ^04&NUM ^07damage!
You have &HPC hit points remaining.
=================================
if the letter is anything other than "^" or "&" then print it to the screen without a carriage return.
4. at the end of each line, PRINT so that it goes to the next line
5. pause after each 21 lines (so that you can read text before it scrolls off the screen!)
6. continue reading lines until you reach the end of the file
Alright, now this may not be the fastest way to display text, but it gets ALL your text into external files, and it makes changing colors and displaying stats and so forth a real piece of cake!!
*peace*
Meg.
Code:
PRINT "You enter the room. Nothing important happens."
and every
Code:
PRINT MonsterName$ + " hit you for" + damage + " damage!"
uses up space in your program. Eventually, bad things will start happening.
So I suggest that if you're ever planning on writing game in QBasic, keep as much stuff out of the actual code as humanly possible!
Some things I did:
1. As early as possible, write a subroutine to print your text for you. Pass this routine a filename, and it will print the file. That way, ALL of your game text can be external to the program. Here's an example of one I used:
Code:
SUB TT (filename$, n)
OPEN "text\" + filename$ FOR INPUT AS #9
count = 0
DO
COLOR 15, 0
LINE INPUT #9, text$
skip = 0
count = count + 1
FOR t = 1 TO LEN(text$)
IF MID$(text$, t, 1) = "^" THEN 'change colors
COLOR(VAL(MID$(text$, t + 1, 2)), 0), 0
t = t + 2
ELSEIF MID$(text$, t, 1) = "&" THEN 'display special
SELECT CASE MID$(text$, t + 1, 3)
CASE "DAT" 'don't display this line of text (it's just a remark line)
count = count - 1
skip = 1
EXIT FOR
CASE "ITM" 'print the nth item in your inventory
PRINT itm$(i(n), id(n));
CASE "HPC" 'print current Health
PRINT MID$(STR$(PC.HP), 2);
CASE "HPM" 'print max health
PRINT MID$(STR$(PC.HPMax), 2);
CASE "SPC" 'print current magic
PRINT MID$(STR$(PC.SP), 2);
CASE "SPM" 'print max magic
PRINT MID$(STR$(PC.SPMax), 2);
CASE "NUM" 'print n (passed argument)
PRINT MID$(STR$(n), 2);
CASE "ROM" 'print current room
PRINT MID$(STR$(PC.Room), 2);
CASE "MOV" 'print remaining movement points
PRINT MID$(STR$(PC.Moves), 2);
CASE "MON" 'print name of current monster
PRINT mon$(m);
CASE "MHP" 'print monster's health
PRINT MID$(STR$(MonHP), 2);
CASE "NAM" 'print character name
PRINT SB$(PC.CName);
CASE "GPC" 'print current gold amount
PRINT MID$(STR$(PC.Gold), 2);
CASE "LEV" 'print current level
PRINT MID$(STR$(PC.Level), 2);
CASE "EXP" 'print experience points
PRINT MID$(STR$(PC.XP), 2);
END SELECT
t = t + 3
ELSE
PRINT MID$(text$, t, 1);
END IF
NEXT t
IF skip = 0 THEN
PRINT
COLOR 15, 0
END IF
IF count = 21 THEN 'pause the screen
DO: LOOP UNTIL INKEY$ <> ""
count = 0
END IF
LOOP UNTIL EOF(9)
CLOSE #9
END SUB
This may look a bit confusing, but here's what it essentially does:
1. opens up the file whose name is passed to it (filename$)
2. reads in the first line of text from the file (line input #9, text$)
3. goes through text$ one letter at a time, doing the following:
if the letter = "^" then change the COLOR of the text to whatever the two digits immediately following the "^" are. For example, "^01this will be in blue ^04but this will be in red"
if the letter = "&" then read in the three characters immediately after it, and print some value out. For example, &GPC will print the amount of gold your player is carrying. &NAM will print the character's name. &MON will print the name of the monster you're fighting. &NUM will print the number (n) that gets passed to the TT routine. This is useful for those random numbers, such as damage:
damagetaken = INT(RND * 10) + 1
TT "yourehit", damagetaken
and the file "yourehit" might look like this:
=================================
^04&MON ^07hits you for ^04&NUM ^07damage!
You have &HPC hit points remaining.
=================================
if the letter is anything other than "^" or "&" then print it to the screen without a carriage return.
4. at the end of each line, PRINT so that it goes to the next line
5. pause after each 21 lines (so that you can read text before it scrolls off the screen!)
6. continue reading lines until you reach the end of the file
Alright, now this may not be the fastest way to display text, but it gets ALL your text into external files, and it makes changing colors and displaying stats and so forth a real piece of cake!!
*peace*
Meg.