Click here to Skip to main content
15,887,304 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I extended the tetrominoes array to include 5 more shapes. They are being drawn properly, but the DrawNext function is having issues accommodating them. What is the best way to code the function so it will use the extended array?

as
private function DrawNext():void {
            if (getChildByName("next")!=null) {
                removeChild(getChildByName("next"));
            }
            var next_t:Sprite=new Sprite();
            next_t.x=352;
            next_t.name="next";
            addChild(next_t);
            next_t.graphics.lineStyle(0,0xFFFFFF);
            for (var i:uint=0; i<tetrominoes[nextTetromino][0].length; i++) {
                for (var j:uint=0; j<tetrominoes[nextTetromino][0][i].length; j++) {
                    if (tetrominoes[nextTetromino][0][i][j]==1) {
                        next_t.graphics.beginFill(colors[nextTetromino]);
                        next_t.graphics.drawRect(tileSize*j,tileSize*i,tileSize,tileSize);
                        next_t.graphics.endFill();
                    }
                }
            }
        }

private function BuildTetrominoes():void {
    // I
    tetrominoes[0]=[[[0,0,0,0],[1,1,1,1],[0,0,0,0],[0,0,0,0]],
        [[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0]]];
    colors[0]=0x00FFFF; //Cyan
    // T
    tetrominoes[1]=[[[0,0,0,0],[1,1,1,0],[0,1,0,0],[0,0,0,0]],
         [[0,1,0,0],[1,1,0,0],[0,1,0,0],[0,0,0,0]],
         [[0,1,0,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],
         [[0,1,0,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]]];
    colors[1]=0xAA00FF; //Purple
    // L
    tetrominoes[2]=[[[0,0,0,0],[1,1,1,0],[1,0,0,0],[0,0,0,0]],
         [[1,1,0,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]],
         [[0,0,1,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],
         [[0,1,0,0],[0,1,0,0],[0,1,1,0],[0,0,0,0]]];
    colors[2]=0xFFA500; //Orange
    // J
    tetrominoes[3]=[[[1,0,0,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],
         [[0,1,1,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]],
         [[0,0,0,0],[1,1,1,0],[0,0,1,0],[0,0,0,0]],
         [[0,1,0,0],[0,1,0,0],[1,1,0,0],[0,0,0,0]]];
    colors[3]=0x0000FF; //Blue
    // Z
    tetrominoes[4]=[[[0,0,0,0],[1,1,0,0],[0,1,1,0],[0,0,0,0]],
         [[0,0,1,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]]];
    colors[4]=0xFF0000; //Red
    // S
    tetrominoes[5]=[[[0,0,0,0],[0,1,1,0],[1,1,0,0],[0,0,0,0]],
         [[0,1,0,0],[0,1,1,0],[0,0,1,0],[0,0,0,0]]];
    colors[5]=0x00FF00; //Green
    // O
    tetrominoes[6]=[[[0,1,1,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]]];
    colors[6]=0xFFFF00; //Yellow
    //X
    tetrominoes[7] = [[[0,1,0,0],[1,1,1,0],[0,1,0,0],[0,0,0,0]]];
    colors[7] = 0x00FF80;
    //U
    tetrominoes[8] = [[[1,1,1,0],[1,0,1,0],[0,0,0,0],[0,0,0,0]],
        [[1,1,0,0],[1,0,0,0],[1,1,0,0],[0,0,0,0]],
        [[1,0,1,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],
        [[0,0,1,1],[0,0,0,1],[0,0,1,1],[0,0,0,0]]];
    colors[8] = 0xFF007F;
    //V
    tetrominoes[9] = [[[1,1,0,0],[1,0,0,0],[0,0,0,0],[0,0,0,0]],
        [[0,0,1,1],[0,0,0,1],[0,0,0,0],[0,0,0,0]],
        [[0,0,0,0],[0,0,0,0],[0,0,0,1],[0,0,1,1]],
        [[0,0,0,0],[0,0,0,0],[1,0,0,0],[1,1,0,0]]];
    colors[9] = 0xFF00FF;
    //Colon
    tetrominoes[10] = [[[1,1,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
        [[1,0,0,0],[1,0,0,0],[0,0,0,0],[0,0,0,0]]];
    colors[10] = 0x0080FF;
    //Dot
    tetrominoes[11] = [[[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]];
    colors[11] = 0xFF4000;
}
Posted
Comments
Sergey Alexandrovich Kryukov 10-Feb-13 21:21pm    
Are you sure it really yours, not copied from somewhere? Usually, it it yours, you know how to change the size from the very beginning...
Why won't you use the debugger and find everything out? We don't have all the working code...
—SA
Blind.Geek81 10-Feb-13 21:36pm    
I did start with source code from the book Flash Game Development by Example.
Sergey Alexandrovich Kryukov 10-Feb-13 22:44pm    
Maybe original code is not designed well. I doubt the problem is in the code you show; you really need to use the debugger.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900