mercredi 3 juin 2015

Downloadable level pack usage pattern

I'm planning to release a level-based game. I'm going to use parse.com to offer users downloadable level packs.

Can you advice me a particular code pattern of how to build level menu based on which level packs are bought and which are not.

Right now I have something like Angry Birds. So different worlds (level packs) and each has 12 levels.

I generate scrollview like so

    contentNode.contentSizeType = CCSizeType(widthUnit: .Normalized, heightUnit: .Normalized);
    contentNode.contentSize = CGSizeMake(5.0, 0.375);



    let prefixes = ["tutorial", "levels", "levels", "levels", "levels"]

    for x in 1...5
    {
        //this is a picture, when you tap on this, level grid is appearing
        let b = CCButton(title: "", spriteFrame: CCSpriteFrame(imageNamed: "b\(x).png"))
        b.positionType = CCPositionType( xUnit: .Normalized, yUnit: .Normalized, corner: .BottomLeft )
        b.position = ccp((CGFloat(x-1) + 0.5)/5, 0.8);

        // this indicates if level pack is bought (or reached, if it is a default one) or not. what is the best way to store this information? NSUserDefaults?
        b.background.effect = CCEffectSaturation(saturation: x > 2 ? -1.0 : 0.0)
        b.enabled = x < 3

        b.block = {
            (id sender) in
            //remove scroll view, show level grid using prefixes[x-1], add "back" button, etc

        }
        contentNode.addChild(b)
    }

It seems so ugly to me. Mostly because if i want to add some more level packs, I'll need to update my app just for updating prefixes.

And also I want to be able to check for ownership of the in-app in offline.

I guess I should download my levels into one specific folder and each time app launches I should iterate through all files and build a level-prefixes array, than build a scroll view according to what I had found, then, If connection is available, I should check for locked level packs which are to be bought, and add them to scroll view as well.

I just need an approach. Detailed pseudo-code will be ok.

Aucun commentaire:

Enregistrer un commentaire