Hi.
Here is a little “divertimento” of mine: guess the number. It is very simple, just for learning more about Codea.
Saludos ~O)
displayMode(FULLSCREEN)
function setup()
t1,h1,w1=vec3(0,0,0) -- some variables' initialization
t2,h2,w2=vec3(0,0,0)
hw=WIDTH/2 -- half width, half height
hh=HEIGHT/2
eh=HEIGHT-400 -- set height of different options
nh=HEIGHT-500
hhh=HEIGHT-600
func=menu
texts={} -- text array
texts[1]="Think a number between 1 and 15 and press GO (below)..."
texts[2]="1 2 3 4 5"
texts[3]="6 7 8 9 10"
texts[4]="11 12 13 14 15"
texts[5]="Is your number here?"
texts[6]="1 3 5 7 9 11 13 15"
texts[7]="2 3 6 7 10 11 14 15"
texts[8]="4 5 6 7 12 13 14 15"
texts[9]="8 9 10 11 12 13 14 15"
texts[10]="Your number is "
end
function draw()
font("Georgia")
fontSize(48)
fill(255, 255, 255, 255)
textWrapWidth(WIDTH-100)
func()
end
function menu()
background(56, 110, 222, 255)
title=texts[1]
textAlign(CENTER)
text(title,hw,HEIGHT-65)
text(texts[2],hw,HEIGHT-200)
text(texts[3],hw,HEIGHT-300)
text(texts[4],hw,HEIGHT-400)
fill(0, 255, 47, 255)
t3="Go!"
text(t3,hw,hhh)
w3,h3=textSize(t3)
suma=0
end
function menu2()
background(40,40,50)
text(texts[5],hw,HEIGHT-35)
if q==1 then text(texts[6],hw,HEIGHT-200)
elseif q==2 then text(texts[7],hw,HEIGHT-200)
elseif q==3 then text(texts[8],hw,HEIGHT-200)
elseif q==4 then text(texts[9],hw,HEIGHT-200)
end
t1="Yes"
text(t1,hw+300,eh)
w1,h1=textSize(t1)
t2="No"
text(t2,hw+300,nh)
w2,h2=textSize(t2)
t4="Restart"
text(t4,hw+300,hhh)
w4,h4=textSize(t4)
end
function menu3()
background(220, 53, 26, 255)
text(texts[10]..math.tointeger(suma).."!",hw-200,HEIGHT-400)
t4="Restart"
text(t4,hw+300,hhh)
end
function touched(t) -- looking for touched text
if t.state==BEGAN then
if func==menu and t.x>hw-w3/2 and t.x<hw+w3/2 and t.y>hhh-h3/2 and t.y<hhh+h3/2 then
q=1
func=menu2
elseif func==menu2 and t.x>hw-w1/2+300 and t.x<hw+w1/2+300 and t.y>eh-h1/2 and t.y<eh+h1/2 then
suma=suma+2^(q-1)
q=q+1
if q<5 then func=menu2 else
func=menu3 end
elseif func==menu2 and t.x>hw-w2/2+300 and t.x<hw+w2/2+300 and t.y>nh-h2/2 and t.y<nh+h2/2 then
q=q+1
if q<5 then func=menu2 else
func=menu3 end
elseif func ~= menu and t.x>hw-w4/2+300 and t.x<hw+w4/2+300 and t.y>hhh-h4/2 and t.y<hhh+h4/2 then
func=menu
end
end
end