--------------------------------------------------- 
-- FBA Tutorials
--
-- Tutorial / 07 / Sounds and Music
--
--------------------------------------------------- 
--
-- Advanced stylus input sample
--
--------------------------------------------------- 


-- you could also use:
-- soundslot = loadsound("do.wav")
--
loadsound(0, "do.wav")
loadsound(1, "re.wav")
loadsound(2, "mi.wav")
loadsound(3, "fa.wav")
loadsound(4, "sol.wav")
loadsound(5, "la.wav")
loadsound(6, "si.wav")
loadsound(7, "do2.wav")

loadmusic(0, "padawan.mod")
playmusic(0)
local playing = true


function onmainloop()	
         clear(255,255,255)

         print(10, 70, "Click on a box", 0,0,0)
                  
         for a=0, 7 do
             pos = 5+(a*30+10*a);
             
             color1 = 255
             color2 = 0
             color3 = 0

             if mousein(pos, 100, pos+30, 130) then

                if mousedown() > 0 then 
                   if mousedown() == 1 then 
                      playsound(a)
                   end
                   color2 = 255
                end

             end
             
             fillrect(pos, 100, pos+30, 130, color1, color2, color3)

         end
 

         if playing then
            fillrect(5, 150, 80, 180, 0,0,255)
         else
            fillrect(5, 150, 80, 180, 255,0,255)
         end
         
         if mousein(5, 150, 80, 180) and mousedown() == 1 then
            if playing then
            
               stopmusic(0)
               playing = false
               
            else

               playmusic(0)
               playing = true

            end
         end
         
         if numkeypress( keyfire1() ) > 0 or numkeypress( keyfire2() ) > 0 or numkeypress( keyfire3() ) > 0 then
            quit()
         end

end
