You'll need to update your tutorial folder to get the new programs and assets included with lesson 22.
I've attached the updated tutorial.zip asset file below. Simply move the tutorial folder found in the ZIP file to your QB64 folder. If you already have the tutorial folder allow the files to be overwritten.
One feature that was added in the last release (that I haven't done a very good job of publicizing yet) that can help with troubleshooting is the Console library. This lets you write logging messages to the QBJS console window based on a log level. You can click the message in the log and it will take you to the corresponding line of code.
If you just want to print text to the console window and you don't really care about line numbers, you can use the Console.Echo method.
Jeez, I go away for a few days and poof, what happened? I tried running a program that worked fine last week and got compilation errors, so I rebooted. Then I tried running a game I've been working on and none of the sounds worked. I tried others, nothin. I tried just a BEEP program, nothin. All sounds outside of QB64 work as usual.
So I tried installing the latest version of QB64pe and still no sounds! What gives?
Sorry to be a pain (again), but
I'm trying to come to grips with "Fonty" stuff, and am a bit (a lot) puzzled by the results of this code:
Code: (Select All)
Screen _NewImage(1024, 820, 32) ' Screen Width is 1024 pixels
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", 24, "monospace")
_Font f&
' width of "X" on current screen
CpL = _DesktopWidth \ _PrintWidth("X") ' chars per line on current screen
Print "Width of X is"; _PrintWidth("X"); ", and Chars per Line is"; CpL
Locate 10, 10
Print String$(CpL, "X");
Sleep
I would expect it to print a single, full line of X's. But it doesn't. I think it's to do with the font I've selected,
but I thought _PrintWidth considered that. Does it?
I modified my Hocus Pocus particle fountain to use a hardware surface and hardware images only. I also made a few optimizations to the code to make it faster. I originally wrote this back in 2014 and have learned a few tricks since then. I'll be including this in Lesson 22 of the tutorial as an example program.
The background music file is included below in a ZIP file. You really need the music to make the program pop.
Simply move the mouse around and watch the magic happen. ESC to exit.
Ugh - never fails - had a bug - it's fixed in the code below.
Code: (Select All)
'*
'* Hocus Pocus V2.3 by Terry Ritchie 09/17/23
'* Original 01/24/14
'* Updated 08/18/22 to reflect the new tutorial
'* Updated 09/17/23 to use hardware images for Lesson 22
'* Open source code - freely share and modify
'*
'* Use the mouse to create magic. Press ESC to leave this magical place.
'*
CONST FALSE = 0 ' truth detector
CONST TRUE = NOT FALSE ' truth detector
CONST SWIDTH = 640 ' screen width
CONST SHEIGHT = 480 ' screen height
CONST BLOOMAMOUNT = 5 ' number of blooms per mouse movement (don't go too high!)
CONST MAXSIZE = 64 ' maximum size of blooms (don't go too high!)
CONST MAXLIFE = 32 ' maximum life time on screen
CONST MAXXSPEED = 6 ' maximum horizontal speed at bloom creation
CONST MAXYSPEED = 10 ' maximum vertical speed at bloom creation
CONST BOUNCE = FALSE ' set to TRUE to have blooms bounce off bottom of screen
CONST FLUFFY = FALSE ' set to TRUE to have blooms fluffier in appearance
TYPE CADABRA ' image properties
lifespan AS INTEGER ' life span of bloom on screen
x AS SINGLE ' x location of bloom
y AS SINGLE ' y location of bloom
size AS SINGLE ' size of bloom
xdir AS SINGLE ' horizontal direction of bloom
ydir AS SINGLE ' vertical direction of bloom
xspeed AS SINGLE ' horizontal speed of bloom
yspeed AS SINGLE ' vertical speed of bloom
image AS LONG ' bloom hardware image handle
END TYPE
REDIM Abra(0) AS CADABRA ' dynamic array to hold properties
DIM x AS INTEGER ' current x position of mouse
DIM y AS INTEGER ' current y position of mouse
DIM Oldx AS INTEGER ' previous x position of mouse
DIM Oldy AS INTEGER ' previous y position of mouse
DIM Blooms AS INTEGER ' bloom counter
DIM sa AS LONG ' Sorcerer's Apprentice sound file
'----------------------------
'- Main Program Begins Here -
'----------------------------
_DISPLAYORDER _HARDWARE
SCREEN _NEWIMAGE(SWIDTH, SHEIGHT, 32) ' create 32 bit graphics screen
_SCREENMOVE _MIDDLE ' move window to center of desktop
sa = _SNDOPEN("apprentice.ogg") ' load sound file into RAM
_SNDLOOP sa ' play music in continuous loop
_MOUSEHIDE ' hide the mouse pointer
_MOUSEMOVE SWIDTH * .5, SHEIGHT * .5 ' move mouse pointer to middle of screen
WHILE _MOUSEINPUT: WEND ' get latest mouse information
Oldx = _MOUSEX ' remember mouse x position
Oldy = _MOUSEY ' remember mouse y position
RANDOMIZE TIMER ' seed random number generator
DO ' begin main loop
_LIMIT 60 ' 60 frames per second
WHILE _MOUSEINPUT: WEND ' get latest mouse information
x = _MOUSEX ' get current mouse x position
y = _MOUSEY ' get current mouse y position
IF (Oldx <> x) OR (Oldy <> y) THEN ' has mouse moved since last loop?
Blooms = BLOOMAMOUNT ' yes, get number of blooms to make
WHILE Blooms > 0 ' begin bloom creation loop
HOCUS x, y ' create bloom at current mouse location
Blooms = Blooms - 1 ' decrement bloom counter
WEND
Oldx = x ' remember mouse x position
Oldy = y ' remember mouse y position
END IF
POCUS ' draw active blooms
_DISPLAY ' update screen with changes
LOOP UNTIL _KEYDOWN(27) ' leave when ESC pressed
_SNDSTOP sa ' stop background music
_SNDCLOSE sa ' remove music from RAM
SYSTEM ' return to operating system
'*
'* Maintains the bloom array by creating bloom properties for a new bloom.
'* If no array indexes are free a new one is added to the end of the array to
'* hold the new bloom. If an unused index is available the new bloom will occupy
'* that free index position.
'*
'* hx - x location of new bloom
'* hy - y location of new bloom
'*
SHARED Abra() AS CADABRA ' need access to bloom array
DIM Radius AS INTEGER ' radius value when drawing blooms
DIM Index AS INTEGER ' array index to create new bloom in
DIM Red AS INTEGER ' red color component of bloom
DIM Green AS INTEGER ' green color component of bloom
DIM Blue AS INTEGER ' blue color component of bloom
DIM RedStep AS INTEGER ' red fade amount
DIM GreenStep AS INTEGER ' green fade amount
DIM BlueStep AS INTEGER ' blue fade amount
DIM AlphaStep AS INTEGER ' alpha fade amount
DIM Alpha AS INTEGER ' alpha amount at current radius
DIM TempImage AS LONG ' temporary software image
Index = 0 ' reset index counter
DO ' begin free index search
IF Abra(Index).lifespan = 0 THEN EXIT DO ' leave loop if index is free
Index = Index + 1 ' increment index counter
LOOP UNTIL Index > UBOUND(Abra) ' leave loop when all indexes checked
IF Index > UBOUND(Abra) THEN REDIM _PRESERVE Abra(Index) AS CADABRA ' increase array size by 1 if no index free
Abra(Index).lifespan = RND * MAXLIFE + 16 ' length of time to live (frames)
Abra(Index).x = hx ' bloom x location
Abra(Index).y = hy ' bloom y location
Abra(Index).size = RND * MAXSIZE + 5 ' size of bloom
Abra(Index).xdir = (RND - RND) * 3 ' horizontal direction of bloom
Abra(Index).ydir = -RND ' vertical direction of bloom (up)
Abra(Index).xspeed = RND * MAXXSPEED ' horizontal speed of bloom
Abra(Index).yspeed = RND * MAXYSPEED ' vertical speed of bloom
Red = RND * 256 ' red component value
Green = RND * 256 ' green compoenent value
Blue = RND * 256 ' blue component value
RedStep = (255 - Red) \ Abra(Index).size ' fade of red component
GreenStep = (255 - Green) \ Abra(Index).size ' fade of green component
BlueStep = (255 - Blue) \ Abra(Index).size ' fade of blue component
AlphaStep = 255 \ Abra(Index).size ' fade of alpha channel
Alpha = 0 ' start alpha channel transparent
TempImage = _NEWIMAGE(Abra(Index).size * 2, Abra(Index).size * 2, 32) ' create temporary software image
_DEST TempImage ' draw on temporary image
Radius = Abra(Index).size ' start from outside of bloom working in
DO WHILE Radius > 0 ' start bloom drawing loop
CIRCLE (Abra(Index).size, Abra(Index).size), Radius, _RGB32(Red, Green, Blue)
IF FLUFFY THEN PAINT (Abra(Index).size, Abra(Index).size), _RGB32(Red, Green, Blue), _RGB32(Red, Green, Blue)
_SETALPHA Alpha, _RGB32(Red, Green, Blue) ' set transparency level of current color
Red = Red + RedStep ' increase red component
Green = Green + GreenStep ' increase green component
Blue = Blue + BlueStep ' increase blue component
Alpha = Alpha + AlphaStep ' increase opacity level of alpha channel
Radius = Radius - 1 ' decrease size of circle
LOOP ' leave loop when smallest circle drawn
Abra(Index).image = _COPYIMAGE(TempImage, 33) ' create a hardware image
_DEST 0 ' leave temp image so it can be freed
_FREEIMAGE TempImage ' temporary software image no longer needed
'*
'* places active blooms onto the hardware screen and updates their
'* position, size and speed
'*
SHARED Abra() AS CADABRA ' need access to bloom array
DIM Index AS INTEGER ' array index counter
Index = UBOUND(Abra) ' start at top of array
WHILE Index > -1 ' is index > -1?
IF Abra(Index).lifespan THEN ' yes, is this bloom active?
Abra(Index).lifespan = Abra(Index).lifespan - 1 ' yes, decrement lifespan of bloom
Abra(Index).size = Abra(Index).size * .98 ' decrease size of bloom slightly
Abra(Index).x = Abra(Index).x + Abra(Index).xdir * Abra(Index).xspeed ' update x position of bloom
Abra(Index).y = Abra(Index).y + Abra(Index).ydir * Abra(Index).yspeed ' update y position of bloom
Abra(Index).xspeed = Abra(Index).xspeed * .9 ' decrease x velocity slightly
Abra(Index).yspeed = Abra(Index).yspeed - .5 ' decrease y velocity (gravity)
IF Abra(Index).y > SHEIGHT THEN ' has bloom left bottom of screen?
IF BOUNCE THEN ' yes, should bloom bounce?
Abra(Index).yspeed = -Abra(Index).yspeed ' yes, reverse y velocity
ELSE ' no
Abra(Index).lifespan = 0 ' bloom is no longer needed
END IF
END IF
_PUTIMAGE (Abra(Index).x - Abra(Index).size, Abra(Index).y - Abra(Index).size)-_
(Abra(Index).x + Abra(Index).size, Abra(Index).y + Abra(Index).size), Abra(Index).image
IF Abra(Index).lifespan = 0 THEN _FREEIMAGE Abra(Index).image ' free image if life of bloom has ended
END IF
Index = Index - 1 ' decrement array index counter
WEND
Should it be (or is it already) mentioned in the Wiki, that Dim var(num of elements) allows element 0, as well as the number of elements dimmed ?
So Dim var(10) actually allocates 11 element positions, not 10. (Or does it)?
This may become significant for memory usage with multi-dimensional arrays:
Dim var(10, 1000) would occupy space for about 11 * 1001 units (11011), not 10000 as I would expect.
One of the Qbasic gurus in the '90's that I learned the most from was Kurt Kuzba. I saved everything he shared. Kurt was a great programmer and generous with his Qbasic knowledge. Back in 1997 he posted a text game on the FidoNet QUIK_BAS Echo called THEWOODS.BAS. It's a bare-bones text adventure that is great for learning and expanding on. I thought I'd update it to QB64 and see where it could go. More monsters and side adventures walking the woods would be a good addition, and another goal than reaching 2000 experience points, like defeating a dragon, would be better ending.
Here's where it is so far. It includes a built-in font with it so the text can easy to read on any desktop size.
- Dav
Code: (Select All)
'=====================
'THEWOODS-MODIFIED.BAS
'=====================
'A modified version of THEWOODS.BAS by Kurt Kuzba that he
'placed in public domain and encouraged others to build on.
'It's a text adventure game in the classic BBS game style.
'Kurt posted it on the FidoNet QUIK_BAS Echo back in 1997.
'You can find the original THEWOODS.BAS in the ABC packets.
'Kurt, thanks for the game - If you're still out there,
'Come back to the BASIC scene! You'll love QB64!
'Modified by Dav for QB64-PE 3.8, SEP/2023
Dim Shared q$: q$ = Chr$(34)
Dim Shared PlayerName$, PlayerHits&, PlayerMagic&, PlayerStrength&
Dim Shared PlayerGold&, PlayerWeapon%, PlayerExperience&
Dim Shared EnemyName$, EnemyHits&, EnemyMagic&, EnemyStrength&
Dim Shared EnemyGold&, EnemyWeapon%, EnemyExperience&
Color _RGB(255, 255, 255), _RGB(32, 32, 128) 'Standard Text color
Color _RGB(255, 255, 0)
Print
Print " -= Welcome to THE WOODS =-"
Print
Color _RGB(255, 255, 255)
Print " Terrible beasts are roaming the nearby woods."
Print " People in town live in constant fear of what "
Print " lurks beyond the town gate. Those who decide"
Print " to venture out seldom return. Something must"
Print " be done. Someone must save the town."
Print
Print " You have decided to be the brave hero and to"
Print " eliminate the evil inhabiting the woods. It"
Print " will NOT be easy however. You will face many"
Print " malevolent forces, many dark and evil beasts."
Print
Print " Go into the woods, hunt down the beasts until"
Print " you reach 2,000 experience points to win."
Print
Color _RGB(255, 255, 0)
Input " Your name? ", plyr$
YourStats 'Show you stats at the beginning of the game
'the main game play loop
Do
If PlayerHits& > 0 Then
Print
If menu% > 0 Then
Color _RGB(255, 255, 255)
Print " You're in the middle of town. What now?"
Print
Print " (W)oods - Enter the woods."
Print " (H)ealer - Heal your wounds."
Print " (A)rmory - Buy/Sell a weapon."
Print " (S)tats - See your stats."
Print " (Q)uit - Quit game."
End If
Print
Print " [W/H/A/S/Q/?]";
Select Case WaitKey%(" WHASQ?")
Case 2: Woods
Case 3: Healer
Case 4: Armory
Case 5: YourStats
Case 6: Print: Print
Print " Quit this quest? (YN)? ";
If WaitKey%(" YN") = 2 Then Exit Do
Case 7: Print: menu% = 1
End Select
Else
Color _RGB(255, 200, 200)
If PlayerExperience& < 2000 Then
Print
Print " Sorry... You have perished in battle."
For t% = 200 To 150 Step -1: Sound t%, .1: Next
Else
Print
Print " You have defeated all enemies! You WIN!!"
For t% = 100 To 999 Step 10: Sound t%, .03: Next
For t% = 1000 To 500 Step -10: Sound t%, .03: Next
End If
Print " You had"; PlayerExperience&; "points."
Exit Do
End If
Loop
Color _RGB(255, 255, 0)
Print: Print " Would you like to play again (YN)? ";
If WaitKey%(" YN") = 2 Then GoTo Restart
End If
Print: Print " Goodbye, then..."
Sleep 2
System
Sub Armory
Dim price(1 To 8) As Integer
price(1) = 75
price(2) = 200
price(3) = 400
price(4) = 600
price(5) = 900
price(6) = 1500
price(7) = 2500
price(8) = 4000
Do
Cls
Print
Print "---------------------------------------------------"
Print " -==**[ Jake's Weapon Shop ]**==- "
Print "---------------------------------------------------"
Print
Print " Welcome to Jake's. We only sell the finest."
Print " Jake looks you over suspiciously and asks..."
Print " Do you want to (B)uy or (S)ell?"
Print
Print " [B/S or ENTER to leave] "
Print
Select Case WaitKey%(" SBQ" + Chr$(13))
Case 2
money% = PlayerWeapon% * 30
If money% = 0 Then
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " Sell what? You're not carrying anything!"
Print " Come back when you have something valuable."
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
Exit Sub
Else
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " Hmm...I'll give you"; money%; "gold for ";
Print RTrim$(Weapon$(PlayerWeapon%)); "."
Print " Is it a deal (Y/N)? ";
Print "---------------------------------------------------"
Print
Color _RGB(255, 255, 255)
k% = WaitKey%(" YN")
Print
If k% = 2 Then
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " Great! Here's your money. Now go away."
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
PlayerGold& = PlayerGold& + money%
PlayerWeapon% = 0
Exit Sub
End If
End If
Case 3
Print "--------------==**[ PRICES ]**==-----------------"
Print
For t% = 1 To 8: Print Str$(t%); "->";
Print " "; Left$(Str$(price(t%)) + " ", 6);
Print " "; Weapon$(t%)
Next
Print
Print " You have"; PlayerGold&; "gold. Which one you want (1-8)?"
Print " (Hit ENTER to buy nothing)"
k% = WaitKey%(" 12345678" + Chr$(13))
k% = k% - 1
If k% < 9 Then
money% = k% * 90
If money% > PlayerGold& Then
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You can't afford "; RTrim$(Weapon$(k%)); "."
Print " Come back when you have more gold."
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
Exit Sub
Else
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " Sold! Good luck with "; RTrim$(Weapon$(k%)); "."
Print " Close the door on your way out."
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
PlayerGold& = PlayerGold& - money%
PlayerWeapon% = k%
Exit Sub
End If
End If
Case 4, 5:
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " Ok, maybe next time, says Jake with a grumble."
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
Exit Sub
End Select
Loop: End Sub
Sub FightMonster
level% = GetLevel%(PlayerExperience&)
MakeEnemy level%
EnemyName$ = RTrim$(EnemyName$)
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You came upon a "; RTrim$(EnemyName$); "!"
Print "---------------------------------------------------"
menu% = 1
While (PlayerHits& > 0) And (EnemyHits& > 0)
If menu% > 0 Then
Print
Print " (F)ight! (Y)our Stats "
Print " (R)un Away (V)iew Enemy "
Print " (S)urrender"
End If
Print
Color _RGB(255, 200, 200)
Print PlayerHits&;
Print PlayerName$
Print EnemyHits&;
Print EnemyName$
Print
Color _RGB(255, 255, 255)
Print " [F/R/S/Y/V/?] "
If Rnd > .5 Then
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You move fast and hit first."
hits% = PlayerAtt! / EnemyDef!
If hits% > EnemyHits& Then hits% = EnemyHits&
EnemyHits& = EnemyHits& - hits%
Print " You hit for"; hits%; "points."
PlayerExperience& = PlayerExperience& + hits%
If EnemyHits& > 0 Then
hits% = EnemyAtt! / PlayerDef!
If hits% > PlayerHits& Then hits% = PlayerHits&
PlayerHits& = PlayerHits& - hits%
Print " You are hit for"; hits%; "points."
End If
Print "---------------------------------------------------"
Else
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You move slow and get hit first."
hits% = EnemyAtt! / PlayerDef!
If hits% > PlayerHits& Then hits% = PlayerHits&
PlayerHits& = PlayerHits& - hits%
Print " You are hit for"; hits%; "points."
If PlayerHits& > 0 Then
hits% = PlayerAtt! / EnemyDef!
If hits% > EnemyHits& Then hits% = EnemyHits&
EnemyHits& = EnemyHits& - hits%
PlayerExperience& = PlayerExperience& + hits%
Print " You hit for"; hits%; "points."
End If
Print "---------------------------------------------------"
End If
If EnemyHits& = 0 Then
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You have defeated the "; RTrim$(EnemyName$)
Print "---------------------------------------------------"
PlayerMagic& = PlayerMagic& + EnemyMagic& \ 10
PlayerGold& = PlayerGold& + EnemyGold&
menu% = 1
End If
If PlayerHits& = 0 Then
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You were defeated by "; RTrim$(EnemyName$)
Print "---------------------------------------------------"
End If
Case 3
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You manage to escape, but all your strength"
Print " and magic are lost, and some experience points."
Print "---------------------------------------------------"
PlayerMagic& = 0
PlayerStrength& = 0
PlayerExperience& = PlayerExperience& * .9
menu% = 1
Color _RGB(255, 255, 255)
Exit Sub
Case 4
Color _RGB(255, 255, 0)
Print
Print "---------------------------------------------------"
Print " You give all your gold to "; RTrim$(EnemyName$);
Print " Being broke is better than dying I suppose..."
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
menu% = 1
PlayerGold& = 0: Exit Sub
Case 5: YourStats
Case 6: EnemyStats
Case 7: menu% = 1
End Select
Wend
End Sub
Function GetLevel% (e&)
Select Case e&
Case Is < 100: level% = 1
Case 101 To 500: level% = 2
Case Else: level% = 3
End Select
GetLevel% = level%
End Function
Sub Healer
Totalhits% = PlayerExperience& \ 10 + 30
ToHeal% = Totalhits% - PlayerHits&
Cls
Color _RGB(255, 200, 200)
Print
Print "---------==**[ HARRY THE HEALER ]**==------------"
Print
Print " Welcome friend. Let me heal your wounds and soul."
If ToHeal% <= 0 Then
Print
Print " Harry looks you over completely and says,"
Print " You don't require healing, friend. Goodbye..."
Else
Print
Print " Each hit point costs 3 gold to heal."
Print " You can afford to heal"; PlayerGold& \ 3; "hit points."
Print " To max out, You need to heal"; RTrim$(Str$(ToHeal%)); "."
Print
Input " How many would you heal? (ENTER for max) ", heal%
If heal% = 0 Then heal% = ToHeal%
If heal% > ToHeal% Then heal% = ToHeal%
If heal% > (PlayerGold& \ 3) Then heal% = PlayerGold& \ 3
PlayerHits& = PlayerHits& + heal%
PlayerGold& = PlayerGold& - (heal% * 3)
Print
Print " I have healed you for"; heal%; "hit points."
Print " Go in peace my son..."
Print
End If
Print "---------------------------------------------------"
Color _RGB(200, 200, 255)
End Sub
Sub MakeEnemy (l%)
ReDim EN(1 To 3) As String
ReDim EP(1 To 3) As String
Sub YourStats ()
Cls
Color _RGB(255, 255, 0)
Print "------------==**[ YOUR STATS ]**==---------------"
Print " Name : "; PlayerName$
Print " Hits :"; PlayerHits&
Print " Magic :"; PlayerMagic&
Print " Strength :"; PlayerStrength&
Print " Gold :"; PlayerGold&
Print " Weapon : "; Weapon$(PlayerWeapon%)
Print " Experience :"; PlayerExperience&
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
End Sub
Sub EnemyStats ()
Cls
Color _RGB(255, 255, 0)
Print "------------==**[ ENEMY STATS ]**==--------------"
Print " Name : "; EnemyName$
Print " Hits :"; EnemyHits&
Print " Magic :"; EnemyMagic&
Print " Strength :"; EnemyStrength&
Print " Gold :"; EnemyGold&
Print " Weapon : "; Weapon$(EnemyWeapon%)
Print " Experience :"; EnemyExperience&
Print "---------------------------------------------------"
Color _RGB(255, 255, 255)
End Sub
Sub UseMagic
Print
Print
Do
Color _RGB(255, 255, 100)
Print
Print "------------==**[ CAST A SPELL ]**==-------------"
Print
Print " (H)ealing Spell (requires 4 magic points)"
Print " (S)trength Spell (requires 9 magic points)"
Print " (Q)uit this menu"
Print
Print " You have"; PlayerMagic&; "magic points."
Print "---------------------------------------------------"
Print
Print " [H/S/Q]"
k% = WaitKey%(" HSQ" + Chr$(13))
Print
Select Case k%
Case 2
If PlayerMagic& < 4 Then
Print "---------------------------------------------------"
Print " You don't have enough magic points for that!"
Print "---------------------------------------------------"
Else
m% = 1 + Rnd * 9
PlayerMagic& = PlayerMagic& - 4
PlayerHits& = PlayerHits& + m%
Print "---------------------------------------------------"
Print " Your spell yields"; m%; "hits."
Print "---------------------------------------------------"
End If
Case 3
If PlayerMagic& < 9 Then
Print "---------------------------------------------------"
Print " You don't have enough magic points for that!"
Print "---------------------------------------------------"
Else
m% = 1 + Rnd * 9
PlayerMagic& = PlayerMagic& - 9
PlayerStrength& = PlayerStrength& + m%
Print "---------------------------------------------------"
Print " Your spell yields"; m%; "strength."
Print "---------------------------------------------------"
End If
Case 4, 5: Color _RGB(255, 255, 255): Exit Sub
End Select
Loop
End Sub
Sub WalkInWoods
Select Case (Rnd * 99)
Case 0 To 9
rndgold = Int(Rnd * 15) + 2
PlayerGold& = PlayerGold& + rndgold
Color _RGB(255, 255, 0)
Print: Print " Lucky you! You found"; rndgold; "pieces of gold!"
Color _RGB(255, 255, 255)
Case 10 To 19
PlayerMagic& = PlayerMagic& + 1
Color _RGB(100, 255, 100)
Print: Print " A nice faerie gives you one magic point!"
Color _RGB(255, 255, 255)
Case 20 To 29: m% = 1 + Rnd * 9
PlayerHits& = PlayerHits& + m%
Color _RGB(100, 200, 255)
Print: Print " A friendly Elf heals you"; m%; "hit point";
If m% = 1 Then Print "!": Else Print "s!"
Color _RGB(255, 255, 255)
Case 30 To 89
Print: Print " The path continues before you. Now what?"
Case Else: FightMonster
End Select
End Sub
Function Weapon$ (w%)
Select Case w%
Case 0: Weapon$ = "Your Bare Hands"
Case 1: Weapon$ = "A Stick"
Case 2: Weapon$ = "A Quarterstaff"
Case 3: Weapon$ = "A Small Knife"
Case 4: Weapon$ = "A Big Knife"
Case 5: Weapon$ = "A Machete"
Case 6: Weapon$ = "A Shortsword"
Case 7: Weapon$ = "A Longsword"
Case 8: Weapon$ = "A Two-Handed Sword"
End Select
End Function
Sub Woods
menu% = 1
Do
level% = GetLevel%(PlayerExperience&)
If PlayerExperience& > 2000 Then PlayerHits& = 0
Print
If PlayerHits& = 0 Then Exit Sub
If menu% <> 0 Then
Color _RGB(255, 255, 255)
Print
Print " You're in the woods, alone. Now what?"
Print
Print " (C)ontinue .....Walk the path."
Print " (T)own .........Go Back to town."
Print " (S)pell.........Cast a Spell."
Print " (Y)our Stats....Show your stats."
Print
End If
menu% = 0
Print " [C/S/T/Y/?] "
k% = WaitKey%(" CTSY?")
Select Case k%
Case 2 'Pressed Continue walking...
Select Case (Rnd * 99)
Case 0 To 9 'found gold
rndgold = Int(Rnd * 15) + 2
PlayerGold& = PlayerGold& + rndgold
Color _RGB(255, 255, 0)
Print: Print " Lucky you! You found"; rndgold; "pieces of gold!"
Color _RGB(255, 255, 255)
Case 10 To 19 'faerie magic
PlayerMagic& = PlayerMagic& + 1
Color _RGB(100, 255, 100)
Print: Print " A nice faerie gives you one magic point!"
Color _RGB(255, 255, 255)
Case 20 To 29 'elf heals you
m% = 1 + Rnd * 9
PlayerHits& = PlayerHits& + m%
Color _RGB(100, 200, 255)
Print: Print " A friendly Elf heals you"; m%; "hit point";
If m% = 1 Then Print "!": Else Print "s!"
Color _RGB(255, 255, 255)
Case 30 To 89 'nothing, you just continue
Print: Print " The path continues before you. Now what?"
Case Else 'Monster fight!
FightMonster: menu% = 1
End Select
Case 3: Exit Sub 'back to town
Case 4: UseMagic: menu% = 1 'you use your magic
Case 5: YourStats 'show your stats
Case 6: menu% = 1 'Pressed ? for help
End Select
Loop
End Sub
Function WaitKey% (keys$)
Do
k% = InStr(keys$, UCase$(InKey$))
Loop While k% < 2
WaitKey% = k%
End Function