--------------------------------------------------- 
-- FBA Tutorials
--
-- Tutorial / 06 / Handling Input - Advanced
--
--------------------------------------------------- 
--
-- Advanced stylus input sample
--
--------------------------------------------------- 


loadimage(0, "button.png")

local buttonpress = false
local picwidth = imagewidth(0)
local picheight = imageheight(0) / 2
local x = 50
local y = 30
local tries=0


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

         
         if mousedown() > 0 then
            -- is mouse inside the area specified?
            if mousein(x, y, x+picwidth, y+picheight) then 
               
               if tries < 3 then 
                  tries = tries + 1
                  y = y + 50
                  return
               end
               
               buttonpress=true
            end
         else
             buttonpress=false
         end
         
         -- draw the button
         if buttonpress == true then
            drawimage(0,x,y,0,picheight,picwidth,picheight*2)
            print(x, y+30, "YEAH!! YOU DID IT :D", 0,0,0)
         else
            drawimage(0,x,y,0,0,picwidth,picheight)
         end      

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