link = Image.load("images/link/front.png")
coin = Image.load("images/minigames/rupee.png")
bg  = Image.load("images/minigames/drop-bg.png")
bgd = Image.load("images/minigames/drop-bgdown.png")
getready = Image.load("images/menu/getready.png")

white = Color.new(255,255,255)


math.randomseed(os.time())
rando = math.random(2,450)

score = 0
miss = 0

Player = {x = 100, y = 212, img = link}


Coin1 = {x=math.random(2,450),y=-20,img=coin}
Coin2 = {x=math.random(2,450),y=math.random(-100,1),img=coin}
Coin3 = {x=math.random(2,450),y=math.random(-100,1),img=coin}




function movement()
pad = Controls.read()

if pad:left() and Player.x > 1 then
Player.x = Player.x - 6
end

if pad:right() and Player.x < 449 then
Player.x = Player.x +6
end

end


function coin()
Coin1.y = Coin1.y + 3
Coin2.y = Coin2.y + 3
Coin3.y = Coin3.y + 3


if Coin1.y > 300 then
Coin1.y = math.random(-100,1)
Coin1.x = math.random(2,450)
miss = miss +1
end

if Coin2.y > 300 then
Coin2.y = math.random(-100,1)
Coin2.x = math.random(2,450)
miss = miss +1
end

if Coin3.y > 300 then
Coin3.y = math.random(-100,1)
Coin3.x = math.random(2,450)
miss = miss +1
end


end



function collision()

if (Player.x + 28 > Coin1.x) and (Player.x < Coin1.x + 20) and (Player.y + 32 > Coin1.y) and (Player.y < Coin1.y + 40) then
score = score +1
Coin1.y = -40
Coin1.x = math.random(2,450)
end

if (Player.x + 28 > Coin2.x) and (Player.x < Coin2.x + 20) and (Player.y + 32 > Coin2.y) and (Player.y < Coin2.y + 40) then
score = score +1
Coin2.y = math.random(-100,1)
Coin2.x = math.random(2,450)
end

if (Player.x + 28 > Coin3.x) and (Player.x < Coin3.x + 20) and (Player.y + 32 > Coin3.y) and (Player.y < Coin3.y + 40) then
score = score +1
Coin3.y = math.random(-100,1)
Coin3.x = math.random(2,450)
end

end



screen:blit(0,0,getready,false)

screen:print(2,70,"Player=",white)
screen:blit(60,60,Player.img)

screen:print(420,70,"=Coin!",white)
screen:blit(390,50,Coin1.img)

screen:print(140,163,"Dont miss   for high score!",white)
screen:blit(212,143,Coin1.img)

screen.flip()
screen.waitVblankStart(250)


Music.playFile("music/ds_links_adventures.xm",true)


while true do
pad = Controls.read()
screen.waitVblankStart()
screen:clear()

screen:blit(0,0,bg,false)

screen:blit(Player.x,Player.y,Player.img)

screen:blit(Coin1.x,Coin1.y,Coin1.img)
screen:blit(Coin2.x,Coin2.y,Coin2.img)
screen:blit(Coin3.x,Coin3.y,Coin3.img)


screen:blit(0,245,bgd,true)

screen:print(350,254,"Score:",white)
screen:print(410,254,"" ..score,white)
screen:print(350,264,"Missed:",white)
screen:print(410,264,"" ..miss,white)

screen:print(100,254,"Press START to Exit",white)
screen:print(100,264,"Press SELECT to Restart",white)


movement()
coin()
collision()

if pad:select() then
Music.stop()
dofile("drop.lua")
end

if pad:start() then 
Music.stop()
Music.playFile("music/4mat-menu12.mod")
dofile("index.lua")
end



screen.flip()
end