--Level 2--

screen:blit(0,0,bg2)

screen:print(100,20,"Level 2")

if gem6 == "on" then
   screen:blit(gem1_3.x, gem1_3.y, gem1_3.img)
end

if gem7 == "on" then
   screen:blit(gem1_4.x, gem1_4.y, gem1_4.img)
end

if gem8 == "on" then
   screen:blit(gem2_3.x, gem2_3.y, gem2_3.img)
end

if gem9 == "on" then
   screen:blit(gem2_4.x, gem2_4.y, gem2_4.img)
end

if gem10 == "on" then
   screen:blit(gem3_1.x, gem3_1.y, gem3_1.img)
end

if gem11 == "on" then
   screen:blit(gem3_2.x, gem3_2.y, gem3_2.img)
end

if gem12 == "on" then
   screen:blit(gem3_3.x, gem3_3.y, gem3_3.img)
end

if gem13 == "on" then
   screen:blit(gem3_4.x, gem3_4.y, gem3_4.img)
end

if enemy2_1 == "on" then
   screen:blit(enemy1.x, enemy1.y, enemy1.img)
end

if enemy3_1 == "on" then
   screen:blit(enemy2.x, enemy2.y, enemy2.img)
end

--

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

function collisionCheck2()
--Check for collision with gems--

if (player.x + 32 > gem1_3.x) and (player.x < gem1_3.x + 32) and (player.y + 32 > gem1_3.y) and (player.y < gem1_3.y + 32) then
   gem6 = "off"
elseif (player.x + 32 > gem1_4.x) and (player.x < gem1_4.x + 32) and (player.y + 32 > gem1_4.y) and (player.y < gem1_4.y + 32) then
   gem7 = "off"
elseif (player.x + 32 > gem2_3.x) and (player.x < gem2_3.x + 32) and (player.y + 32 > gem2_3.y) and (player.y < gem2_3.y + 32) then
   gem8 = "off"
elseif (player.x + 32 > gem2_4.x) and (player.x < gem2_4.x + 32) and (player.y + 32 > gem2_4.y) and (player.y < gem2_4.y + 32) then
   gem9 = "off"
elseif (player.x + 32 > gem3_1.x) and (player.x < gem3_1.x + 32) and (player.y + 32 > gem3_1.y) and (player.y < gem3_1.y + 32) then
   gem10 = "off"
elseif (player.x + 32 > gem3_2.x) and (player.x < gem3_2.x + 32) and (player.y + 32 > gem3_2.y) and (player.y < gem3_2.y + 32) then
   gem11 = "off"
elseif (player.x + 32 > gem3_3.x) and (player.x < gem3_3.x + 32) and (player.y + 32 > gem3_3.y) and (player.y < gem3_3.y + 32) then
   gem12 = "off"
elseif (player.x + 32 > gem3_4.x) and (player.x < gem3_4.x + 32) and (player.y + 32 > gem3_4.y) and (player.y < gem3_4.y + 32) then
   gem13 = "off"
end

--Check for collision with enemy2--

if (player.x + 32 > enemy1.x) and (player.x < enemy1.x + 32) and (player.y + 32 > enemy1.y) and (player.y < enemy1.y + 32) then
   enemy2_1 = "off"
end

--Check for collision with enemy3--

if (player.x + 32 > enemy2.x) and (player.x < enemy2.x + 32) and (player.y + 32 > enemy2.y) and (player.y < enemy2.y + 32) then
   enemy3_1 = "off"
end

end

function endCheck2()
--Check for end of level--

pad = Controls.read()

if gem6 == "off" and gem7 == "off" and gem8 == "off" and gem9 == "off" and gem10 == "off" and gem11 == "off" and gem12 == "off" and gem13 == "off" and over == "false" then
   level = 3
end

if enemy2_1 == "off" or enemy3_1 == "off" then
   screen:blit(0,0,busted)
   screen:print(150,200,"PRESS START TO RESTART")
   over = "true"
end

if over == "true" and pad:start() then
   dofile("script.lua")
end

end

collisionCheck2()
endCheck2()