--Level 1--

screen:blit(0,0,bg1)

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

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

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

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

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

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

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

--

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

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

if (player.x + 32 > gem1_1.x) and (player.x < gem1_1.x + 32) and (player.y + 32 > gem1_1.y) and (player.y < gem1_1.y + 32) then
   gem1 = "off"
elseif (player.x + 32 > gem1_2.x) and (player.x < gem1_2.x + 32) and (player.y + 32 > gem1_2.y) and (player.y < gem1_2.y + 32) then
   gem2 = "off"
elseif (player.x + 32 > gem2_1.x) and (player.x < gem2_1.x + 32) and (player.y + 32 > gem2_1.y) and (player.y < gem2_1.y + 32) then
   gem3 = "off"
elseif (player.x + 32 > gem2_2.x) and (player.x < gem2_2.x + 32) and (player.y + 32 > gem2_2.y) and (player.y < gem2_2.y + 32) then
   gem4 = "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
   gem5 = "off"
end

--Check for collision with enemy1--

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
   enemy1_1 = "off"
end

end

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

pad = Controls.read()

if gem1 == "off" and gem2 == "off" and gem3 == "off" and gem4 == "off" and gem5 == "off" and over == "false" then
   level = 2
end

if enemy1_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

collisionCheck1()
endCheck1()