Here’s something I thru together just to pass the time. To play, touch an image and slide it up, down, left, or right one square to a matching image. The image you slide will disappear and any image above it will take it’s place. The object is to eliminate as many images as you can. The text will tell you how many images are left, your low score and how many valid moves are left. You’ll get a message when there are no more valid move and the game is over. It should work in landscape or portrait mode. This was written on an iPad Air, so I’m not sure what it looks like on a smaller or larger screen.
viewer.mode=FULLSCREEN
function setup()
--clearProjectData()
score=13*19
xVal,yVal=19,13
if HEIGHT>WIDTH then
xVal,yVal=13,19
end
lowScore=readProjectData("lowScore",score)
spr={asset.builtin.Planet_Cute.Character_Pink_Girl,
asset.builtin.Planet_Cute.Character_Horn_Girl,
asset.builtin.Planet_Cute.Character_Cat_Girl,
asset.builtin.Planet_Cute.Character_Princess_Girl,
asset.builtin.Planet_Cute.Character_Boy}
selected=0
moves={-1,0,1,0,0,-1,0,1}
tab={}
for x=1,xVal do
tab[x]={}
for y=1,yVal do
tab[x][y]=math.random(5)
end
end
checkPieces()
end
function draw()
background(0)
stroke(255)
strokeWidth(2)
fill(128)
for x=1,xVal do
for y=1,yVal do
rect(x*50,y*50,52)
if tab[x][y]>0 then
sprite(spr[tab[x][y]],x*50+25,y*50+35,50)
end
end
end
fill(255)
fontSize(20)
text("Score "..score.." Low Score "..string.format("%d",lowScore).." Valid moves left "..count,WIDTH/2,HEIGHT-10)
if gameOver then
fontSize(70)
fill(255)
text("NO MORE MOVES",WIDTH/2,HEIGHT/2)
end
end
function touched(t)
x=math.floor(t.x/50)
y=math.floor(t.y/50)
if x<1 or x>xVal or y<1 or y>yVal then
fillGap()
return
end
if t.state==BEGAN and tab[x][y]>0 then
selected=tab[x][y]
selX,selY=x,y
end
if t.state==ENDED and selected>0 then
if validMove() and selected==tab[x][y] then
tab[selX][selY]=0
selected=0
score=score-1
checkScore()
end
fillGap()
end
end
function validMove()
if selX==x and (selY==y+1 or selY==y-1) then
return true
elseif selY==y and (selX==x+1 or selX==x-1) then
return true
end
return false
end
function checkScore()
if score<lowScore then
lowScore=score
saveProjectData("lowScore",lowScore)
end
end
function fillGap()
for x=1,xVal do
for y=1,yVal do
if tab[x][y]==0 then
for z=1,yVal-y do
if tab[x][y+z]~=0 then
tab[x][y]=tab[x][y+z]
tab[x][y+z]=0
break
end
end
end
end
end
checkPieces()
end
function checkPieces()
count=0
gameOver=true
for x=1,xVal do
for y=1,yVal do
if tab[x][y]>0 then
for h=1,8,2 do
x1=x+moves[h]
y1=y+moves[h+1]
if x1>=1 and x1<=xVal and y1>=1 and y1<=yVal then
if tab[x][y]==tab[x1][y1] then
gameOver=false
count=count+1
end
end
end
end
end
end
end