--****INITIALIZE****--
dofile("init.lua")

--***********GAME LOOP***********--
while running == true do -- if start is pressed quit to luaplayer
    pad = Controls.read()

	screen:clear()

	currentTime = gameTimer:time()

	if pad:select() then
		screen:save("screenshot.png")
	end

	if status == "title" then
		if pad:cross() or (currentTime - oldTime) >= 5000 then  -- press 'X' or wait 5 secs
			status = "playfield"
		end
	elseif status == "playfield" then
	    if pad:start() then
	    	status = "IGM"
        else
			movePlayer() -- Moves the player around
		end
	end
	
	blitStage() -- put stuff onscreen

	if status == "IGM" then   -- MUST be called after blitStage so it overlays
	    showMenu()
	end

	screen.waitVblankStart()
	screen.flip()
end
--*********END GAME LOOP*********--


--Coding by zion & h4rdc0m, please only use this code for education -- -- reusing this code is the same as stealing.-
--Thanks to jman420 for some helpfull coding advice.-
--Thanks to PSPDemon for the sweet background-
--Thanks to gunntims for some helpful tips-
--And thanks to dcemu! you rock!