Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Flood It

edited July 2012 in Questions Posts: 266

has any one created code for this game:
http://floodit.appspot.com
It's called many different things, but I just wanted to know if it's possible to create this in codea.
I would really need some help because I'm new to coding at 15 years old. Thanks

Comments

  • Posts: 447

    pretty interesting game. It's a good codea project indeed.

  • Posts: 447

    this is a very cool game. Have been playing a vs the computer version and seems like there's a lot of strategy

  • Posts: 20

    Here you go, in 80 lines. Just had to code it after seeing this post. Had fun doing it. Didn't realize the flood fill algo could be so simple (Go recurrsion!).

    function setup()
        displayMode(FULLSCREEN)
        
        grid = {}  
        turnsLeft = 25
        
        local r,c
        for r = 1,14 do
            grid[r] = {}
            for c = 1,14 do
                grid[r][c] = math.random(6)
            end
        end
        
        colors = {}
        colors[1] = color(255, 0, 0, 255)
        colors[2] = color(0, 0, 255, 255)
        colors[3] = color(0, 255, 0, 255)
        colors[4] = color(255, 255, 0, 255)
        colors[5] = color(255, 0, 255, 255)
        colors[6] = color(0, 255, 255, 255)
    end
    
    function draw()
        background(40, 40, 50)
    
        pushStyle()
        noSmooth()
        local r,c,col
        for r, row in ipairs(grid) do
            for c, cellVal in ipairs(row) do
                col = colors[cellVal]
                fill(col.r, col.g, col.b)
                rect(((c - 1) * 50) + 300, ((r - 1) * 50) + 25, 50, 50)
            end
        end
        popStyle()
        
        pushStyle()
        strokeWidth(3)
        stroke(255, 255, 255, 255)
        for c, col in ipairs(colors) do
            fill(col.r, col.g, col.b)
            ellipse(150, ((c - 1) * 120) + 100, 100)
        end
        popStyle()
        
        text(turnsLeft, 15, HEIGHT - 15)
    end
    
    function touched(touch)
        
        if touch.state == ENDED and turnsLeft > 0 then
            local x,y,c
            x = 150
            for c in ipairs(colors) do
                y = ((c - 1) * 120) + 100
                if lineDist(x, y, touch.x, touch.y) <= 50 then
                    floodFill(grid, 14, 1, grid[14][1], c)
                    turnsLeft = turnsLeft - 1
                end
            end
        end
    end
    
    function lineDist(x1, y1, x2, y2)
        return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2))
    end
    
    function floodFill(grid, row, col, target, new)
        if row < 1 or col < 1 or row > #grid or col > #grid[row] then return end
        
        if grid[row][col] == target then
            grid[row][col] = new
            floodFill(grid, row + 1, col, target, new)
            floodFill(grid, row - 1, col, target, new)
            floodFill(grid, row, col + 1, target, new)
            floodFill(grid, row, col - 1, target, new)
        end
    end
    
  • Posts: 447

    @Eric, that's short and looks good too, very nice. Now i want a two player version with an AI that beats me every time. I downloaded a feel free apps, none had two player versions.

  • Posts: 266

    @ruilov that's exactly what I was thinking of. Maybe an iPad app and the two different players would have the same puzzle and first one to finish with the least moves wins. I haven't even downloaded the app yet b/c I don't have enough money. Looking forward to it now!

  • Posts: 447
  • BortelsBortels Mod
    Posts: 1,557

    there is (was?) an app named "battleflood" in the app store that was 2 player this - but it broke in ios5 (got really really slow) and is apparently unmaintained. I liked it - I'd play a 2 player version.

  • Posts: 1,392

    Hi All,

    Been working on this, not complete yet - needs tidying and debugging but playable. Here's my latest version. Will put on GitHub and post when updates available:

    function setup()
        displayMode(FULLSCREEN)
        
        grid = {}  
        turnsStart = 25
        turnsUsed = 0
        turnsLeft = turnsStart - turnsUsed
        -- using a multiple of 14 for the cells used in cellNo
        cellNo = 14
        cellW = 48*14/cellNo
        gridWidth = cellNo*cellW  
        offsetLeft = (WIDTH - gridWidth)/2
        offsetTop = (HEIGHT - gridWidth)/2
        totCells = cellNo*cellNo
        maxCells = 0
        midX = WIDTH/2
        midY = HEIGHT/2
        
        local r,c
        for r = 1,56 do
            grid[r] = {}
            for c = 1,56 do
                grid[r][c] = math.random(6)
            end
        end
        
        colors = {}
        colors[1] = color(255, 0, 0, 255)
        colors[2] = color(0, 0, 255, 255)
        colors[3] = color(0, 255, 0, 255)
        colors[4] = color(255, 255, 0, 255)
        colors[5] = color(255, 0, 255, 255)
        colors[6] = color(0, 255, 255, 255)
        
        colNumber = {}
        statReset()
    end
    
    function draw()
        background(40, 40, 50)
        gridDraw()    
        selectors()
        
        font("Georgia-Bold")
        fontSize(72)
        fill(255, 0, 4, 255)
        text("Flood-it", midX, HEIGHT-72)
        fontSize(16)
        text("You have used "..turnsUsed.." turns from "..turnsStart.." in "..totCells.." tiles", midX, HEIGHT - 150)
        if maxCells == totCells then
            messageWin()
        elseif turnsLeft == 0 then
            messageLose()
        end
    end
    
    function touched(touch)
        
        if touch.state == ENDED and turnsLeft > 0 then
            local x,y,c
            y = 100
            for c in ipairs(colors) do
                x = ((c - 1) * 120) + 100
                if lineDist(x, y, touch.x, touch.y) <= 50 then
                    floodFill(grid, cellNo, 1, grid[cellNo][1], c)
                    turnsUsed = turnsUsed + 1
                    turnsLeft = turnsStart - turnsUsed
                end
            end
            statReset()
            colourStats()
        end
    end
    
    function lineDist(x1, y1, x2, y2)
        return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2))
    end
    
    function floodFill(grid, row, col, target, new)
        if row < 1 or col < 1 or row > cellNo or col > cellNo then return end
        
        if grid[row][col] == target then
            grid[row][col] = new
            floodFill(grid, row + 1, col, target, new)
            floodFill(grid, row - 1, col, target, new)
            floodFill(grid, row, col + 1, target, new)
            floodFill(grid, row, col - 1, target, new)
        end
    end
    
    function selectors()
        pushStyle()
        strokeWidth(3)
        stroke(255, 255, 255, 255)
        for c, col in ipairs(colors) do
            fill(col.r, col.g, col.b)
            ellipse(((c - 1) * 120) + 100, 100, 50)
            fill(0, 0, 0, 255)
            text(colNumber[c],((c - 1) * 120) + 100, 100)
        end
        popStyle()  
    end
    
    function gridDraw()
        pushStyle()
            noSmooth()
            fill(0, 0, 0, 255)
            rect(offsetLeft-10, offsetTop-10,WIDTH-offsetLeft-28,HEIGHT-offsetTop-156)
            strokeWidth(3)
            stroke(248, 2, 47, 255)
    rect(offsetLeft-10, offsetTop-10,WIDTH-offsetLeft-28,HEIGHT-offsetTop-156)    
            noStroke()  
            local r,c,col
            for r = 1, cellNo do
                for c = 1, cellNo do
                    cellVal = grid[r][c]
                    col = colors[cellVal]
                    fill(col.r, col.g, col.b)
                    rect(((c - 1) * cellW) + offsetLeft, ((r - 1) * cellW) + offsetTop, cellW, cellW)
                end
            end
        popStyle()
    end
    
    function colourStats()
        local r,c, l
        for r = 1, cellNo do
            for c = 1, cellNo do
                cellVal = grid[r][c]
                colNumber[cellVal] = colNumber[cellVal] + 1
            end
        end
        maxCells = colNumber[1]
        for l = 2,6 do
            if maxCells < colNumber[l] then
                maxCells = colNumber[l]
            end
        end
    end
    
    function statReset()
        local l
        for l = 1,6 do
            colNumber[l] = 0
        end 
    end
    
    function messageWin()
        pushStyle()
            fill(124, 108, 45, 255)
            rect(midX-200, midY-200, 400, 400)
            fill(215, 212, 165, 255)
            rect(midX-197, midY-197, 394, 394)
            font("Georgia-Bold")
            fontSize(32)
            fill(0,0,0,255)
            text("CONGRATULATIONS", WIDTH/2, midY+160)
            fontSize(18)
            text("You completed the target of : "..totCells.." tiles", WIDTH/2, midY+130)
            text("In a total of : "..turnsUsed.." moves", WIDTH/2, midY+110)     
            
        popStyle() 
    end
    
    function messageLose()
        pushStyle()
            fill(124, 108, 45, 255)
            rect(midX-200, midY-200, 400, 400)
            fill(215, 212, 165, 255)
            rect(midX-197, midY-197, 394, 394)
            font("Georgia-Bold")
            fontSize(32)
            fill(0,0,0,255)        
            text("HARD LUCK", WIDTH/2, midY+160)
            fontSize(18)       
            text("You converted a total of : "..maxCells.." tiles", WIDTH/2, midY+130)
            text("From a target of : "..totCells.." tiles", WIDTH/2, midY+110)
            text("Which is a percentage of : "..maxCells*100/totCells.."%", WIDTH/2, midY+90)
        popStyle()
    end
    

    Hope you like it.

    Any suggestions for bugs - please feel free to make any suggestions.

    Bri_G

    :)

  • Posts: 266

    @Bri_G my only suggestion would be to fix the orientation. This causes a problem because then the text blends in.

  • Posts: 1,392

    Hi @veeeralp,

    Thanks for the feedback. One of my objectives is to enable running in any mode. But, first I'd like to get the system optimised. So, when you say text merging in - at which point is it merging. The reporting of stats etc, at the end, is not finished.

    There may be other Codea users making their own versions, it will be interesting to see what they have made.

    Thanks,

    Bri_G

    :)

  • Posts: 266

    this is mine

  • edited July 2012 Posts: 266
    function setup()
        displayMode(FULLSCREEN_NO_BUTTONS)
        
        supportedOrientations(LANDSCAPE_ANY)
        
        grid = {}  
        turnsLeft = 25
        
        local r,c
        for r = 1,14 do
            grid[r] = {}
            for c = 1,14 do
                grid[r][c] = math.random(6)
            end
        end
        
        colors = {}
        colors[1] = color(255, 0, 0, 255)
        colors[2] = color(0, 0, 255, 255)
        colors[3] = color(0, 255, 0, 255)
        colors[4] = color(255, 255, 0, 255)
        colors[5] = color(255, 0, 255, 255)
        colors[6] = color(117, 38, 137, 0)
    end
    
    function draw()
        background(255, 255, 255, 255)
    
        pushStyle()
        noSmooth()
        local r,c,col
        for r, row in ipairs(grid) do
            for c, cellVal in ipairs(row) do
                col = colors[cellVal]
                fill(col.r, col.g, col.b)
                rect(((c - 1) * 50) + 300, ((r - 1) * 50) + 25, 50, 50)
            end
        end
        popStyle()
        pushStyle()    
        strokeWidth(0)
        stroke(255, 255, 255, 255)
        for c, col in ipairs(colors) do
            fill(col.r, col.g, col.b)
            ellipse(150, ((c-1) * 120) + 74, 100)
        end
        
        
        popStyle()
        rotate(90)
        font("HelveticaNeue-Light")
        fill(235, 234, 235, 255)
        fontSize(102)
        text("Flood It", 368, -50)
        
        popStyle()
        font("HelveticaNeue-Light")
        fill(235, 234, 235, 255)
        fontSize(72)
        text("Veeral Patel", 368, -248)
        
        popStyle()
        rotate(-90)
        font("HelveticaNeue-Light")
        fontSize(43)
        fill(127, 127, 127, 255)
        text(turnsLeft, 649, HEIGHT - 23)
    end
    
    function touched(touch)
        
        if touch.state == ENDED and turnsLeft > 0 then
            local x,y,c
            x = 150
            for c in ipairs(colors) do
                y = ((c - 1) * 120) + 100
                if lineDist(x, y, touch.x, touch.y) <= 50 then
                    floodFill(grid, 14, 1, grid[14][1], c)
                    turnsLeft = turnsLeft - 1
                end
            end
        end
    end
    
    function lineDist(x1, y1, x2, y2)
        return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2))
    end
    
    function floodFill(grid, row, col, target, new)
        if row < 1 or col < 1 or row > #grid or col > #grid[row] then return end
        
        if grid[row][col] == target then
            grid[row][col] = new
            floodFill(grid, row + 1, col, target, new)
            floodFill(grid, row - 1, col, target, new)
            floodFill(grid, row, col + 1, target, new)
            floodFill(grid, row, col - 1, target, new)
        end
    end
    
    
    
    
    
  • Posts: 266

    anyone know how to implement a shake to restart feature into this game. Would be awesome

  • Posts: 266

    to reset. Triple tap the left side with three fingers

  • Posts: 1,392

    Hi veeeralp,

    Thanks for that - nice package. I'm going to try to get my code so it can be used in whichever orientation you choose.

    Bri_G

    :)

  • Posts: 447

    @veeeralp, I wrote a shake detector for cargo bot, and works ok but in the end I took it out because I tried using while traveling in a car and it kept triggering. With that disclaimer, code is here: https://github.com/ruilov/CargoBot/blob/master/ShakeDetector.lua

  • Posts: 266

    @Bri_G I updated my code.

    function setup()
        displayMode(FULLSCREEN_NO_BUTTONS)
        
        supportedOrientations(LANDSCAPE_ANY)
        
        grid = {}  
        turnsLeft = 25
        
        local r,c
        for r = 1,15 do
            grid[r] = {}
            for c = 1,17 do
                grid[r][c] = math.random(6)
            end
        end
        
        colors = {}
        colors[1] = color(255, 0, 0, 255)
        colors[2] = color(0, 0, 255, 255)
        colors[3] = color(0, 255, 0, 255)
        colors[4] = color(255, 255, 0, 255)
        colors[5] = color(255, 0, 255, 255)
        colors[6] = color(117, 38, 137, 0)
    end
    
    function draw()
        background(135,206,249,255)
    
        pushStyle()
        noSmooth()
        local r,c,col
        for r, row in ipairs(grid) do
            for c, cellVal in ipairs(row) do
                col = colors[cellVal]
                fill(col.r, col.g, col.b)
                rect(((c - 1) * 50) + 164, ((r - 1) * 50) + 9, 50, 50)
            end
        end
        popStyle()
        pushStyle()    
        strokeWidth(3)
        stroke(255, 255, 255, 255)
        for c, col in ipairs(colors) do
            fill(col.r, col.g, col.b)
            ellipse(81, ((c-1) * 120) + 85, 130)
            rect(16, ((c-1) * 120) + 20, 130,130)
            
        end
        
        popStyle()
        font("ArialMT")
        fontSize(43)
        fill(255, 255, 255, 146)
        text(turnsLeft, 505, HEIGHT - 27)
        
        popStyle()
        font("ArialMT")
        fontSize(43)
        fill(255, 255, 255, 146)
        text("turns left", 618, HEIGHT - 27)
        
        popStyle()
        font("ArialMT")
        fontSize(140)
        fill(255, 255, 255, 146)
        text("FLOOD IT", 585, HEIGHT - 388)
        
        popStyle()
        font("ArialMT")
        fontSize(55)
        fill(255, 255, 255, 146)
        text("VEERAL PATEL", 593, HEIGHT - 740)
        
       
    end
    
    function touched(touch)
        
        if touch.state == ENDED and turnsLeft > 0 then
            local x,y,c
            x = 81
            for c in ipairs(colors) do
                y = ((c - 1) * 120) + 85
                if lineDist(x, y, touch.x, touch.y) <= 50 then
                    floodFill(grid, 14, 1, grid[14][1], c)
                    turnsLeft = turnsLeft - 1
                end
            end
        end
    end
    
    function lineDist(x1, y1, x2, y2)
        return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2))
    end
    
    function floodFill(grid, row, col, target, new)
        if row < 1 or col < 1 or row > #grid or col > #grid[row] then return end
        
        if grid[row][col] == target then
            grid[row][col] = new
            floodFill(grid, row + 1, col, target, new)
            floodFill(grid, row - 1, col, target, new)
            floodFill(grid, row, col + 1, target, new)
            floodFill(grid, row, col - 1, target, new)
        end
    end
    
    
    
    
    
    
    
    
  • Posts: 226

    @veeeralp, nice! I think, it's better to let the buttons on the screen to reset the game :-D

  • Posts: 266

    can anyone help with a reset button and some code for it to say "congrats, you win" when the game is over and all of the cells are one color. I worked out one for it to say you lose but can't get the winning label to work. Also, how would you play 1 sound when some wins/loses. I tried but it keeps on playing the sound over and over again. Thanks. Code is attached for help.

    function setup()
        displayMode(FULLSCREEN_NO_BUTTONS)
        
        supportedOrientations(LANDSCAPE_ANY)
        
        grid = {}  
        turnsStart = 25
        turnsUsed = 0
        turnsLeft = turnsStart- turnsUsed
        totCells = 15*17
        maxCells = 0
        
    
        local r,c
        for r = 1,15 do
            grid[r] = {}
            for c = 1,17 do
                grid[r][c] = math.random(6)
            end
        end
        
        colors = {}
        colors[1] = color(255, 0, 0, 255)
        colors[2] = color(0, 0, 255, 255)
        colors[3] = color(0, 255, 0, 255)
        colors[4] = color(255, 255, 0, 255)
        colors[5] = color(255, 0, 255, 255)
        colors[6] = color(117, 38, 137, 0)
        
    end
    function colourStats()
        local r,c, l
        for r = 1, cellNo do
            for c = 1, cellNo do
                cellVal = grid[r][c]
                colNumber[cellVal] = colNumber[cellVal] + 1
            end
        end
        maxCells = colNumber[1]
        for l = 2,6 do
            if maxCells < colNumber[l] then
                maxCells = colNumber[l]
            end
        end
    end
    function draw()
        background(135,206,249,255)
    
        pushStyle()
        noSmooth()
        local r,c,col
        for r, row in ipairs(grid) do
            for c, cellVal in ipairs(row) do
                col = colors[cellVal]
                fill(col.r, col.g, col.b)
                rect(((c - 1) * 50) + 164, ((r - 1) * 50) + 9, 50, 50)
            end
        end
        popStyle()
        pushStyle()    
        strokeWidth(4)
        stroke(255, 255, 255, 255)
        for c, col in ipairs(colors) do
            fill(col.r, col.g, col.b)
            rect(16, ((c-1) * 120) + 20, 130,130)
            
        end
        
        popStyle()
        font("ArialMT")
        fontSize(43)
        fill(255, 255, 255, 146)
        text(turnsLeft, 505, HEIGHT - 27)
        
        popStyle()
        font("ArialMT")
        fontSize(43)
        fill(255, 255, 255, 146)
        text("turns left", 618, HEIGHT - 27)
        
        popStyle()
        font("ArialMT")
        fontSize(140)
        fill(255, 255, 255, 85)
        text("FLOOD IT", 585, HEIGHT - 388)
        
        popStyle()
        font("ArialMT")
        fontSize(55)
        fill(255, 255, 255, 0)
        text("VEERAL PATEL", 593, HEIGHT - 740)
        
        timeLeft = os.difftime(91 - ElapsedTime)
        
        popStyle()
        font("ArialMT")
        fontSize(43)
        fill(255, 255, 255,  146)
        text(timeLeft, 589, HEIGHT - 740)
        
        if timeLeft == 0 then
            messageLose()
        end
        if maxCells == totCells then
            messageWin()
        elseif turnsLeft == 0 then
            messageLose()
        end
    end
    
    function lineDist(x1, y1, x2, y2)
        return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2))
    end
    
    function floodFill(grid, row, col, target, new)
        if row < 1 or col < 1 or row > #grid or col > #grid[row] then return end
        
        if grid[row][col] == target then
            grid[row][col] = new
            floodFill(grid, row + 1, col, target, new)
            floodFill(grid, row - 1, col, target, new)
            floodFill(grid, row, col + 1, target, new)
            floodFill(grid, row, col - 1, target, new)
        end
    end
    
    function touched(touch)
        
        if touch.state == ENDED and turnsLeft > 0 then
            local x,y,c
            x = 81
            for c in ipairs(colors) do
                y = ((c - 1) * 120) + 85
                if lineDist(x, y, touch.x, touch.y) <= 50 then
                    floodFill(grid, 15, 1, grid[15][1], c)
                    turnsLeft = turnsLeft - 1
                end
            end
        end
    end
    
    
    
    function messageWin()
        pushStyle()
            font("ArialMT")
            fontSize(54)
            fill(30, 125, 36, 255)
            text("CONGRATULATIONS, YOU WIN!", 585, HEIGHT - 263)
        popStyle() 
    end
    
    function messageLose()
        pushStyle()
            font("ArialMT")
            fontSize(54)
            fill(183, 31, 31, 255)        
            text("SORRY, YOU LOSE!", 585, HEIGHT - 263)
        popStyle()
    end
    
    
    
    
  • edited July 2012 Posts: 1,392

    Hi @veeeralp,

    Just a couple of things -

    First - when I cut and paste your code I always get errors for style().
    This looks like you have an imbalance in your push and pop setup as, when I correct it it works fine for me. Are you trying to nest push and pops?

    Should be in order pushStyle() then popStyle(), ignore this comment if it's obvious.

    Second - I notice you've increased you grid size from 14x14 to 17x15. This is a change of 196 cells to 256. That's quite a big change and I've found the target of 25 too small. Think you may have to increase ti pro-rata to say 33 (rounding up). You may have to play with this to get a good balance.

    Finally, I've posted your code on my github site, to help people download. The problem with loads of code in posts means it ends up in lottsa pages for a thread - which we have to negotiate - fustrates me. Ought to post in reverse order i.e. latest date first, like the main forum discussion list. Collapsible code would help as well.

    You may be able to update the listing yourself, as it's in a public gist (never tried this myself), or make a fork off it. If not - if you post changes to the code I'll do it myself.

    link is : https://gist.github.com/3075538

    Noted you've put a timer on yours - toying with the idea for mine.

    Thanks again,

    Bri_G

    :)

  • Posts: 266

    @Bri_G I'm new to coding so I have no idea what pushStyle() and popStyle() is. I just used it as a guideline from the code in the examples. I don't know what nesting push and pops is. Did you fix this in the code you put on github? Also, I'm having trouble making it say that you win. I tried to use conditionals (like you), but it doesn't work for me. Also is there a way to make sure the timeLeft doesn't go under 0 and pauses when the the person loses. I made a zer0 appear over the actual timeLeft but how would I make the timeLeft disappear once it goes below zero. Thanks and I'll try to update my code through gist.github. If not, I'll post here. How's your code lookin?

  • Posts: 266

    @Bri_G I fixed the pushstyle() and popStyle() thing you were talking about by looking at the gist.github post for my version 3. In the above post I was talking about v4 so here it is.
    https://gist.github.com/3077133
    I need help on this one.

  • Posts: 266

    Also, I put it to countdown from 10 so you know what I'm talking about

  • edited July 2012 Posts: 1,392

    Hi All,

    Just a note to post a video of the Flood-pad app I have written, based on @Eric's original code. The app is still in development - currently working on HiScore table. Then needs debugging, but is almost there. Will take a few weeks due to arrival of Hols (kinda reverse logic - but I have less time during hols than during rest of year!!!).

    This post just to show @veeeralp my progress and what you can do with Codea in this app.

    The vid:

    Enjoy, code will be released when I have the total package - before optimisation and clean-up (or it will take months!!!).

    Bri_G

    ;-)

  • Posts: 266

    I love your app. I stopped working on it and focused on another game. After I'm done with that, I'll work on this.

    PS. How did you create thos fancy fonts?

  • Posts: 1,392

    Hi @veeeralp,

    Thanks on the app front. Code to follow when I finish the his core table. On the fancy fonts front, I'm assuming you mean the app title, I made those with Xara Photo and Graphic Studio - it's got a built in 3D font functionality which you can then convert to vector objects and export as png or jpg.

    I'm working on other apps which will be posted later.

    Bri_G

    :)

  • Posts: 266

    @Bri_G ok cool. ill probably just use adobe illustrator and photoshop once I get back to school. Also, does your project have any sound. I wish the recorder recorded sound. how are you going to implement high scores. I was looking at @Vega's post and was wondering how you would let the user type in their own name?

  • Posts: 1,392

    Hi @veeerlap,

    You've it on two of the things I haven't done yet. @Vega's post is my starting point. Hope to sort this out over the next 3 weeks.

    On the sound front we need to be able to play sample files. Is there any help from the Carg-Bot example code?

    Bri_G

    :)

  • Posts: 384

    @Bri_G, Cargo Bot does not use audio samples, but you can see the sound effects we chose and how the music works. To hear it you will need to set the nosound flag to false in main.

  • edited July 2012 Posts: 563

    @Bri_G and @veeeralp - if you want some sample high score code have a look at this tutorial: http://codeatuts.blogspot.com.au/2012/07/tutorial-7-minesweeper-part-2.html

    It uses the textBox class from Spritely to enter the players name for the high score and then saves it to local data with the score.

  • Posts: 266

    @Reefwing ok thanks. I'll look into that. The only problem with that is that you won't be able to see other peoples' scores. Only yours

  • Posts: 563

    @veeeralp - true, you need something like @Vega's solution to have a global high score but at least you can see how to use the textBox class to enter a player's name.

  • Posts: 266

    @Reefwing ok thanks will do. Are you gonna make a tutorial about submitting your minesweeper app to the appstore

  • Posts: 563

    @veeeralp - yes indeed.

    I just got side tracked with the new dependency functionality. I'm going to tidy up MineSweeper using my new RSLibrary and then I will have a shot at this.

  • Posts: 57

    @veeeralp, a while ago I started working on a "Pop up dialog" with text input field. I found the code and have just published it here (as it is) http://sprng.me/f7phd. It is a mess, non-polished code, I know, but the basic functionality is buried there somewhere. If it can save you some typing it will be worth. BTW, question for all and specially for @Simeon: Is it worth writing our own windowing system for Codea or are we going to have pop-ups, buttons, input fields, menus, etc natively in Codea any time soon?

  • Posts: 2,161

    I have a fairly extensive UI system available from http://www.math.ntnu.no/~stacey/HowDidIDoThat/iPad/Codea.html with menus, various buttons, text boxes, and so forth.

  • Posts: 57

    Thanks for sharing @Andrew_Stacey, I'll give them a go.

  • Posts: 266

    how did you end up making it work in both orientations. Right now, when I change orientations while the game is running my buttons get messed up. But when I press the reset button in the new orientation it gets fixed. I'm worried on how it will actually look once in xcode

  • Posts: 563

    . @veeeralp - you need to define the orientationChanged(newOrientation) function and adjust your button (x, y) co-ordinates in there so that the next time they are drawn they are in the right spot for that orientation.

  • Posts: 563

    On a related topic, at the moment,

    CurrentOrientation == PORTRAIT_ANY
    

    Doesn't seem to work so you have to test for the two different portrait orientations. Is this a bug or an undocumented feature?

  • Posts: 2,161

    That's because currentOrientation and the various flavours of PORTRAIT are just numbers. So that test is testing two numbers and finding them not equal. The CurrentOrientation will always be one of the actual orientations and so will fail against the generic ones.

    The numbers are:

    PORTRAIT = 0
    PORTRAIT_UPSIDE_DOWN = 1
    LANDSCAPE_LEFT = 2
    LANDSCAPE_RIGHT = 3
    PORTRAIT_ANY = 4
    LANDSCAPE_ANY = 5
    

    So to test for CurrentOrientation == PORTRAIT_ANY you'd need to test CurrentOrientation < LANDSCAPE_LEFT! (Or better to write an auxiliary function:

    function testOrientation(o)
        if CurrentOrientation == o then
            return true
        fi
        if o == PORTRAIT_ANY and CurrentOrientation <= 2 then
            return true
        fi
        if o == LANDSCAPE_ANY and CurrentOrientation > 2 then
            return true
        fi
        return false
    end
    

    Note: the tests on o are written with the _ANYs to provide robustness against these numbers changing. However the tests on CurrentOrientation are not as a reminder that if the numbers change, these tests will need changing. I put them as inequalities to make them a single test - though it strikes me that two equality tests might be faster than a single inequality test.

  • Posts: 563

    Hmm - thanks @Andrew_Stacey, that makes sense. The problem with using CurrentOrientation < LANDSCAPE_LEFT is that it isn't obvious what you are trying to do, so it makes your code harder to read by someone else.

    Given that you can't compare CurrentOrientation with PORTRAIT_ANY what is the point of this constant?

    I wonder whether some sort of binary masking arrangement would be more versatile. Not a big deal in the scheme of things.

  • Posts: 2,161

    The problem with using CurrentOrientation < LANDSCAPE_LEFT is that it isn't obvious what you are trying to do, so it makes your code harder to read by someone else.

    Exactly. That's why in the testOrientation function I wrote it explicitly as testing against 2. But as I said, a single inequality might not be any more efficient than testing o == PORTRAIT or o == PORTRAIT_UPSIDE_DOWN.

    Given that you can't compare CurrentOrientation with PORTRAIT_ANY what is the point of this constant?

    Because it's a valid input to the supportedOrientations function which tells Codea which orientation changes to "notice".

  • .@Bri_G how's your app coming along? I just finished my first app and it's waiting for review right now. I was looking at the original code by @Eric and your codea and was wondering how to overcome the stackover flow error when you press a color twice in a row. If anyone else knows, it would be a huge help for my project. Thanks.

  • Posts: 1,392

    Hi @veeeralp,

    Only just picked up Flood-it again, been distracted by hols and house decorating. Also have a number of other things I'm pursuing with HTML/PHP and haven't done much with the app.

    Having said that - I've almost completed the hi-scores table and am looking at the possibility of posting results up onto a web-site so you can see globally who's top of the pile.

    On the stackover flow error - I'd left that to the end as a known bug to strip out. I was planning on re-visiting the core of the colour changes as part of that to avoid bugs like that.

    With the other things in the pipeline - I think it will take me a couple of weeks to finish and tidy up. I'll keep you posted.

    Thanks,

    Bri_G

    :)

  • edited September 2012 Posts: 266

    .@Bri_G awesome can't wait to see yours. I've also been working on mine, here's a YouTube link

    The awesome backgrounds were made in photoshop and the patterns are courtesy of subtlepatterns.com. Buttons were made in Ps too. I'm about 50 percent done. Now I just need to make a "lite" version and add a special feature.

    edit: just noticed you can't really see the detail in the video. Here are some links to screenshots. also, the physics boxes that fall react to how you tilt the ipad :)

    http://d.pr/i/a6SI

    http://d.pr/i/y7j1

    http://d.pr/i/gq5Y

    http://d.pr/i/Z415

    http://d.pr/i/HDT2

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Wow, that looks really polished, @veeeralp.

    I'd suggest drawing the physics boxes that drop down as solid-filled and softly coloured, rather than red outlines.

  • .@Simeon thanks for the compliment. I've been trying to color the boxes with a fill that matches the flood grid. I've been using the PhysicsDebugDraw provided in the physics test and i don't know how to change the fill of the box. I've managed to make the stroke a random color every time the program is launched.

  • Posts: 3

    Does anyone have the code in C language for flood it?

Sign In or Register to comment.