Flood It

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?

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.

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.

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.

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

:slight_smile:

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

http://www.youtube.com/watch?v=nOUu9ftobxM

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 :slight_smile:

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

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.

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