'Blubber Dragon BLUBBER2.BAS NoEMS
'$INCLUDE: 'BLUBBERD\DECLARS.BAS'
'$INCLUDE: 'DEXTERN.BI'

'$DYNAMIC

'Palette
DIM SHARED Pal AS STRING * 786

REM $STATIC
DEFSNG A-Z
SUB CURSOR

CursorAnim% = CursorAnim% + 1: IF CursorAnim% > 39 THEN CursorAnim% = 0

'Playing Cursor
IF CursorType% = 0 AND NoMouse% = 0 THEN DQBellipse READY, DQBmouseX, DQBmouseY, 5, 5, INT(RND * 255) + 1

IF CursorType% > 0 THEN
IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\OTHER\OBJ.BMP", Pal, 0, 0) THEN QUIT
END IF

'Draco Walking Cursor
IF CursorType% = 1 THEN
IF CursorAnim% < 10 THEN DQBxput TEMPLAYER, 290, 0, 319, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 10 AND CursorAnim% < 20 THEN DQBxput TEMPLAYER, 290, 31, 319, 60, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 20 AND CursorAnim% < 30 THEN DQBxput TEMPLAYER, 290, 0, 319, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 30 THEN DQBxput TEMPLAYER, 290, 62, 319, 91, READY, DQBmouseX, DQBmouseY
END IF
'Devon Walking Cursor
IF CursorType% = 2 THEN
IF CursorAnim% < 10 THEN DQBxput TEMPLAYER, 259, 0, 288, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 10 AND CursorAnim% < 20 THEN DQBxput TEMPLAYER, 259, 31, 288, 60, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 20 AND CursorAnim% < 30 THEN DQBxput TEMPLAYER, 259, 0, 288, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 30 THEN DQBxput TEMPLAYER, 259, 62, 288, 91, READY, DQBmouseX, DQBmouseY
END IF
'Gilbert Walking Cursor
IF CursorType% = 3 THEN
IF CursorAnim% < 10 THEN DQBxput TEMPLAYER, 228, 0, 257, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 10 AND CursorAnim% < 20 THEN DQBxput TEMPLAYER, 228, 31, 257, 60, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 20 AND CursorAnim% < 30 THEN DQBxput TEMPLAYER, 228, 0, 257, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 30 THEN DQBxput TEMPLAYER, 228, 62, 257, 91, READY, DQBmouseX, DQBmouseY
END IF
'Fat Draco Cursor
IF CursorType% = 4 THEN
IF CursorAnim% < 10 THEN DQBxput TEMPLAYER, 197, 0, 226, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 10 THEN DQBxput TEMPLAYER, 197, 31, 226, 60, READY, DQBmouseX, DQBmouseY
END IF
'Fat Draco2 Cursor
IF CursorType% = 5 THEN
DQBpset READY, DQBmouseX + INT(RND * 30), DQBmouseY + INT(RND * 15), 200
DQBpset READY, DQBmouseX + INT(RND * 30), DQBmouseY + INT(RND * 15), 200
DQBpset READY, DQBmouseX + INT(RND * 30), DQBmouseY + INT(RND * 15), 200
DQBxput TEMPLAYER, 197, 62, 226, 91, READY, DQBmouseX, DQBmouseY
END IF
'Flying Draco Cursor
IF CursorType% = 6 THEN
IF CursorAnim% < 10 THEN DQBxput TEMPLAYER, 166, 0, 195, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 10 AND CursorAnim% < 20 THEN DQBxput TEMPLAYER, 166, 31, 195, 60, READY, DQBmouseX, DQBmouseY - 1
IF CursorAnim% >= 20 AND CursorAnim% < 30 THEN DQBxput TEMPLAYER, 166, 0, 195, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 30 THEN DQBxput TEMPLAYER, 166, 31, 195, 60, READY, DQBmouseX, DQBmouseY - 1
END IF
'Flying Fat Draco Cursor
IF CursorType% = 7 THEN
IF CursorAnim% < 20 THEN DQBxput TEMPLAYER, 135, 0, 164, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 20 THEN DQBxput TEMPLAYER, 135, 31, 164, 60, READY, DQBmouseX, DQBmouseY - 1
END IF
'Inflating Gilbert Cursor
IF CursorType% = 8 THEN
IF CursorAnim% < 20 THEN DQBxput TEMPLAYER, 104, 0, 133, 29, READY, DQBmouseX, DQBmouseY
IF CursorAnim% >= 20 THEN DQBxput TEMPLAYER, 104, 31, 133, 60, READY, DQBmouseX, DQBmouseY
END IF

'Pointer
IF CursorType% > 0 THEN DQBxput TEMPLAYER, 92, 0, 98, 7, READY, DQBmouseX, DQBmouseY

END SUB

SUB DRAWPLAYER (jplay%)

'Draw character
'**************

JError$ = "Error in loading of character graphics!"

DRAWPLAYERAGAIN:

'Normal state & Losing weight
IF Player.FATTEN% <= 0 THEN
IF Player.FATTEN% < 0 THEN t% = INT(RND * 2): IF Player.PILL$ = "BOU" OR Player.PILL$ = "GAS" THEN t% = 0
IF t% = 1 THEN t% = 0: Player.FATTEN% = Player.FATTEN% + 1: Player.FAT% = Player.FAT% - 1
IF Player.FAT% < 0 THEN Player.FAT% = 0

PL% = TEMPLAYER
IF Player.FAT% < 100 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\1.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 100 AND Player.FAT% < 200 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\2.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 200 AND Player.FAT% < 300 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\3.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 300 AND Player.FAT% < 400 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\4.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 400 AND Player.FAT% < 500 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\5.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 500 AND Player.FAT% < 600 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\6.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 600 AND Player.FAT% < 700 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\7.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 700 AND Player.FAT% < 800 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\8.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 800 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\9.BMP", Pal, 0, 0) THEN QUIT
END IF

'Gaining weight
IF Player.FATTEN% > 0 THEN
t% = INT(RND * 2): IF Player.PILL$ = "BOU" OR Player.PILL$ = "GAS" THEN t% = 0
IF t% = 1 THEN t% = 0: Player.FATTEN% = Player.FATTEN% - 1: Player.FAT% = Player.FAT% + 1
IF Player.FAT% >= Player.MAXFAT% THEN Player.FAT% = Player.MAXFAT%: Player.FATTEN% = 0: GOTO DRAWPLAYERAGAIN

PL% = TEMPLAYER
IF Player.FAT% < 100 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\1P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 100 AND Player.FAT% < 200 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\2P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 200 AND Player.FAT% < 300 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\3P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 300 AND Player.FAT% < 400 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\4P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 400 AND Player.FAT% < 500 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\5P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 500 AND Player.FAT% < 600 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\6P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 600 AND Player.FAT% < 700 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\7P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 700 AND Player.FAT% < 800 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\8P.BMP", Pal, 0, 0) THEN QUIT
IF Player.FAT% >= 800 THEN IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\9.BMP", Pal, 0, 0) THEN QUIT
END IF

JTEMP% = READY
JX% = INT(Player.OX% / 10): JY% = Player.OY%

IF Player.INFLATE% = 1 THEN
DQBclearLayer TEMPLAYER2
JTEMP% = TEMPLAYER2
JX% = 0: JY% = 0
IF Player.PILL$ = "GAS" THEN t% = 200 - (99 + jplay%): JX% = 35: JY% = 65 - INT(t% / 3)
END IF

IF Player.INFLATE% < 2 THEN
'Right side
IF Player.DIRECTION% = 0 THEN
IF Player.FRAME% = 0 OR Player.FRAME% = 2 THEN
DQBxput PL%, 0, 0, 105, 49, JTEMP%, JX%, JY%
DQBxput PL%, 0, 50, 105, 98, JTEMP%, JX%, JY% + 50
END IF
IF Player.FRAME% = 1 THEN
DQBxput PL%, 107, 0, 212, 49, JTEMP%, JX%, JY%
DQBxput PL%, 107, 50, 212, 98, JTEMP%, JX%, JY% + 50
END IF
IF Player.FRAME% = 3 THEN
DQBxput PL%, 214, 0, 319, 49, JTEMP%, JX%, JY%
DQBxput PL%, 214, 50, 319, 98, JTEMP%, JX%, JY% + 50
END IF
END IF
'Left side
IF Player.DIRECTION% = 1 THEN
IF Player.FRAME% = 0 OR Player.FRAME% = 2 THEN
DQBxput PL%, 0, 100, 105, 149, JTEMP%, JX%, JY%
DQBxput PL%, 0, 150, 105, 198, JTEMP%, JX%, JY% + 50
END IF
IF Player.FRAME% = 1 THEN
DQBxput PL%, 107, 100, 212, 149, JTEMP%, JX%, JY%
DQBxput PL%, 107, 150, 212, 198, JTEMP%, JX%, JY% + 50
END IF
IF Player.FRAME% = 3 THEN
DQBxput PL%, 214, 100, 319, 149, JTEMP%, JX%, JY%
DQBxput PL%, 214, 150, 319, 198, JTEMP%, JX%, JY% + 50
END IF
END IF
END IF

END SUB

SUB GAME2 (jplay%)

'Part 1 - many things
IF jplay% = 0 THEN

'No Minus Score
IF Game.AddScore% < 0 THEN Game.AddScore% = 0

'Darken pill effect
IF Player.PILL$ = "DAR" THEN
DQBboxf TEMPLAYER, 0, 0, 319, 199, 246
IF Player.DIRECTION% = 0 THEN DQBellipse TEMPLAYER, FATX% + FATXP% - 2, FATY%, 50, 50, 1: DQBpaint TEMPLAYER, FATX% + FATXP% - 2, FATY%, 1: DQBpaint TEMPLAYER, FATX% + FATXP% - 2, FATY%, 0
IF Player.DIRECTION% = 1 THEN DQBellipse TEMPLAYER, FATX% + 2, FATY%, 50, 50, 1: DQBpaint TEMPLAYER, FATX% + 2, FATY%, 1: DQBpaint TEMPLAYER, FATX% + 2, FATY%, 0
DQBcopyTransLayer TEMPLAYER, READY: DQBclearLayer TEMPLAYER
END IF

'Information
'Special abilities left
IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\OTHER\OBJ.BMP", Pal, 0, 0) THEN QUIT
IF Game.Fires% > 2 THEN DQBxput TEMPLAYER, 0, 0 + Player.ABILITY% * 31, 29, 29 + Player.ABILITY% * 31, READY, 63, 2
IF Game.Fires% > 1 THEN DQBxput TEMPLAYER, 0, 0 + Player.ABILITY% * 31, 29, 29 + Player.ABILITY% * 31, READY, 33, 2
IF Game.Fires% > 0 THEN DQBxput TEMPLAYER, 0, 0 + Player.ABILITY% * 31, 29, 29 + Player.ABILITY% * 31, READY, 3, 2
'Extra lives left
IF DQBloadImage(TEMPLAYER, 0, 0, "DATA\CHARS\" + CharacterDir$ + "\LIFE.BMP", Pal, 0, 0) THEN QUIT
IF Game.Lives% > 0 THEN
IF CursorAnim% < 10 THEN
IF Game.Lives% > 2 THEN DQBxput TEMPLAYER, 0, 0, 29, 29, READY, 287, 2
IF Game.Lives% > 1 THEN DQBxput TEMPLAYER, 0, 0, 29, 29, READY, 257, 2
DQBxput TEMPLAYER, 0, 0, 29, 29, READY, 227, 2
END IF
IF CursorAnim% >= 10 AND CursorAnim% < 20 THEN
IF Game.Lives% > 2 THEN DQBxput TEMPLAYER, 31, 0, 60, 29, READY, 287, 2
IF Game.Lives% > 1 THEN DQBxput TEMPLAYER, 31, 0, 60, 29, READY, 257, 2
DQBxput TEMPLAYER, 31, 0, 60, 29, READY, 227, 2
END IF
IF CursorAnim% >= 20 AND CursorAnim% < 30 THEN
IF Game.Lives% > 2 THEN DQBxput TEMPLAYER, 0, 0, 29, 29, READY, 287, 2
IF Game.Lives% > 1 THEN DQBxput TEMPLAYER, 0, 0, 29, 29, READY, 257, 2
DQBxput TEMPLAYER, 0, 0, 29, 29, READY, 227, 2
END IF
IF CursorAnim% >= 30 THEN
IF Game.Lives% > 2 THEN DQBxput TEMPLAYER, 62, 0, 91, 29, READY, 287, 2
IF Game.Lives% > 1 THEN DQBxput TEMPLAYER, 62, 0, 91, 29, READY, 257, 2
DQBxput TEMPLAYER, 62, 0, 91, 29, READY, 227, 2
END IF
END IF

IF PPOINTS% > 100 THEN PPOINTS% = 100
JPRINT READY, "Points:" + STR$(PPOINTS%) + " /" + STR$(Game.MaxPoints%), 100, 10, 7
JPRINT READY, "  Level:" + STR$(Game.Level%) + " /" + STR$(Game.Levels%), 100, 20, 7
'Running energy
DQBbox READY, 105, 30, 205, 35, 246
DRAWCOLOR% = 4
IF Player.PILL$ = "RUN" THEN DRAWCOLOR% = 176
IF Player.PILL$ = "SLO" THEN DRAWCOLOR% = 187
IF Player.PILL$ = "DRU" THEN DRAWCOLOR% = 187
DQBboxf READY, 105, 30, 105 + INT(Player.SPRINT% / (Player.MAXSPRINT% / 100)), 35, DRAWCOLOR%
'Fat bar
DQBbox READY, 105, 40, 205, 45, 246
IF Player.FAT% > Player.MAXFAT% THEN Player.FAT% = Player.MAXFAT%
IF Player.FAT% > 0 THEN DQBboxf READY, 105, 40, 105 + INT(Player.FAT% / INT(Player.MAXFAT% / 100)), 45, 4
'Fatten bar
IF Player.FATTEN% > 100 THEN Player.FATTEN% = 100
IF Player.FATTEN% < -100 THEN Player.FATTEN% = -100
IF Player.FATTEN% > 0 THEN DQBboxf READY, 105, 46, 105 + Player.FATTEN%, 48, 1
IF Player.FATTEN% < 0 THEN DQBboxf READY, 105, 46, 105 - Player.FATTEN%, 48, 2

'Dizzy effect
IF Player.PILL$ = "SLO" THEN t% = INT(RND * 4): IF t% = 0 THEN DQBscroll READY, INT(RND * 5) - 2, INT(RND * 5) - 2
IF Player.PILL$ = "DRU" THEN t% = INT(RND * 4): IF t% = 0 THEN DQBpalRotate 1, 255, INT(RND * 2)
IF Player.PILL$ = "FAT" THEN
IF Player.PILLTIME% > 35 AND Player.PILLTIME% < 40 THEN DQBscroll READY, INT(RND * 5) - 2, INT(RND * 5) - 2
IF Player.PILLTIME% > 75 AND Player.PILLTIME% < 80 THEN DQBscroll READY, INT(RND * 5) - 2, INT(RND * 5) - 2
IF Player.PILLTIME% > 115 AND Player.PILLTIME% < 120 THEN DQBscroll READY, INT(RND * 5) - 2, INT(RND * 5) - 2
END IF

'Show text messages
IF MessageDelay% > 0 AND Player.MSG% <> 1 THEN
t% = DQBlen(Message$)
DQBprint READY, Message$, 162 - INT(t% / 2), 102, 246
IF MessageDelay% > 20 THEN JPRINT READY, Message$, 160 - INT(t% / 2), 100, 7
MessageDelay% = MessageDelay% - 1: IF MessageDelay% = 0 THEN Message$ = ""
IF Message$ = "" THEN MessageDelay% = 0
END IF

'Get player text messages (Dialog.dat)
IF Player.FAT% < Player.MAXFAT% AND Player.FATTEN% < 50 AND Player.MSG% = 1 THEN
MessageDelay% = 120: Player.MSG% = 0
OPEN "DATA\CHARS\" + CharacterDir$ + "\DIALOG.DAT" FOR INPUT AS #1
IF LOF(1) THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = Message$
INPUT #1, JTEMP%
t% = INT(RND * JTEMP%) + 1
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(t%) + ":"
INPUT #1, Message$
ELSE JError$ = "DATA\CHARS\" + CharacterDir$ + "\DIALOG.DAT not found!": QUIT
END IF
CLOSE #1
END IF

'Get player life lost message (Dialog.dat)
IF Player.FAT% = Player.MAXFAT% AND Player.MSG% = 0 THEN Player.MSG% = 1
IF Player.FAT% = Player.MAXFAT% AND Player.MSG% = 1 THEN
MessageDelay% = 120: Player.MSG% = 2: Player.PILL$ = ""
OPEN "DATA\CHARS\" + CharacterDir$ + "\DIALOG.DAT" FOR INPUT AS #1
IF LOF(1) THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "DIALOG2:"
INPUT #1, JTEMP%
t% = INT(RND * JTEMP%) + 1
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(t%) + ":"
INPUT #1, Message$
ELSE JError$ = "DATA\CHARS\" + CharacterDir$ + "\DIALOG.DAT not found!": QUIT
END IF
CLOSE #1
END IF

'Game Over
IF Game.Lives% = 0 AND Player.FAT% = Player.MAXFAT% THEN
JPRINT READY, "Game Over. Press ESC or Backspace", 25, 90, 4
JPRINT READY, "Your Score:" + STR$(Game.Score%), 80, 120, 4
END IF

'Draw mouse cursor
CursorType% = 0
CURSOR

END IF

'-----------------------------------------------------
'Part 2 - pill effects (some also in Part 1)
IF jplay% = 1 THEN

'Effect from special pills
IF Player.PILLTIME% > 0 THEN
Player.PILLTIME% = Player.PILLTIME% - 1
IF Player.PILLTIME% = 0 THEN
DQBsetpal Pal 'Reset palette
Player.INFLATE% = 0: Player.ROT1% = 0: Player.ROT2% = 0
IF Player.PILL$ = "SLO" THEN Message$ = "DIZZYEND:": Player.MSG% = 1
IF Player.PILL$ = "RUN" THEN Message$ = "ENERGETICEND:": Player.MSG% = 1
IF Player.PILL$ = "RUN" THEN PLAYSOUND "POWERD", 0
IF Player.PILL$ = "FAT" THEN Message$ = "MEGAFATEND:": Player.MSG% = 1: Player.SPRINT% = 0
IF Player.PILL$ = "BOU" THEN Message$ = "BOUNCYEND:": Player.MSG% = 1
IF Player.PILL$ = "BOU" THEN PLAYSOUND "POWERD", 0
IF Player.PILL$ = "GAS" THEN Message$ = "HELIUMEND:": Player.MSG% = 1: Player.FLY% = 0
IF Player.PILL$ = "GAS" THEN PLAYSOUND "HELIUMEND", 0: Player.SPRINT% = 0
IF Player.PILL$ = "DRU" THEN Message$ = "DRUGEND:": Player.MSG% = 1: Player.SPRINT% = 0
IF Player.PILL$ = "DAR" THEN Message$ = "DARKENEND:": Player.MSG% = 1
Player.PILL$ = ""
END IF
IF Player.PILL$ = "SLO" THEN Player.SPRINT% = Player.SPRINT% - INT(RND * 2): IF Player.MOVE% = 0 THEN Player.OX% = Player.OX% + INT(RND * 11) - 5
IF Player.SPRINT% < 0 THEN Player.SPRINT% = 0
IF Player.PILL$ = "RUN" THEN Player.SPRINT% = Player.SPRINT% + INT(RND * 2): IF Player.MOVE% = 0 THEN Player.OX% = Player.OX% + INT(RND * 9) - 4
IF Player.SPRINT% > Player.MAXSPRINT% THEN Player.SPRINT% = Player.MAXSPRINT%
IF Player.PILL$ = "FAT" THEN
IF Player.PILLTIME% = 40 THEN Player.FATTEN% = Player.FATTEN% + 50 + INT(RND * 10): PLAYSOUND "INFLATE", 80
IF Player.PILLTIME% = 80 THEN Player.FATTEN% = Player.FATTEN% + 50 + INT(RND * 10): PLAYSOUND "INFLATE", 60
IF Player.PILLTIME% = 120 THEN Player.FATTEN% = Player.FATTEN% + 50 + INT(RND * 10): PLAYSOUND "INFLATE", 40
IF Player.PILLTIME% = 180 THEN PLAYSOUND "MEGAFATDELAY", 40
IF Player.PILLTIME% = 240 THEN PLAYSOUND "MEGAFATDELAY", 20
IF Player.PILLTIME% = 300 THEN PLAYSOUND "MEGAFATDELAY", 0
END IF
IF Player.PILL$ = "BOU" AND Player.OY% > 99 THEN
IF Terrain% < 2 THEN Player.FLY% = INT(1.05 * -Player.FLY%): PLAYSOUND "BOUNCYHIT", 0
IF Terrain% = 2 THEN Player.FLY% = INT(.75 * -Player.FLY%): PLAYSOUND "BOUNCYHIT", 0
END IF
IF Player.PILL$ = "GAS" THEN Player.FLY% = Player.FLY% - 1 - INT(RND * 2)
IF Player.PILL$ = "DRU" THEN Player.OX% = Player.OX% + INT(RND * 15) - 7
END IF

END IF

'-----------------------------------------------------
'Part 3 - Move sounds
IF jplay% = 2 AND UseSounds% = 1 THEN

'Player fatigue sound, panting
IF Player.SPRINT% < Player.MAXSPRINT% AND Game.HearFatigue% = 1 THEN
JTEMP% = 0
IF WAIT.PILLTIME% = 125 THEN JTEMP% = 1
IF WAIT.PILLTIME% = 250 THEN JTEMP% = 1
IF WAIT.PILLTIME% = 375 THEN JTEMP% = 1
IF WAIT.PILLTIME% = 500 THEN JTEMP% = 1
IF WAIT.PILLTIME% = 625 THEN JTEMP% = 1
IF WAIT.PILLTIME% = 750 THEN JTEMP% = 1
IF WAIT.PILLTIME% = 875 THEN JTEMP% = 1
IF WAIT.PILLTIME% = 999 THEN JTEMP% = 1
IF Player.SPRINT% = Player.MAXSPRINT% THEN JTEMP% = 0
IF JTEMP% = 1 THEN
IF Player.SPRINT% / Player.MAXSPRINT% < .9 THEN JTEMP% = 1
IF Player.SPRINT% / Player.MAXSPRINT% < .8 THEN JTEMP% = 2
IF Player.SPRINT% / Player.MAXSPRINT% < .7 THEN JTEMP% = 3
IF Player.SPRINT% / Player.MAXSPRINT% < .6 THEN JTEMP% = 4
IF Player.SPRINT% / Player.MAXSPRINT% < .5 THEN JTEMP% = 5
IF Player.SPRINT% / Player.MAXSPRINT% < .4 THEN JTEMP% = 6
IF Player.SPRINT% / Player.MAXSPRINT% < .3 THEN JTEMP% = 7
IF Player.SPRINT% / Player.MAXSPRINT% < .2 THEN JTEMP% = 8
IF Player.SPRINT% / Player.MAXSPRINT% < .1 THEN JTEMP% = 9
IF FATY% >= FloodY% THEN JTEMP% = 0
IF JTEMP% = 1 THEN PLAYSOUND "FATIGUE1", 0
IF JTEMP% = 2 THEN PLAYSOUND "FATIGUE2", 0
IF JTEMP% = 3 THEN PLAYSOUND "FATIGUE3", 0
IF JTEMP% = 4 THEN PLAYSOUND "FATIGUE4", 0
IF JTEMP% = 5 THEN PLAYSOUND "FATIGUE5", 0
IF JTEMP% = 6 THEN PLAYSOUND "FATIGUE6", 0
IF JTEMP% = 7 THEN PLAYSOUND "FATIGUE7", 0
IF JTEMP% = 8 THEN PLAYSOUND "FATIGUE8", 0
IF JTEMP% = 9 THEN PLAYSOUND "FATIGUE9", 0
END IF
END IF

END IF

END SUB

SUB HELP

'Help (F1, 59)
IF DQBloadImage(READY, 0, 0, "DATA\OTHER\HELP1.PCX", Pal, 0, 0) THEN QUIT
DQBcopyTransLayer READY, VIDEO
DO: LOOP UNTIL DQBkey(KEYENTER)
DO: LOOP UNTIL DQBkey(KEYENTER) = FALSE
IF DQBloadImage(READY, 0, 0, "DATA\OTHER\HELP2.PCX", Pal, 0, 0) THEN QUIT
DQBcopyTransLayer READY, VIDEO
DO: LOOP UNTIL DQBkey(KEYENTER)
DO: LOOP UNTIL DQBkey(KEYENTER) = FALSE

END SUB

SUB INIT

CLS : PRINT "-- Blubber Dragon V.2.04 NoEMS --"
PRINT "Important! Read README.TXT! During game, F1 is help."
PRINT

JError$ = "Missing config files! Run SETUP.EXE!"

OPEN "DATA\OS.DAT" FOR INPUT AS #1
IF LOF(1) THEN
INPUT #1, Game.OS%
INPUT #1, UseSounds%
INPUT #1, UseMusic%
ELSE JError$ = "Missing config files! Run SETUP.EXE!": QUIT
END IF
CLOSE #1

JError$ = ""

IF Game.OS% = 0 THEN PRINT "Running game with Win9x or WinME operating system."
IF Game.OS% = 1 THEN PRINT "Running game with WinXP, Win2000 or WinNT operating system."
PRINT "This can be changed from SETUP.EXE."

OPEN "DATA\GAME.DAT" FOR INPUT AS #1
IF LOF(1) THEN
INPUT #1, NoMouse%
INPUT #1, Game.GFX%
INPUT #1, Game.HearFatigue%
INPUT #1, Game.SndVol%
INPUT #1, ShowErrors%
INPUT #1, Game.WAIT!
ELSE JError$ = "DATA\GAME.DAT not found!": QUIT
END IF
CLOSE #1
PRINT
PRINT "- Press any key to continue -"
PRINT

WHILE INKEY$ = "": WEND

'Load DS4QB++ sound system (Uses Directsound)
IF UseSounds% > 0 OR UseMusic% > 0 THEN
IF DS4QB.Init(CURRENT, 64) THEN JError$ = "Run SETUP.EXE. Select correct OS and save!": QUIT
PRINT "DS4QB++ 1.2 sound system loaded..."
END IF
IF UseSounds% = 0 AND UseMusic% = 0 THEN PRINT "DS4QB++ 1.2 sound system NOT loaded..."

'Load DirectQB 1.61 + DQBrel graphic libraries
NumLayers% = 0
FreeEMS% = 0
IF DQBinit(NumLayers%, 0, FreeEMS%) THEN JError$ = "Unable to load DirectQB + DQBrel libraries!": QUIT
PRINT "DirectQB 1.61 + DQBrel graphic libraries loaded..."

'------------------------------------------------
'Sound volumes
IF UseSounds% > 0 OR UseMusic% > 0 THEN
DS4QB.SetMasterVolume 100
DS4QB.SetGlobalVolumes 50, Game.SndVol%   'Volume for music, volume for sounds
END IF

DQBinstallKeyboard

dummy& = SETMEM(-65000)
t% = DQBsetBaseLayer(B0)
IF t% = 0 THEN JError$ = "Out of conventional memory. Layer 1/4...": QUIT
dummy& = SETMEM(-65000)
t% = DQBsetBaseLayer(B1)
IF t% = 0 THEN JError$ = "Out of conventional memory. Layer 2/4...": QUIT
dummy& = SETMEM(-65000)
t% = DQBsetBaseLayer(B2)
IF t% = 0 THEN JError$ = "Out of conventional memory. Layer 3/4...": QUIT
dummy& = SETMEM(-65000)
t% = DQBsetBaseLayer(B3)
IF t% = 0 THEN JError$ = "Out of conventional memory. Layer 4/4...": QUIT

PRINT "Successfully created off-screen layers into conventional memory!"

DQBwait 100

'Screen 13 equivalent
DQBinitVGA
IF Game.OS% = 0 THEN DQBsetFrameRate 40 'Doesn't work in WinXP, Win2k or WinNT

'These graphics are loaded only once
IF DQBloadImage(READY, 0, 0, "DATA\OTHER\OBJ.BMP", Pal, 0, 0) THEN QUIT
DQBsetpal Pal 'Get palette

'Show start picture
DQBfadeTo 0, 0, 0
DQBclearLayer VIDEO
IF DQBloadImage(VIDEO, 0, 0, "DATA\OTHER\START.PCX", Pal, 0, 0) THEN QUIT
DQBfadeIn Pal
DQBwait 100
DQBfadeTo 0, 0, 0
DQBclearLayer VIDEO
IF DQBloadImage(VIDEO, 0, 0, "DATA\OTHER\START2.PCX", Pal, 0, 0) THEN QUIT
DQBfadeIn Pal
DQBwait 100
DQBfadeTo 0, 0, 0
DQBclearLayer VIDEO
DQBfadeIn Pal

'Mouse!
DQBresetMouse
DQBmouseHide 'Hide mouse - can use own cursor graphics
DQBsetMousePos 120, 60

END SUB

SUB JPRINT (Layer%, Text$, X%, Y%, Col%)

DQBprint Layer%, Text$, X% + 1, Y%, 246
DQBprint Layer%, Text$, X% - 1, Y%, 246
DQBprint Layer%, Text$, X%, Y% + 1, 246
DQBprint Layer%, Text$, X%, Y% - 1, 246
DQBprint Layer%, Text$, X% + 2, Y% + 2, 246
DQBprint Layer%, Text$, X%, Y%, Col%

END SUB

SUB LOADGFX

JError$ = "Error in campaign:" + Game.Campaign$ + "!"

OPEN "DATA\LEVELS\" + Game.Campaign$ + "\LEVEL.DAT" FOR INPUT AS #1
IF LOF(1) THEN
INPUT #1, CampaignName$
INPUT #1, Game.Levels%
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(Game.Level%) + ":"
INPUT #1, Message$
INPUT #1, Level.GFX1$, Level.GFX2$, Level.GFX3$, Level.GFX4$
INPUT #1, BG2.Draw%, BG3.Draw%
INPUT #1, Game.MinPills%, Game.MaxPills%, Game.MaxPoints%
INPUT #1, Game.Clouds%, Game.CloudType%
INPUT #1, Game.Wind%, Game.CloudAlt%, Game.CeilingAlt%
INPUT #1, Game.Shadow%, Game.Marks%, Game.MarkColor%
INPUT #1, Weather%, Terrain%
INPUT #1, FootStepSound%
INPUT #1, Game.AddScore%
INPUT #1, FatgasOdd%, HeliumOdd%, PlaneOdd%
INPUT #1, FloodAmount%, FloodY%, FloodCol%
IF MusicToUse% = 0 THEN INPUT #1, Game.Music$, Game.MusVol%
ELSE JError$ = "DATA\LEVELS\" + Game.Campaign$ + "\LEVEL.DAT not found!": QUIT
END IF
CLOSE #1
IF FloodY% = 0 THEN FloodY% = 300

JError$ = "Error in loading of level graphics!"

'Background & Destroyable & Indestructible (Layers 15, 16, 17)
DQBclearLayer DESTLAYER
IF Level.GFX2$ <> "" THEN
IF DQBloadImage(DESTLAYER, 0, 0, "DATA\LEVELS\" + Game.Campaign$ + "\" + Level.GFX2$, Pal, 0, 0) THEN QUIT
END IF

JError$ = ""

END SUB

SUB LOADMUSIC (jplay%)

IF UseMusic% = 0 THEN EXIT SUB

JError$ = "Unable to set music to NONE."

'Open new music file
IF jplay% = 0 THEN
IF Game.Music$ = "" THEN MusicPlaying$ = "": DS4QB.StopMusic 1: JError$ = "": EXIT SUB

JError$ = "Unable to open music file: " + UCASE$(Game.Music$) + "!"

'Deletes old music from memory
DS4QB.StopMusic 1
DS4QB.DeleteMusic 1
'Change music volume
DS4QB.SetGlobalVolumes Game.MusVol%, Game.SndVol%
'Loads new music
JPRINT VIDEO, "Loading Music: " + UCASE$(Game.Music$), 23, 135, 6
DS4QB.LoadMusic 1, "MUSIC\" + Game.Music$, DEFAULT
JPRINT VIDEO, "Done", 23, 145, 6
DQBwait 50
DS4QB.PlayMusic 1
MusicPlaying$ = Game.Music$
END IF

JError$ = "Error: Unable to restart music."

'Restart music
IF jplay% = 1 AND Game.Music$ <> "" THEN DS4QB.StopMusic 1: DS4QB.PlayMusic 1

JError$ = ""

END SUB

SUB LOADSOUNDS (jplay%)

IF UseSounds% = 0 THEN EXIT SUB

'Play & Clear sound buffer
DS4QB.PlaySounds

JError$ = "Error in loading of character sounds! Restart game..."

'Delete old character sounds and load new ones
IF jplay% = 0 THEN

IF Game.Start% = 1 THEN
FOR t% = 1 TO 27
DS4QB.StopSound t%
NEXT t%
END IF

OPEN "DATA\CHARS\" + CharacterDir$ + "\SOUND.DAT" FOR INPUT AS #1
FOR t% = 1 TO 27
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(t%) + ":"
INPUT #1, JTEMP$
IF JTEMP$ <> "" THEN
IF Game.Start% = 1 THEN DS4QB.DeleteSound t%
DS4QB.LoadSound t%, "SND\" + JTEMP$, DEFAULT
END IF
NEXT t%
CLOSE #1

END IF
'-------------------------------------------------------------

JError$ = "Error in loading of footstep & weather sounds! Restart game..."

'Replace footstep & weather sounds
IF jplay% = 1 THEN

IF Game.Start% = 1 THEN
FOR t% = 28 TO 34
DS4QB.StopSound t%
NEXT t%
END IF

'Character's footstep sound
IF Game.Start% = 1 THEN DS4QB.DeleteSound 28
OPEN "DATA\CHARS\" + CharacterDir$ + "\SOUND.DAT" FOR INPUT AS #1
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = " 28:"
INPUT #1, JTEMP$

'Load default footstep sound
IF FootStepSound% = 0 AND JTEMP$ <> "" THEN DS4QB.LoadSound 28, "SND\" + JTEMP$, DEFAULT

'Load other than default footstep sound
IF FootStepSound% > 0 THEN

IF FootStepSound% = 1 THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "FOOTSTEPSTONE:"
END IF
IF FootStepSound% = 2 THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "FOOTSTEPMUD:"
END IF
IF FootStepSound% = 3 THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "FOOTSTEPSNOW:"
END IF
IF FootStepSound% = 4 THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "FOOTSTEPWATER:"
END IF
IF FootStepSound% = 5 THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "FOOTSTEPWOOD:"
END IF
IF FootStepSound% = 6 THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "FOOTSTEPSTOMP:"
END IF

INPUT #1, JTEMP$
IF JTEMP$ <> "" THEN DS4QB.LoadSound 28, "SND\" + JTEMP$, DEFAULT
END IF
CLOSE #1

'Wind/Snowing sound (not replaced, always the same)
IF Game.Start% = 0 THEN DS4QB.LoadSound 29, "SND\ENV\WIND.MP3", DEFAULT

'Level specific background sound
OPEN "DATA\LEVELS\" + Game.Campaign$ + "\LEVEL.DAT" FOR INPUT AS #1
IF LOF(1) THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(Game.Level%) + ":"
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "BGSOUND:"
INPUT #1, JTEMP$, BGSoundOdd%
IF JTEMP$ = "" THEN BGSoundOdd% = -1
ELSE JError$ = "DATA\LEVELS\" + Game.Campaign$ + "\LEVEL.DAT not found!": QUIT
END IF
CLOSE #1
IF BGSoundOdd% > -1 THEN DS4QB.DeleteSound 30: DS4QB.LoadSound 30, "SND\" + JTEMP$, DEFAULT

'Rain & Lightning sounds
IF Weather% > 0 AND Weather% < 4 THEN DS4QB.DeleteSound 31
IF Weather% = 1 THEN DS4QB.LoadSound 31, "SND\ENV\RAIN1.MP3", DEFAULT
IF Weather% = 2 THEN DS4QB.LoadSound 31, "SND\ENV\RAIN2.MP3", DEFAULT
IF Weather% = 3 THEN DS4QB.LoadSound 31, "SND\ENV\RAIN3.MP3", DEFAULT
IF Game.Start% = 0 THEN
DS4QB.LoadSound 32, "SND\ENV\THUNDER1.MP3", DEFAULT
DS4QB.LoadSound 33, "SND\ENV\THUNDER2.MP3", DEFAULT
DS4QB.LoadSound 34, "SND\ENV\THUNDER3.MP3", DEFAULT
END IF
Game.Start% = 1
END IF

JError$ = ""

END SUB

SUB MENUMUSIC

IF UseMusic% = 0 THEN EXIT SUB

JError$ = "Error loading menu music!"

OPEN "MUSIC\MUSIC.TXT" FOR INPUT AS #1
IF LOF(1) THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "MENU:"
INPUT #1, JTEMP%
t% = INT(RND * JTEMP%) + 1
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(t%) + ":"
INPUT #1, Game.Music$, Game.MusVol%
ELSE JError$ = "MUSIC\MUSIC.TXT not found!": QUIT
END IF
CLOSE #1

'Music
IF Game.Music$ <> "" THEN
IF MusicPlaying$ <> Game.Music$ THEN LOADMUSIC 0 'Load new music
IF MusicPlaying$ = Game.Music$ THEN LOADMUSIC 1 'Restart music
END IF
IF Game.Music$ = "" THEN LOADMUSIC 0

JError$ = ""

END SUB

SUB PLAYSOUND (jplay$, jvol%)

IF UseSounds% = 0 THEN EXIT SUB

'Stop looping sounds
IF jplay$ = "STOPWEATHER" THEN
DS4QB.StopSound 29
DS4QB.StopSound 30
DS4QB.StopSound 31
END IF

'Get sounds ready to be played
'-----------------------------------------------------------
'Weather & background sounds (looping)
IF jplay$ = "WIND1" THEN DS4QB.PlaySoundEx 29, 22050, 50, 0, 1
IF jplay$ = "WIND2" THEN DS4QB.PlaySoundEx 29, 22050, 75, 0, 1
IF jplay$ = "WIND3" THEN DS4QB.PlaySoundEx 29, 22050, 100, 0, 1
IF jplay$ = "BGSOUNDL" THEN DS4QB.AddSound 30, 22050, 100, 0, 1
IF jplay$ = "BGSOUND" THEN DS4QB.PlaySoundEx 30, 20050 + INT(RND * 2000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "RAIN" THEN DS4QB.PlaySoundEx 31, 22050, 100, 0, 1
IF jplay$ = "LIGHTNING" THEN DS4QB.PlaySoundEx 32 + INT(RND * 3), 16050 + INT(RND * 6000), 50 + INT(RND * 51), 0, DEFAULT

'Player bumps walls (sound heard from direction)
IF jplay$ = "BUMPWALL1L" THEN DS4QB.AddSound 4, 20050 + INT(RND * 2000), 80 + INT(RND * 21), -50, DEFAULT
IF jplay$ = "BUMPWALL2L" THEN DS4QB.AddSound 5, 20050 + INT(RND * 2000), 80 + INT(RND * 21), -50, DEFAULT
IF jplay$ = "BUMPWALL1R" THEN DS4QB.AddSound 4, 20050 + INT(RND * 2000), 80 + INT(RND * 21), 50, DEFAULT
IF jplay$ = "BUMPWALL2R" THEN DS4QB.AddSound 5, 20050 + INT(RND * 2000), 80 + INT(RND * 21), 50, DEFAULT

'Player fatigue, panting
IF jplay$ = "FATIGUE1" THEN DS4QB.PlaySoundEx 27, 20000, 10, 0, DEFAULT
IF jplay$ = "FATIGUE2" THEN DS4QB.PlaySoundEx 27, 23000, 15, 0, DEFAULT
IF jplay$ = "FATIGUE3" THEN DS4QB.PlaySoundEx 27, 26000, 20, 0, DEFAULT
IF jplay$ = "FATIGUE4" THEN DS4QB.PlaySoundEx 27, 29000, 25, 0, DEFAULT
IF jplay$ = "FATIGUE5" THEN DS4QB.PlaySoundEx 27, 32000, 30, 0, DEFAULT
IF jplay$ = "FATIGUE6" THEN DS4QB.PlaySoundEx 27, 35000, 35, 0, DEFAULT
IF jplay$ = "FATIGUE7" THEN DS4QB.PlaySoundEx 27, 38000, 40, 0, DEFAULT
IF jplay$ = "FATIGUE8" THEN DS4QB.PlaySoundEx 27, 41000, 45, 0, DEFAULT
IF jplay$ = "FATIGUE9" THEN DS4QB.PlaySoundEx 27, 44000, 50, 0, DEFAULT

'Normal sounds
IF jplay$ = "BELCH" THEN DS4QB.AddSound 1 + INT(RND * 3), 16050 + INT(RND * 6000) - INT(jvol% * 600), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "BOUNCYHIT" THEN DS4QB.PlaySoundEx 6, 20050 + INT(RND * 2000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "DROWN" THEN DS4QB.AddSound 7, 20050 + INT(RND * 2000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "LOSEWEIGHT" THEN DS4QB.AddSound 8, 20050 + INT(RND * 2000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "MEGAFATDELAY" THEN DS4QB.AddSound 9, 20050 + INT(RND * 2000), 50 + jvol%, 0, DEFAULT
IF jplay$ = "RANDOMIZE" THEN DS4QB.AddSound 10, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "HIT" THEN DS4QB.PlaySoundEx 11 + INT(RND * 2), 20050 + INT(RND * 2000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "INFLATE" THEN DS4QB.AddSound 13, 20050 + INT(RND * 2000), jvol% + 20, 0, DEFAULT
IF jplay$ = "INFLATEGAS" THEN DS4QB.PlaySoundEx 13, 20050 + INT(RND * 2000), 30 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "MEGAFAT" THEN DS4QB.AddSound 14, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "BOUNCY" THEN DS4QB.AddSound 15, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "EXTRALIFE" THEN DS4QB.AddSound 16, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "HELIUMEND" THEN DS4QB.PlaySoundEx 17, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "POWERB" THEN DS4QB.AddSound 18, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "POWERU" THEN DS4QB.AddSound 19, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "POWERD" THEN DS4QB.PlaySoundEx 20, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "MOVESOUND2" THEN DS4QB.AddSound 21, 18050 + INT(RND * 4000), jvol%, 0, DEFAULT
IF jplay$ = "MOVESOUND1" THEN DS4QB.AddSound 22, 18050 + INT(RND * 4000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "SWALLOW" THEN DS4QB.AddSound 23, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "FALLTOWATER" THEN DS4QB.AddSound 24, 18050 + INT(RND * 4000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "GETSPECIAL" THEN DS4QB.AddSound 25, 20050 + INT(RND * 2000), 100, 0, DEFAULT
IF jplay$ = "USESPECIAL" THEN DS4QB.AddSound 26, 20050 + INT(RND * 2000), 80 + INT(RND * 21), 0, DEFAULT
IF jplay$ = "FOOTSTEP" THEN DS4QB.PlaySoundEx 28, 18050 + INT(RND * 4000), 50 + INT(RND * 21), 0, DEFAULT

END SUB

SUB PLAYSOUNDS (jplay$)

IF UseSounds% = 0 THEN EXIT SUB

'Play Score Sound
IF jplay$ <> "" THEN
FOR t% = 1 TO 34
DS4QB.StopSound t%
NEXT t%
DS4QB.DeleteSound 30
DS4QB.LoadSound 30, "SND\" + jplay$, DEFAULT
DS4QB.AddSound 30, 22050, 100, 0, DEFAULT
END IF

'Play sounds from sound buffer
DS4QB.PlaySounds

END SUB

SUB QUIT

'Close libraries
DQBclose     'close DirectQB 1.61 + DQBrel
IF UseSounds% > 0 OR UseMusic% > 0 THEN DS4QB.Close  'close DS4QB++ 1.2

'Try to free used base memory
dummy& = SETMEM(65000)
dummy& = SETMEM(65000)
dummy& = SETMEM(65000)
dummy& = SETMEM(65000)

CLS

'Show error messages
IF JError$ <> "" THEN PRINT JError$
IF JError$ <> "" THEN PRINT
IF ERR <> 0 THEN PRINT STR$(ERR) + " - Last QB error code"
IF ERR <> 0 THEN PRINT
IF DQBerror$ <> "" THEN PRINT DQBerror$ + " - DirectQB message"
PRINT "------------------------------------------------------------------"
PRINT "QB Error 53 Ignored:" + STR$(Error53Num%) + " Times."
PRINT "QB Error 75 Ignored:" + STR$(Error75Num%) + " Times."
PRINT "------------------------------------------------------------------"
PRINT "- Exited Blubber Dragon -"
PRINT
PRINT "- Press any key to continue -"

WHILE INKEY$ = "": WEND

END

END SUB

SUB SELECTCAMPAIGN

JError$ = "Errors in DATA\LEVELS\LEVELS.DAT!"

Campaign% = 1
Game.Level% = 1
Game.Score% = 0
JSelect% = 0

'Menu Music
MENUMUSIC

SELECTCAMPAIGN:
DO: LOOP UNTIL DQBkey(KEYUP) = FALSE AND DQBkey(KEYDOWN) = FALSE AND DQBmouseLB = FALSE AND DQBmouseRB = FALSE

'Randomize Cursor Type
CursorType% = INT(RND * 3) + 1
IF CursorType% = 3 THEN CursorType% = 6

OPEN "DATA\LEVELS\LEVELS.DAT" FOR INPUT AS #1
IF LOF(1) THEN
INPUT #1, Campaigns%
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(Campaign%) + ":"
INPUT #1, Game.Campaign$
ELSE JError$ = "DATA\LEVELS\LEVELS.DAT not found!": QUIT
END IF
CLOSE #1

OPEN "DATA\LEVELS\" + Game.Campaign$ + "\LEVEL.DAT" FOR INPUT AS #1
IF LOF(1) THEN
INPUT #1, CampaignName$
ELSE JError$ = "DATA\LEVELS\" + Game.Campaign$ + "\LEVEL.DAT not found!": QUIT
END IF
CLOSE #1

JError$ = "Errors in DATA\LEVELS\" + Game.Campaign$ + "\LEVEL.DAT!"

'Load background image
IF DQBloadImage(READY, 0, 0, "DATA\LEVELS\" + Game.Campaign$ + "\SELECT.BMP", Pal, 0, 0) THEN QUIT

JPRINT READY, STR$(Campaign%) + " /" + STR$(Campaigns%), 5, 10, 7

JPRINT READY, CampaignName$, 80, 10, 7

JPRINT READY, "Press UP and DOWN arrows to change", 10, 160, 7
JPRINT READY, "Press SPACE to select ", 10, 170, 7
JPRINT READY, "Press ESC to QUIT game ", 10, 180, 7
JPRINT READY, "Press Backspace in the game to return", 10, 190, 7
DQBcopyLayer READY, VIDEO
DQBcopyLayer READY, TEMPLAYER2

DQBfadeIn Pal

DO
'Change campaign with mouse
JX% = 5: JX2% = 65: JY% = 5: JY2% = 20
IF DQBmouseX > JX% AND DQBmouseX < JX2% AND DQBmouseY > JY% AND DQBmouseY < JY2% THEN
DQBbox READY, JX%, JY%, JX2%, JY2%, INT(RND * 255) + 1
IF DQBmouseLB = TRUE AND Campaign% < Campaigns% THEN Campaign% = Campaign% + 1: GOTO SELECTCAMPAIGN
IF DQBmouseRB = TRUE AND Campaign% > 1 THEN Campaign% = Campaign% - 1: GOTO SELECTCAMPAIGN
END IF
'Select campaign with mouse
JX% = 75: JX2% = 310: JY% = 5: JY2% = 20
IF DQBmouseX > JX% AND DQBmouseX < JX2% AND DQBmouseY > JY% AND DQBmouseY < JY2% THEN
DQBbox READY, JX%, JY%, JX2%, JY2%, INT(RND * 255) + 1
IF DQBmouseLB = TRUE THEN JSelect% = 1
END IF
'Draw mouse cursor
CURSOR
DQBcopyLayer READY, VIDEO
DQBcopyLayer TEMPLAYER2, READY
IF DQBkey(KEYUP) AND Campaign% > 1 THEN Campaign% = Campaign% - 1: GOTO SELECTCAMPAIGN
IF DQBkey(KEYDOWN) AND Campaign% < Campaigns% THEN Campaign% = Campaign% + 1: GOTO SELECTCAMPAIGN
IF DQBkey(KEYESC) THEN JError$ = "": DQBfadeTo 0, 0, 0: QUIT
WAITFRAME
LOOP UNTIL DQBkey(KEYSPACE) OR JSelect% = 1
DO: LOOP UNTIL DQBkey(KEYSPACE) = FALSE AND DQBmouseLB = FALSE AND DQBmouseRB = FALSE
JSelect% = 0

JError$ = ""

END SUB

SUB SELECTMUSIC

IF UseMusic% = 0 THEN EXIT SUB

JError$ = "Errors in MUSIC\MUSIC.TXT!"

JSelect% = 0

IF MusicToUse% > 0 THEN GOTO SELECTMUSIC

OPEN "MUSIC\MUSIC.TXT" FOR INPUT AS #1
IF LOF(1) THEN
INPUT #1, MusicToUse%
ELSE JError$ = "MUSIC\MUSIC.TXT not found!": QUIT
END IF
CLOSE #1
IF MusicToUse% = 0 THEN JError$ = "": EXIT SUB

SELECTMUSIC:
DO: LOOP UNTIL DQBkey(KEYUP) = FALSE AND DQBkey(KEYDOWN) = FALSE
DO: LOOP UNTIL DQBkey(73) = FALSE AND DQBkey(81) = FALSE
DO: LOOP UNTIL DQBkey(71) = FALSE AND DQBkey(79) = FALSE
DO: LOOP UNTIL DQBmouseLB = FALSE AND DQBmouseRB = FALSE

'Randomize Cursor Type
CursorType% = INT(RND * 8) + 1

OPEN "MUSIC\MUSIC.TXT" FOR INPUT AS #1
IF LOF(1) THEN
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = "MUSIC:"
INPUT #1, MusicFiles%
IF MusicToUse% = 2 THEN MusicFile% = INT(RND * MusicFiles%) + 1

IF MusicFile% < 1 THEN MusicFile% = 1
DO
INPUT #1, JTEMP$
LOOP UNTIL JTEMP$ = STR$(MusicFile%) + ":"
INPUT #1, MusicName$, MusVol%
ELSE JError$ = "MUSIC\MUSIC.TXT not found!": QUIT
END IF
CLOSE #1
IF MusicToUse% = 2 THEN GOTO STARTMUSIC

DQBclearLayer READY
IF DQBloadImage(READY, 0, 0, "DATA\OTHER\BG02.BMP", Pal, 0, 0) THEN QUIT

JPRINT READY, "Music:" + STR$(MusicFile%) + " /" + STR$(MusicFiles%), 10, 10, 7

JPRINT READY, MusicName$, 10, 30, 7
JPRINT READY, "Music Volume To Use:" + STR$(MusVol%) + " (" + STR$(MusVol% + 100) + "%)", 10, 45, 7

JPRINT READY, "Press UP and DOWN arrows to change", 10, 120, 7
JPRINT READY, "Press PAGEUP and PAGEDOWN to jump 5", 10, 130, 7
JPRINT READY, "Press HOME and END to jump 10 ", 10, 140, 7
JPRINT READY, "Press SPACE to select/restart music", 10, 150, 7
JPRINT READY, "Press ENTER to leave screen", 10, 160, 7
JPRINT READY, "Press R to use random music", 10, 170, 7
JPRINT READY, "Press ESC to QUIT game ", 10, 180, 7
JPRINT READY, "Press M in the game to return", 10, 190, 7
DQBcopyLayer READY, VIDEO
DQBcopyLayer READY, TEMPLAYER2

DO
'Change music with mouse
JX% = 60: JX2% = 160: JY% = 5: JY2% = 20
IF DQBmouseX > JX% AND DQBmouseX < JX2% AND DQBmouseY > JY% AND DQBmouseY < JY2% THEN
DQBbox READY, JX%, JY%, JX2%, JY2%, INT(RND * 255) + 1
IF DQBmouseLB = TRUE AND MusicFile% < MusicFiles% THEN MusicFile% = MusicFile% + 1: GOTO SELECTMUSIC
IF DQBmouseRB = TRUE AND MusicFile% > 1 THEN MusicFile% = MusicFile% - 1: GOTO SELECTMUSIC
END IF
'Select music with mouse
JX% = 5: JX2% = 310: JY% = 25: JY2% = 40
IF DQBmouseX > JX% AND DQBmouseX < JX2% AND DQBmouseY > JY% AND DQBmouseY < JY2% THEN
DQBbox READY, JX%, JY%, JX2%, JY2%, INT(RND * 255) + 1
IF DQBmouseLB = TRUE THEN JSelect% = 1
IF DQBmouseRB = TRUE THEN GOTO DEFMUSIC
END IF
'Draw mouse cursor
CURSOR
DQBcopyLayer READY, VIDEO
DQBcopyLayer TEMPLAYER2, READY
IF DQBkey(KEYUP) AND MusicFile% > 1 THEN MusicFile% = MusicFile% - 1: GOTO SELECTMUSIC
IF DQBkey(KEYDOWN) AND MusicFile% < MusicFiles% THEN MusicFile% = MusicFile% + 1: GOTO SELECTMUSIC
IF DQBkey(19) THEN MusicToUse% = 2: GOTO SELECTMUSIC
IF DQBkey(73) THEN
MusicFile% = MusicFile% - 5
IF MusicFile% < 1 THEN MusicFile% = 1
GOTO SELECTMUSIC
END IF
IF DQBkey(81) THEN
MusicFile% = MusicFile% + 5
IF MusicFile% > MusicFiles% THEN MusicFile% = MusicFiles%
GOTO SELECTMUSIC
END IF
IF DQBkey(71) THEN
MusicFile% = MusicFile% - 10
IF MusicFile% < 1 THEN MusicFile% = 1
GOTO SELECTMUSIC
END IF
IF DQBkey(79) THEN
MusicFile% = MusicFile% + 10
IF MusicFile% > MusicFiles% THEN MusicFile% = MusicFiles%
GOTO SELECTMUSIC
END IF
IF DQBkey(KEYESC) THEN JError$ = "": DQBfadeTo 0, 0, 0: QUIT
IF DQBkey(KEYENTER) THEN GOTO DEFMUSIC
WAITFRAME
LOOP UNTIL DQBkey(KEYSPACE) OR JSelect% = 1
DO: LOOP UNTIL DQBkey(KEYSPACE) = FALSE

STARTMUSIC:
Game.Music$ = MusicName$
Game.MusVol% = MusVol%

'Music
IF Game.Music$ <> "" THEN
IF MusicPlaying$ <> Game.Music$ THEN LOADMUSIC 0 'Load new music
IF MusicPlaying$ = Game.Music$ THEN LOADMUSIC 1 'Restart music
END IF
IF Game.Music$ = "" THEN LOADMUSIC 0

DEFMUSIC:
DO: LOOP UNTIL DQBkey(KEYENTER) = FALSE AND DQBmouseLB = FALSE AND DQBmouseRB = FALSE
JSelect% = 0
JError$ = ""

END SUB

SUB WAITFRAME

JError$ = "Error occured in GAME TIMING"

'Keep correct frame rate

'For Win9x and WinME
IF Game.OS% = 0 THEN
DO
JTEMP% = DQBframeReady    'Doesn't work in WinXP, Win2k or WinNT
LOOP UNTIL JTEMP% = TRUE
END IF

'For WinXP, Win2k and WinNT
IF Game.OS% = 1 THEN
JTEMP! = Game.WAIT!
DO
JTEMP! = JTEMP! - 1
LOOP UNTIL JTEMP! <= 0
END IF

JError$ = ""

END SUB

SUB WEATHERSUB

'Light rain
IF Weather% = 1 THEN
FOR t% = 1 TO INT(RND * 10 + 25 + Game.GFX% * 25)
SaaX% = INT(RND * 320): SaaY% = INT(RND * 200 - 2)
IF SaaY% < FloodY% THEN
DQBpset READY, SaaX%, SaaY%, FloodCol%
DQBpset READY, SaaX%, SaaY% + 1, FloodCol%
DQBpset READY, SaaX%, SaaY% + 2, FloodCol%
END IF
NEXT t%
FOR t% = 1 TO INT(RND * 10 + 13 + Game.GFX% * 13)
SaaX% = INT(RND * 320): SaaY% = 190 + INT(RND * 10)
IF FloodY% < 200 THEN SaaY% = 195 + INT(RND * 5) + FloodY% - 200
DQBpset READY, SaaX%, SaaY%, FloodCol%
NEXT t%
END IF

'Normal rain
IF Weather% = 2 THEN
FOR t% = 1 TO INT(RND * 15 + 75 + Game.GFX% * 75)
SaaX% = INT(RND * 320): SaaY% = INT(RND * 200 - 2)
IF SaaY% < FloodY% THEN
DQBpset READY, SaaX%, SaaY%, FloodCol%
DQBpset READY, SaaX%, SaaY% + 1, FloodCol%
DQBpset READY, SaaX%, SaaY% + 2, FloodCol%
END IF
NEXT t%
FOR t% = 1 TO INT(RND * 15 + 38 + Game.GFX% * 38)
SaaX% = INT(RND * 320): SaaY% = 190 + INT(RND * 10)
IF FloodY% < 200 THEN SaaY% = 195 + INT(RND * 5) + FloodY% - 200
DQBpset READY, SaaX%, SaaY%, FloodCol%
NEXT t%
END IF

'Heavy rain + lightning (only when not flooding)
IF Weather% = 3 THEN
FOR t% = 1 TO INT(RND * 20 + 125 + Game.GFX% * 125)
SaaX% = INT(RND * 320): SaaY% = INT(RND * 200 - 2)
IF SaaY% < FloodY% THEN
DQBpset READY, SaaX%, SaaY%, FloodCol%
DQBpset READY, SaaX%, SaaY% + 1, FloodCol%
DQBpset READY, SaaX%, SaaY% + 2, FloodCol%
END IF
NEXT t%
FOR t% = 1 TO INT(RND * 20 + 63 + Game.GFX% * 63)
SaaX% = INT(RND * 320): SaaY% = 190 + INT(RND * 10)
IF FloodY% < 200 THEN SaaY% = 195 + INT(RND * 5) + FloodY% - 200
DQBpset READY, SaaX%, SaaY%, FloodCol%
NEXT t%
END IF

'Snowing
IF Weather% = 4 THEN
FOR t% = 1 TO INT(RND * 10 + 50 + Game.GFX% * 50)
SaaX% = INT(RND * 320): SaaY% = INT(RND * 200 - 1)
IF SaaY% < FloodY% THEN
DQBpset READY, SaaX%, SaaY%, 15
DQBpset READY, SaaX% + INT(RND * 2), SaaY% + INT(RND * 2), 15
DQBpset READY, SaaX% - INT(RND * 2), SaaY% - INT(RND * 2), 15
END IF
NEXT t%
END IF

'Heavier snowing
IF Weather% = 5 THEN
FOR t% = 1 TO INT(RND * 15 + 150 + Game.GFX% * 150)
SaaX% = INT(RND * 320): SaaY% = INT(RND * 200 - 1)
IF SaaY% < FloodY% THEN
DQBpset READY, SaaX%, SaaY%, 15
DQBpset READY, SaaX% + INT(RND * 2), SaaY% + INT(RND * 2), 15
DQBpset READY, SaaX% - INT(RND * 2), SaaY% - INT(RND * 2), 15
END IF
NEXT t%
END IF

'Snow blizard
IF Weather% = 6 THEN
FOR t% = 1 TO INT(RND * 20 + 250 + Game.GFX% * 250)
SaaX% = INT(RND * 320): SaaY% = INT(RND * 200 - 1)
IF SaaY% < FloodY% THEN
DQBpset READY, SaaX%, SaaY%, 15
DQBpset READY, SaaX% + INT(RND * 2), SaaY% + INT(RND * 2), 15
DQBpset READY, SaaX% - INT(RND * 2), SaaY% - INT(RND * 2), 15
END IF
NEXT t%
END IF

'---------------------------
'Lightning
IF Weather% = 3 THEN
JTEMP% = INT(RND * 500)
IF JTEMP% = 0 THEN
DQBboxf READY, 0, 0, 319, 199, 80
PLAYSOUND "LIGHTNING", 0
END IF
END IF

END SUB

