--by littlevish
--If you're looking at this, I know that you're trying to figure out how it works. Wow, look at that. I read your mind again!

--images
startImg = Image.load("images/start.jpg")
instructionsImg = Image.load("images/instructions.jpg")
card1 = Image.load("images/1.jpg")
card2 = Image.load("images/2.jpg")
card3 = Image.load("images/3.jpg")
card4 = Image.load("images/4.jpg")
card5 = Image.load("images/5.jpg")
reading = Image.load("images/mindz.jpg")
final = Image.load("images/answer.jpg")
screenColor = Color.new(0,0,0)
textColor = Color.new(0,0,0)

--variables
pressStart = 1
firstCard = 0
secondCard = 0
thirdCard = 0
fourthCard = 0
fifthCard = 0
firstLeft = 1
secondLeft = 2
thirdLeft = 4
fourthLeft = 8
fifthLeft = 16
answer = 0
currentCard = instructionsImg
instructionsVar = 0

--misc
arial = Font.load("images/arial.ttf")
arial:setPixelSizes(0,75)

--functionz

function start()
      pressStart = 0
	instructionsVar = 1
      screen:clear(screenColor)
	screen:blit(0,0,startImg)
	screen.flip()
	while not Controls.read():start() do screen.waitVblankStart() end
end

function instructions()
      instructionsVar = 0
      screen:clear(screenColor)
	screen:blit(0,0,instructionsImg)
	screen.flip()
	while not Controls.read():start() do screen.waitVblankStart() end
end

function finish()
	finishi = 1
	screen:clear(screenColor)
	screen:blit(0,0,final)
	screen:fontPrint(arial,203,140,answer,textColor)
	screen.flip()
end

function gotoNext()
	if currentCard == instructionsImg then
		currentCard = card1
	elseif currentCard == card1 then
		currentCard = card2
	elseif currentCard == card2 then
		currentCard = card3
	elseif currentCard == card3 then
		currentCard = card4
	elseif currentCard == card4 then
		currentCard = card5
	elseif currentCard == card5 then
		finish()
	end
end

function score()
	if currentCard == card1 then
		answer = answer + firstLeft
		gotoNext()
	elseif currentCard == card2 then 
		answer = answer + secondLeft
		gotoNext()
	elseif currentCard == card3 then 
		answer = answer + thirdLeft
		gotoNext()
	elseif currentCard == card4 then 
		answer = answer + fourthLeft
		gotoNext()
	elseif currentCard == card5 then 
		answer = answer + fifthLeft
		gotoNext()
	end
end

while true do
	pad = Controls.read()
	if pressStart == 1 then
		start()
	elseif finishi == 1 then
		finish()
	if oldpad ~= pad then
			if pad:cross() then
				answer = 0
				currentCard = card1
				finishi = 0
			elseif pad:circle() then
				System.Quit()
			end	
	end
			
	elseif instructionsVar == 1 then
		instructions()
	else
	if oldpad ~= pad then
		if pad:cross()then 
			score()
		elseif pad:circle() then
			gotoNext()
		elseif pad:start() then
			gotoNext()
		end
	end
		screen:clear(screenColor)
		screen:blit(0,0,currentCard)
		screen.waitVblankStart()
		screen.flip()
	end
oldpad = pad
end


