starter game 15

Here’s another starter game if someone wants to expand on it. The object is to see how fast you can tap the numbers from 1 to 100. The numbers are mixed up in a 10 by 10 square. The number you’re supposed to tap is shown at the top. If you tap the correct number it turns green, tap the wrong number and the tap number decremented by 1. Every 20 seconds the number you’re looking for is also decremented by 1 and the numbers are re-shuffled. Keep an eye on the number to tap. Once you tap all 100 numbers, your total time is shown. Double tap the screen to replay.


displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)

function setup()
    limit=21    -- find limit
    found=1
    done=false
    startTime=os.time()
    totalTime=0
    create(100)
end

function create(size)
    tab={}
    for z=1,size do
        table.insert(tab,z)
    end
    for z=1,size do
        local n=math.random(size+1-z)
        table.insert(tab,tab[n])
        table.remove(tab,n)
    end
    findTime=os.time()+limit
end

function draw()
    background(40, 40, 50)
    fontSize(30)
    local count=0
    for x=1,10 do
        for y=1,10 do
            count=count+1
            fill(255)
            if tab[count]<found then
                fill(0,255,0)
            end
            rect(-65+x*75,y*75,75,75)
            fill(255,0,0)
            text(tab[count],-65+x*75+75/2,y*75+75/2)
        end
    end
    fill(255)
    if done then
        text("Total time  "..totalTime.."  seconds.",WIDTH/2,HEIGHT-50)
        text("Double tap to play again",WIDTH/2,HEIGHT-150)
    else
        text("Total seconds  "..os.time()-startTime,200,HEIGHT-50)
        local diff=findTime-os.time()
        text("Seconds remaining  "..diff,200,HEIGHT-150)
        if diff<=0 then
            sound(SOUND_BLIT, 45070)
            create(100)
            if found>1 then
                found=found-1
            end
        end
        fontSize(70)
        text("Tap  "..found,WIDTH-200,HEIGHT-100)
    end
end

function touched(t)
    if t.state==BEGAN then
        if done then
            if t.tapCount==2 then
                restart()
            end
            return
        end
        x=math.floor((t.x+65)/75)
        y=math.floor((t.y)/75)
        if x>=1 and x<=10 and y>=1 and y<=10 then
            if tab[(x-1)*10+y]==found then
                found=found+1
            elseif found>1 then
                found=found-1
            end
            if found>100 then
                totalTime=os.time()-startTime
                done=true
            end
        end
    end    
end

646 seconds… that’s the time it took for me to finish o.O

this is such a ‘simple’ idea, but so challenging, and as always, nicely coded by @dave1707, good job sir :slight_smile:

edit: 419 was my second time, improving :slight_smile:

@stevon8ter That’s better than I’ve ever done. I haven’t gotten out of the 500’s yet. Sometimes I just can’t find the next number and end up going back one without going forward.

@dave1707 yeah it’s a rather challenging game :slight_smile: my tactic is looking at 2 rows at the same time and hoping I don’t look over it xD tho it’s also a bit based on luck, if the numbers are close to eachother etc

It’s a really nice and a bit adicting game :slight_smile:

EDIT: I was able to reduce my time to EXACTLY 400 second :stuck_out_tongue:

@stevon8ter I tried your method of scanning 2 rows and I managed to get to 409. Still not as good as you.

@dave1707 that’s pretty impressive :slight_smile: I gotta stop playing now tho because my ipad’s almost dead, but I’m sure that I’ll be spending more time on this app :slight_smile:

I even think it would be appstore worthy (with a proper menu, etc)
Tho I don’t think I’d wanna pay for it

@stevon8ter I don’t have a Mac or license and don’t plan on giving Apple any more money. They have too much already. This game was for anyone to take and do what they want with it, along with any of my other “starter game” examples. Besides, with so many apps on the App Store, there’s probably something like this already out there.

@dave1707 I completely understand and respect your choice, I also wasn’t saying you should do it, I’m just saying that it’s really nicely worked out, and I think everyone on this forum would agree with me if I say that we appreciate your starter games, I’ve learned alot from them already :slight_smile:

This is a pretty cool game! Harder than it sounds!

If I wanted to reset the timer when you tap the correct number, is findTime the variable that you reset to 21? Seems to be bugging out when I try findTime, and limit or diff don’t do anything. Looks like limit, diff, and findTime are all tied to the time left to tap.

Good code to learn about tying a bunch of timers to os.time.

Such a cool game in 85 lines of code!

@Crumble limit=21 right after setup(). Just change 21 to whatever count down value you want.

EDIT: Ignore my comment, I misread it. I know what you mean now.

@Crumble Find the code I show below in the touched() function and add the line that I have marked “add this line”

        if x>=1 and x<=10 and y>=1 and y<=10 then
            if tab[(x-1)*10+y]==found then
                found=found+1
                findTime=os.time()+limit      -- add this line
            elseif found>1 then
                found=found-1
            end

High score 316

@JakAttak The last time I had 316, I was still looking for numbers in the 30’s. My problem is I get to a point where I can’t find the number I’m looking for and I use up 20 seconds and then go back one number.

Here’s my version, mostly just visual changes, adds a second every time you get one, uses ElapsedTime for timers so it is more exact (so the colors shift smoothly):

displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)

function setup()
    limit = 20    -- find limit
    scoreadd = 1
    found = 1
    done = false
    startTime = ElapsedTime
    totalTime = 0
    create(100)
    
    music("Game Music One:Nothingness", true)
end

function create(size)
    tab={}
    for z=1,size do
        table.insert(tab,z)
    end
    for z=1,size do
        local n=math.random(size+1-z)
        table.insert(tab,tab[n])
        table.remove(tab,n)
    end
    findTime = ElapsedTime + limit
end

function draw()
    local diff = findTime - ElapsedTime
    local amnt = math.min(1, diff / limit)
    local backcol = color(255 - 255*amnt, 180*amnt, 255*amnt, 255)
    background(backcol)
    fontSize(WIDTH / 30)
    
    fill(255)
    if done then
        text("Total time  " .. math.floor(totalTime + 0.5) .. "  seconds.", WIDTH / 2, HEIGHT / 2 + fontSize())
        text("Double tap to play again", WIDTH / 2, HEIGHT / 2 - fontSize())
    else
        totalTime = ElapsedTime - startTime
        
        local count = 0
        local min = math.min(WIDTH, HEIGHT)
        local rsize = min / math.sqrt(#tab)
        local lw, lh = WIDTH / 2 - min / 2, HEIGHT / 2 - min / 2
        for x = 0, math.sqrt(#tab) - 1 do
            for y = 0, math.sqrt(#tab) - 1 do
                count = count + 1
                fill(255)
                if tab[count] < found then
                    fill(backcol)
                end
                local nx, ny = lw + x * rsize, lh + y * rsize
                rect(nx, ny, rsize, rsize)
                local r,g,b = fill()
                fill(255-r, 255-g, 255-b)
                text(tab[count], nx + rsize / 2, ny + rsize / 2)
            end
        end
        
        text("Time left: " .. math.floor(diff+0.5), WIDTH / 2, HEIGHT - fontSize())
        text("Total seconds  " .. math.floor(totalTime + 0.5), WIDTH / 2, fontSize())
        if diff <= 0 then
            sound("Game Sounds One:Block 3")
            create(100)
            found = math.max(found - 1, 1)
        end
        fontSize(WIDTH / 2) fill(255 - (255*amnt), 0, 0, 127) fill(0, 127)
        text(found, WIDTH / 2, HEIGHT / 2)
    end
end

function touched(t)
    if t.state == BEGAN then
        if done then
            if t.tapCount == 2 then
                restart()
            end
            return
        end
        local min = math.min(WIDTH, HEIGHT)
        x = math.floor((t.x - ((WIDTH - min) / 2)) / (min / math.sqrt(#tab))) + 1
        y = math.floor((t.y - ((HEIGHT - min) / 2)) / (min / math.sqrt(#tab))) + 1
        if x >= 1 and x <= 10 and y >= 1 and y <= 10 then
            if tab[(x-1)*math.sqrt(#tab)+y] == found then
                found = found + 1
                findTime = math.min(findTime + scoreadd, ElapsedTime + limit)
                sound("Game Sounds One:Block 1")
            elseif found > 1 then
                found = found - 1
                sound("Game Sounds One:Menu Select")
            end
            
            if found > #tab then
                totalTime = ElapsedTime - startTime
                done = true
            end
        end
    end    
end

@JakAttak Nice changes, but it still doesn’t make me any faster. I still get into situations where I can’t find a number until the screen changes.

@dave1707, another change I considered was having the correct cube highlight for the last second, and then change all of them except that one so you can move on faster after being stuck

@JakAttak That was my intent when I posted it. For people to take and change it however they wanted. But don’t make it too easy. Have you looked at my physics question. That has me confused.