Here’s something I threw together that I thought might interest one of the new coders. You can take this and add whatever you want to spruce it up. You can modify the font, the text, the colors, the menu, whatever. I’m not saving any of the scores when the game ends, so maybe you can add a routine to save the data and read it back in. The purpose of this is to tap a red square to reveal a number. You have to select the numbers in order starting at 1. If the number isn’t in order, it will be covered when the next square is selected. You have to remember where the numbers were to keep your tap count low. The square size will increase after each game or you can select a square size.
supportedOrientations(LANDSCAPE_ANY)
function setup()
rectMode(CENTER)
displayMode(FULLSCREEN)
max=12
play=false
side=0
level=0
score={}
for z=1,max do
score[z]=0
end
showMenu=true
end
function setup2()
play=true
tries=0
side=side+1
if side>max then
side=max
end
level=side
squares=side*side
offsetX=WIDTH/2-side/2*50-25
offsetY=HEIGHT/2-side/2*50-25
nbrTab={} -- table for numbers that are in order
for z=1,squares do
zz=tostring(z)
nbrTab[z]=false
end
tab={} -- table of random numbers
for z=1,squares do -- fill squares with random numbers
zz=getRandomNbr()
tab[z]=vec2(zz,0)
end
next=1
end
function menu()
fontSize(40)
str=[[
How good is your memory.
The object is to select the numbers in order.
Tap a red square to reveal a number.
If that number is 1 or the next number in order,
it will remain showing when you tap another square.
If it's not the next number, then it will be covered
again when you select another red square.
Double tap to start.
]]
text(str,WIDTH/2,HEIGHT/2)
fontSize(20)
end
function getRandomNbr() -- get random number not selected already
n=math.random(1,squares)
nn=tostring(n)
if not nbrTab[nn] then
nbrTab[nn]=true
return(n)
else
loop=true
while loop do
n=n+1
if n>squares then
n=1
end
nn=tostring(n)
if not nbrTab[nn] then
nbrTab[nn]=true
return(n)
end
if n>200 then
close() -- while loop error, exit
end
end
end
end
function draw()
background(40, 40, 50)
fill(255)
if showMenu then
menu()
return
end
strokeWidth(2)
textMode(CORNER)
for z=1,max do
text("Level "..z.." "..score[z],WIDTH-170,HEIGHT-z*60)
end
textMode(CENTER)
z=1
for y=1,side do
for x=1,side do
stroke(255)
fill(255,0,0)
if tab[z].y==1 or tab[z].y==2 then
fill(255)
end
rect(x*50+offsetX,y*50+offsetY,48,48)
fill(255,0,0)
text(tab[z].x,x*50+offsetX,y*50+offsetY)
z=z+1
end
end
fill(255)
if not play then
text("Number of tries for level "..level.." was "..tries,WIDTH/2,HEIGHT-20)
text("Double tap for next level.",WIDTH/2,HEIGHT-50)
text("Tap a level at the right to goto that level.",WIDTH/2,HEIGHT-80)
else
text("Current number of tries "..tries,WIDTH/2,HEIGHT-40)
text("Select a red square to reveal a number.",WIDTH/2,40)
end
end
function touched(t)
if t.state==BEGAN then
if t.tapCount==2 and not play then
showMenu=false
setup2()
return
end
if t.x>WIDTH-200 and not showMenu then -- select level
for x=1,max do
if t.y>HEIGHT-x*60-30 and t.y<HEIGHT-x*60+30 then
side=x-1
setup2()
return
end
end
return
end
if play then
for z=1,squares do -- reset selected out of order number
if tab[z].y==1 then
tab[z].y=0
end
end
z=1
for y=1,side do
for x=1,side do
if t.x>(x*50+offsetX-25) and t.x<(x*50+offsetX+25) and
t.y>(y*50+offsetY-25) and t.y<(y*50+offsetY+25) then
tries=tries+1
if tab[z].y~=2 then -- square selected
tab[z].y=1 -- show number
end
if tab[z].x==next then -- number in order
tab[z].y=2 -- set to keep showing
next=next+1
if next>squares then -- game over
score[level]=tries
play=false
end
end
end
z=z+1
end
end
end
end
end