sync on
sync rate 100
set display mode 800,600,32
autocam off
hide mouse
position camera 0,0,-10
set text font "arial"
set text size 30
 
 
createsound("sound1",1,500,50,8000,0,0,0.00,0.0,0,0)
 
make object cube 1,1
delete object 1
 
 
practice=1
level=1
 
restart:
changepitch=1
score=0
miss#=0
 
do
 
colour=colour-mousemovey()*100
if colour>80000 then colour=80000
if colour<5000 then colour=5000
color backdrop colour/350.0
 
if changepitch=1
  speed=rnd(75000)+5000
  set sound speed 1,speed
  changepitch=0
endif
 
if sound playing(1)=0 then play sound 1
 
if mouseclick()=1
  if colour>speed and colour<speed+10000
    changepitch=1
    inc score
  else
    inc miss#
  endif
endif
 
if practice=1 and inkey$()="s" then practice=0:goto restart
if practice=1
  if colour>speed and colour<speed+10000
    text 350,200,"Just right! ="
  else
    if colour>speed then text 350,200,"Go Down! v"
    if colour<speed+10000 then text 350,200,"Go Up! ^"
  endif
 
  text 0,0,"TRAINING MODE !! (Press 's' to skip training.)"
  text 0,30,"Match the brightness to the sound."
  text 0,60,"Mouse up/down to change brightness"
  text 0,90,"Left mouse click to make an attempt."
  text 0,120,"Each attempt will increase my score.  First to 10 wins."
endif
 
text 350,300,"Your Score: "+str$(score)
text 350,350,"My Score: "+left$(str$(miss#/(100.0-level*15)),4)
`text 0,0,str$(screen fps())
 
if score>=10
  if practice=1
    text 0,500,"You win.  Now let's play for real - no help this time!  Press any key":sync:wait key
    practice=0
    goto restart
  else
    inc level
    if level<6 then text 0,500,"You win.  Moving to level "+str$(level)+" out of 5. Press any key":sync:wait key
    goto restart
  endif
endif
 
if miss#/(100.0-level*20)>=10 then text 0,500,"I win.  Game Over!  You got to level "+str$(level)+" out of 5":sync:wait key:end
if level>5 then text 0,500,"Congratulations - you have won!":sync:wait key:end
sync
loop
 
 
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#)
 
if file exist(name$+".wav")=1 then delete file name$+".wav"
open to write 1,name$+".wav"
chunk=int(((length#/1000)*44100*16)/8) `sample size (no of samples * bitrate * channels / 8)
samples=int((length#/1000)*44100) `length *44100
restore
for x=1 to 40
   read byte2
   write byte 1, byte2
next x
write long 1,chunk
rem generate and write wave
for x=1 to samples
  output#=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#+tremelodepth#*sin(phi#)))*3.0
  inc theta#,vibratospeed#
  inc phi#,tremelospeed#
  dec frequency#,bend#
  if loudness#>0 then dec loudness#,decay#
  write word 1,output#
next x
close file 1
 
load sound name$+".wav",soundnumber
 
data 82:data 73:data 70:data 70:data 208:data 59:data 1:data 0:data 87
data 65:data 86:data 69:data 102:data 109:data 116:data 32:data 16
data 0:data 0:data 0:data 1:data 0:data 2:data 0:data 34:data 86:data 0
data 0:data 136:data 88:data 1:data 0:data 4:data 0:data 16:data 0
data 100:data 97:data 116:data 97
 
endfunction