Remstart
Underwater Entry
Made by Sinani201
~The DB Classic Programming Challenge Thread~
remend
 
Set Display Mode 800,600,16
 
rem added sync on and sync rate
   sync on
   sync rate 60
 
cls 0 : sync
hide mouse
print "Welcome to Sinani201's UnderWater... thing"
print "Use the arrow keys to move and space to shoot"
print "If you run out of air, you lose!"
print "You are the green guy, and your enemies are purple. Shoot as many as you can before you lose!"
print "If you get hit then you lose."
print "Good luck!"
print "Press any key to start"
wait key
cls
printc "Drawing sand..."
`Shore(Sand)
ink RGB(255,215,130),0
box 0,100,100,599
ink 0,0
`Draw random dots in the sand
for y=100 to 599
  for x=1 to 100
    draw=rnd(32)
    if draw=24 then dot x,y
  next x
next y
ink RGB(255,255,255),0
`Draw water
ink RGB(75,185,225),0
box 101,150,799,599
ink 0,0
text 0,0,"Drawing sand..."
`Draw your character
ink RGB(0,255,0),0
box 0,0,70,50
box 70,20,90,30
get image 1,0,0,90,50
 
rem added sync
sync
 
 
ink 0,0
box 0,0,90,50
`Draw enemy
ink rgb(170,30,160),0
box 0,0,70,50
get image 2,0,0,70,50
 
rem added sync
sync
 
 
ink 0,0
box 0,0,70,50
wait 1000
`Put your character on the screen
charx=1
chary=50
set text opaque
`Enemy vars
enemyNum=2
makeEnemy=1
`MAIN LOOP TIME!!!!
DO : `!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
  rem commented out
  `sync
 
  sprite 1,charx,chary,1
  set text size 20
  text 70,20,"Kills: "+str$(kills)
 
  rem changed to sub-routines
  gosub controlcharacter
  gosub shoot
  gosub movelimit
  gosub _make_enemy
  gosub hitenemy
  gosub updateposition
 
  rem added sync
  sync
loop
 
remstart
*****************************************
*****************************************
********Functions and subroutines********
*****************************************
*****************************************
REMEND
movebullet:
  set text size 15
  set text opaque
  ink rgb(255,255,255),RGB(75,185,225)
  inc bulletposx,10
  text bulletposx,bulletposy,"-"
  sleep 1
  text bulletposx,bulletposy," "
  if bulletposx>799 then firedbullet=0
return
 
controlcharacter:
  `Control character
  if underwater=1
    if upkey()=1 then sprite 1,charx,chary-speed,1
  endif
  if movedown=1
    if downkey()=1 then sprite 1,charx,chary+speed,1
  endif
  if leftkey()=1 then sprite 1,charx-speed,chary,1
  if rightkey()=1 then sprite 1,charx+speed,chary,1
return
 
shoot:
  `Shoot
  if underwater=1
    if spacekey()=1
      if firedbullet=0
        firedbullet=1
        bulletposx=sprite x(1)+sprite width(1)
        bulletposy=sprite y(1)+5
      endif
    endif
    dec air#,0.2
  endif
  if firedbullet=1
    speed=6
  else
    speed=3
  endif
  if firedbullet=1
    gosub movebullet
  else
    sleep 1
  endif
return
 
movelimit:
  `Make sure character does not fall out of boundries
  if charx>99
    if changevar=0
      sprite 1,sprite x(1),151,1
      changevar=1
    endif
    movedown=1
    underwater=1
  endif
  if underwater=1
    if chary<120 then sprite 1,sprite x(1),120,1
    if charx+sprite width(1)>799 then sprite 1,799-sprite width(1),sprite y(1),1
    if charx<101 then sprite 1,101,sprite y(1),1
    gainair=0
  endif
return
 
_make_enemy:
  `Enemy Character
  if makeEnemy=1
  for enemy=2 to enemyNum
    if enemy-1<4 then sprite enemy,700,(enemy-2)*70+160,2
    if enemy-1>3 then sprite enemy,600,(enemy-2)*70+160,2
  next enemy
  makeEnemy=0
  endif
return
 
hitenemy:
  `If enemy gets hit...
  for enemy=2 to enemyNum
  if sprite exist(2)=1
    spritex=sprite x(enemy)
    spritey=sprite y(enemy)
  endif
  if sprite exist(2)=1
    if bulletposx > spritex and bulletposx < spritex+sprite width(enemy)
      if bulletposy > spritey and bulletposy < spritey+sprite height(enemy)
        delete sprite enemy
        firedbullet=0
        inc enemyNum
        inc kills
        inc makeEnemy
      endif
    endif
  endif
  next enemy
return
 
updateposition:
    `Update charcter position
  if charx<0 then sprite 1,0,sprite y(1),1
  charx=sprite x(1)
  chary=sprite y(1)
  sprite 1,charx,chary,1
return