Question

I was reading a tutorial about creating multiple levels, and the below really interested me on how i should go about this.

It may seem natural to make one class per level, with each class extending AvoiderGame, and use events to switch between them. So, we might have classes named AvoiderGameLevelOne, AvoiderGameLevelTwo, etc., and let each one fire off a “NavigationEvent.NEXT_LEVEL” when appropriate. Presumably then the document class would listen for this event, and when it heard it, it would run “playScreen = new AvoiderGameLevelTwo()” (or whichever level was appropriate), and pass through all the information such as score and time to this new playScreen instance.

I'm not entirely sure on how to go about this. I put my stage, which is an array of tiles in a class called level1, level2, etc and had it extend my main class. Just to check if everything works, I added a public static var called levelArray in my main, which is a blank array. Then in level1, I pushed my array into levelArray.

So for my level1 class

package  {

    public class Level1 extends Main {

        public var floor1:Array = new Array();
        floor1[0] = [2,1,1,1,1,1,2];
        floor1[1] = [1,1,1,1,1,1,1];
        floor1[2] = [1,1,1,2,1,1,1];
        floor1[3] = [1,1,1,1,1,1,1];
        floor1[4] = [1,1,1,2,1,1,1];
        floor1[5] = [1,1,1,1,1,1,1];
        floor1[6] = [2,1,1,1,1,1,2];

        public function Level1() {

            Main.levelArray.push(floor1);
        }


    }

}

Doesn't seem to be working. levelArray comes up as blank. Might be because the two classes aren't communicating with each other correctly? Any ideas if I am approaching this the correct way?

Was it helpful?

Solution

I dont know if the rest of your concept is sound, but I think the syntax is off for the part you have shown. try:

package  {

    public class Level1 extends Main {

        public var floor1:Array = new Array( [2,1,1,1,1,1,2],
                                             [1,1,1,1,1,1,1],
                                             [1,1,1,2,1,1,1],
                                             [1,1,1,1,1,1,1],
                                             [1,1,1,2,1,1,1],
                                             [1,1,1,1,1,1,1],
                                             [2,1,1,1,1,1,2]
                                           );

        public function Level1() {
            Main.levelArray = floor1;
        }
    }

}

EDIT: if the only thing distinct about each level is the array that forms the floor, you may consider the fact that you do not need a new class for each level, just a new array. you can define the arrays for each level in the class that is super to this one and then just replace them with each progression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top