示例#1
0
        private ShieldRoot GenerateShield(PCSTree pRootTree, float startX, float startY, int idx)
        {
            ShieldRoot pShieldRoot = new ShieldRoot(GameObjectName.ShieldRoot, SpriteBaseName.Null, 0.0f, 0.0f, idx);

            pRootTree.Insert(pShieldRoot, null);
            GameObjectManager.AttachTree(pShieldRoot);
            ShieldFactory shieldFactory = new ShieldFactory(SpriteBatchName.Shields, SpriteBatchName.Boxes, pRootTree);

            shieldFactory.SetParent(pShieldRoot);
            ShieldCategory pShieldGrid = shieldFactory.Create(ShieldType.Grid, GameObjectName.ShieldGrid);

            int            j = 0;
            ShieldCategory pCol;

            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.ShieldColumn, j++);
            shieldFactory.SetParent(pCol);

            int i = 0;

            float start_x     = startX;
            float start_y     = startY;
            float off_x       = 0;
            float brickWidth  = 15.0f;
            float brickHeight = 10.0f;

            for (int x = 0; x < 8; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.Create(ShieldType.LeftTop1, GameObjectName.ShieldBrick, start_x, start_y + 8 * brickHeight, i++);
            shieldFactory.Create(ShieldType.LeftTop0, GameObjectName.ShieldBrick, start_x, start_y + 9 * brickHeight, i++);
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 0; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            shieldFactory.Create(ShieldType.LeftBottom, GameObjectName.ShieldBrick, start_x + off_x, start_y + 2 * brickHeight);
            for (int x = 3; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 3; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            shieldFactory.Create(ShieldType.RightBottom, GameObjectName.ShieldBrick, start_x + off_x, start_y + 2 * brickHeight, i++);
            for (int x = 3; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 0; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 0; x < 8; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.Create(ShieldType.RightTop1, GameObjectName.ShieldBrick, start_x + off_x, start_y + 8 * brickHeight);
            shieldFactory.Create(ShieldType.RightTop0, GameObjectName.ShieldBrick, start_x + off_x, start_y + 9 * brickHeight);

            return(pShieldRoot);
        }
示例#2
0
        public void BuildShield(ShieldCategory pShieldRoot, float startPos_x, float startPos_y, float brickSpriteWidth, float brickSpriteHeight)
        {
            // set the parent for hierarchy inside the factory, grid is root, so parent is null
            this.setParent(pShieldRoot);

            // create and attach grid to Root
            ShieldCategory pShieldGrid = this.Create(ShieldCategory.Type.ShieldGrid, GameObject.Name.ShieldGrid);

            // load the shield by column, bottom to top, left to right;
            int j = 0;

            ShieldCategory pColumn;

            this.setParent(pShieldGrid);

            //Each Shield has 7 Columns and 5 Rows
            //-----------------------------------------------------------------------------------

            pColumn = this.Create(ShieldCategory.Type.ShieldColumn, GameObject.Name.ShieldColumn, j++);
            this.setParent(pColumn);

            int i = 0;

            //float start_x = 75.0f;
            //float start_y = 100.0f;
            float gap = 0;

            //-----------------------------------------------------------------------------------
            //Column 1: row 1 = topLeft, row 2-5 = normal bricks

            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x, startPos_y);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x, startPos_y + brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x, startPos_y + 2 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x, startPos_y + 3 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrickLeft_Top, GameObject.Name.ShieldBrick, i++, startPos_x, startPos_y + 4 * brickSpriteHeight);


            this.setParent(pShieldGrid);

            //-----------------------------------------------------------------------------------
            //Column 2: row 1-5 = normal bricks

            pColumn = this.Create(ShieldCategory.Type.ShieldColumn, GameObject.Name.ShieldColumn, j++);
            this.setParent(pColumn);

            gap += brickSpriteWidth;
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 2 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 3 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 4 * brickSpriteHeight);


            this.setParent(pShieldGrid);

            //-----------------------------------------------------------------------------------
            //Column 3: 1-3 normal, 4 = bottomleft, 5 = no brick!

            pColumn = this.Create(ShieldCategory.Type.ShieldColumn, GameObject.Name.ShieldColumn, j++);
            this.setParent(pColumn);

            gap += brickSpriteWidth;
            this.Create(ShieldCategory.Type.ShieldBrickMidLeft_Bottom, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 1 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 2 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 3 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 4 * brickSpriteHeight);


            this.setParent(pShieldGrid);


            //-----------------------------------------------------------------------------------
            //Column 4: 1-3 normal, 4 = bottom mid, 5 = no brick!


            pColumn = this.Create(ShieldCategory.Type.ShieldColumn, GameObject.Name.ShieldColumn, j++);
            this.setParent(pColumn);

            gap += brickSpriteWidth;
            this.Create(ShieldCategory.Type.ShieldBrickMid_Bottom, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 1 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 2 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 3 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 4 * brickSpriteHeight);

            this.setParent(pShieldGrid);


            //-----------------------------------------------------------------------------------
            //Column 5: 1-3 normal, 4 = bottom right, 5 = no brick!


            pColumn = this.Create(ShieldCategory.Type.ShieldColumn, GameObject.Name.ShieldColumn, j++);
            this.setParent(pColumn);

            gap += brickSpriteWidth;
            this.Create(ShieldCategory.Type.ShieldBrickMidRight_Bottom, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 1 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 2 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 3 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 4 * brickSpriteHeight);

            this.setParent(pShieldGrid);


            //-----------------------------------------------------------------------------------
            //Column 6: 1-5 normal

            pColumn = this.Create(ShieldCategory.Type.ShieldColumn, GameObject.Name.ShieldColumn, j++);
            this.setParent(pColumn);

            gap += brickSpriteWidth;
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 2 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 3 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 4 * brickSpriteHeight);

            this.setParent(pShieldGrid);


            //-----------------------------------------------------------------------------------
            //Column 7: 1 top right, 2-5 normal


            pColumn = this.Create(ShieldCategory.Type.ShieldColumn, GameObject.Name.ShieldColumn, j++);
            this.setParent(pColumn);

            gap += brickSpriteWidth;

            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 2 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrick, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 3 * brickSpriteHeight);
            this.Create(ShieldCategory.Type.ShieldBrickRight_Top, GameObject.Name.ShieldBrick, i++, startPos_x + gap, startPos_y + 4 * brickSpriteHeight);
        }
示例#3
0
        public ShieldCategory Create(ShieldCategory.Type type, GameObject.Name gameObjName, int index = 0, float posX = 0.0f, float posY = 0.0f)
        {
            ShieldCategory pShield = null;

            switch (type)
            {
            case ShieldCategory.Type.Root:
                pShield = new ShieldRoot(gameObjName, GameSprite.Name.NullObject, index, posX, posY);
                //pShield.SetCollisionColor(0.0f, 0.0f, 1.0f);
                //GameObjectManager.AttachTree(pShield, this.pTree);
                //pShield.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;

            case ShieldCategory.Type.ShieldGrid:
                pShield = new ShieldGrid(gameObjName, GameSprite.Name.NullObject, index, posX, posY);
                //pShield.SetCollisionColor(1.0f, 0.0f, 0.0f);
                pShield.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;

            case ShieldCategory.Type.ShieldColumn:
                pShield = new ShieldColumn(gameObjName, GameSprite.Name.NullObject, index, posX, posY);
                //pShield.SetCollisionColor(1.0f, 0.0f, 0.0f);
                pShield.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;


            case ShieldCategory.Type.ShieldBrick:
                pShield = new ShieldBrick(gameObjName, GameSprite.Name.ShieldBrick, index, posX, posY);
                break;

            case ShieldCategory.Type.ShieldBrickLeft_Top:
                pShield = new ShieldBrick(gameObjName, GameSprite.Name.ShieldBrickLeft_Top, index, posX, posY);
                break;


            case ShieldCategory.Type.ShieldBrickRight_Top:
                pShield = new ShieldBrick(gameObjName, GameSprite.Name.ShieldBrickRight_Top, index, posX, posY);
                break;


            case ShieldCategory.Type.ShieldBrickMidLeft_Bottom:
                pShield = new ShieldBrick(gameObjName, GameSprite.Name.ShieldBrickMidLeft_Bottom, index, posX, posY);
                break;

            case ShieldCategory.Type.ShieldBrickMid_Bottom:
                pShield = new ShieldBrick(gameObjName, GameSprite.Name.ShieldBrickMid_Bottom, index, posX, posY);
                break;

            case ShieldCategory.Type.ShieldBrickMidRight_Bottom:
                pShield = new ShieldBrick(gameObjName, GameSprite.Name.ShieldBrickMidRight_Bottom, index, posX, posY);
                break;

            default:
                // something is wrong
                Debug.Assert(false);
                break;
            }

            // add to the tree
            this.pTree.Insert(pShield, this.pParent);

            // Attached to Group
            pShield.ActivateGameSprite(this.pSpriteBatch);
            pShield.ActivateCollisionSprite(this.pCollisionSpriteBatch);

            return(pShield);
        }
示例#4
0
        public ShieldCategory Create(ShieldType type, GameObjectName goName, float x = 0.0f, float y = 0.0f, int idx = 0)
        {
            ShieldCategory pShield = null;

            switch (type)
            {
            case ShieldType.Brick:
                pShield = new ShieldBrick(goName, SpriteBaseName.Brick, x, y, idx);
                break;

            case ShieldType.LeftTop0:
                pShield = new ShieldBrick(goName, SpriteBaseName.BrickLeftTop0, x, y, idx);
                break;

            case ShieldType.LeftTop1:
                pShield = new ShieldBrick(goName, SpriteBaseName.BrickLeftTop1, x, y, idx);
                break;

            case ShieldType.LeftBottom:
                pShield = new ShieldBrick(goName, SpriteBaseName.BrickLeftBottom, x, y, idx);
                break;

            case ShieldType.RightTop0:
                pShield = new ShieldBrick(goName, SpriteBaseName.BrickRightTop0, x, y, idx);
                break;

            case ShieldType.RightTop1:
                pShield = new ShieldBrick(goName, SpriteBaseName.BrickRightTop1, x, y, idx);
                break;

            case ShieldType.RightBottom:
                pShield = new ShieldBrick(goName, SpriteBaseName.BrickRightBottom, x, y, idx);
                break;

            case ShieldType.Root:
                pShield = new ShieldRoot(goName, SpriteBaseName.Null, x, y, idx);
                pShield.pCollisionObject.pCollisionSpriteBox.pLineColor = ColorFactory.Create(ColorName.Blue).pAzulColor;
                Debug.Assert(false);
                break;

            case ShieldType.Grid:
                pShield = new ShieldGrid(goName, SpriteBaseName.Null, x, y, idx);
                pShield.pCollisionObject.pCollisionSpriteBox.pLineColor = ColorFactory.Create(ColorName.Blue).pAzulColor;
                break;

            case ShieldType.Column:
                pShield = new ShieldColumn(goName, SpriteBaseName.Null, x, y, idx);
                pShield.pCollisionObject.pCollisionSpriteBox.pLineColor = ColorFactory.Create(ColorName.Red).pAzulColor;
                break;

            default:
                Debug.Assert(false);
                break;
            }
            this.pTree.Insert(pShield, this.pParent);
            pShield.ActivateGameSprite(this.pSpriteBatch);
            if (GameManager.GetCollisionBoxes())
            {
                pShield.ActivateCollisionSprite(this.pCollisionSpriteBatch);
            }
            return(pShield);
        }