コード例 #1
0
ファイル: BlockTest.cs プロジェクト: DJSymBiotiX/BlockXNA
        public override void Initialize()
        {
            playerInput = new PlayerInput(PlayerIndex.One);
            this.Game.Components.Add(playerInput);

            playerInput.BindAction("Quit", Keys.Escape);
            playerInput.BindAction("Up", Keys.Up);
            playerInput.BindAction("Down", Keys.Down);
            playerInput.BindAction("Left", Keys.Left);
            playerInput.BindAction("Right", Keys.Right);
            playerInput.BindAction("Swap", Keys.Space);
            playerInput.BindAction("Explode", Keys.Z);
            playerInput.BindAction("ExplodeAll", Keys.X);

            playerInput.BindAction("Reset", Keys.Enter);

            playerInput.BindAction("Up", Buttons.DPadUp);
            playerInput.BindAction("Down", Buttons.DPadDown);
            playerInput.BindAction("Left", Buttons.DPadLeft);
            playerInput.BindAction("Right", Buttons.DPadRight);

            blockGrid = new BlockGrid(48, 48, 12, 10);

            blockGrid.X = 48;
            blockGrid.Y = 64;

            BlockGroup bg = new BlockGroup(3, 3, blockGrid);
            bg.Add(new Block(BlockType.White), 0, 1);
            bg.Add(new Block(BlockType.White), 1, 1);
            bg.Add(new Block(BlockType.White), 2, 1);
            bg.Add(new Block(BlockType.White), 2, 2);

            //blockGrid.Drop(bg, 2);
            blockGrid.Drop(bg, 4);

            InputLimiter = new Limiter[2]{new Limiter(InputLimiterInterval),new Limiter(InputLimiterInterval)};
            dropLimiter = new Limiter(0.15);

            burstEffect = new ParticleEffect_B();
            this.Game.Components.Add(burstEffect);

            explodeEffect = new ParticleEffect_C();
            this.Game.Components.Add(explodeEffect);

            blockGrid.BurstEffect = burstEffect;
            blockGrid.ExplodeEffect = explodeEffect;

            this.Game.Components.Add(blockGrid);

            base.Initialize();

            this.Enabled = true;
        }
コード例 #2
0
ファイル: BlockGrid.cs プロジェクト: fchorney/BlockXNA
        private void CompressColumn(int col)
        {
            BlockGroup freeGroup       = null;
            bool       foundEmptySpace = false;

            for (int i = NumRows - 1; i >= 0; i--)
            {
                //empty block means potential for free group to fall
                if (BlockIsEmpty(i, col))
                {
                    if (freeGroup != null)
                    {
                        _FreeBlocks.Add(freeGroup);
                    }

                    foundEmptySpace = true;
                    freeGroup       = null;
                }
                else if (foundEmptySpace && _Blocks[i, col].State == BlockState.Normal)
                {
                    if (freeGroup == null)
                    {
                        //create a new free group to add blocks above the last empty space until the next empty space
                        //currently creates a group spanning the entire column - we can optimize this a little at the expense of readability
                        freeGroup     = new BlockGroup(NumRows, 1, this);
                        freeGroup.Col = col;
                    }
                    freeGroup.Add(_Blocks[i, col], i, 0);
                    _Blocks[i, col] = null;
                }
            }

            if (freeGroup != null)
            {
                _FreeBlocks.Add(freeGroup);
            }
        }
コード例 #3
0
ファイル: BlockGrid.cs プロジェクト: DJSymBiotiX/BlockXNA
 private bool TryChainExplode(Block b, int r, int c, BlockGroup chainGroup)
 {
     if (InBounds(r, c, this) && !BlockIsEmpty(r, c))
     {
         Block target = _Blocks[r, c];
         if (target.State == BlockState.Normal && target.Type == b.Type && !target.IsEmpty)
         {
             target.State = BlockState.Exploding;
             chainGroup.Add(target, r, c);
             return true;
         }
     }
     return false;
 }
コード例 #4
0
ファイル: BlockGrid.cs プロジェクト: DJSymBiotiX/BlockXNA
 private void CopyGroup(BlockGroup bg)
 {
     for (int r = 0; r < bg.NumRows; r++)
         for (int c = 0; c < bg.NumCols; c++)
             if (InBounds(bg.Row + r, bg.Col + c, this) && bg.Blocks[r, c] != null)
             {
                 if (_Blocks[bg.Row + r, bg.Col +c] == null || _Blocks[bg.Row + r, bg.Col +c].State != BlockState.Exploding)
                     _Blocks[bg.Row + r, bg.Col + c] = bg.Blocks[r, c];
             }
 }
コード例 #5
0
ファイル: BlockGrid.cs プロジェクト: DJSymBiotiX/BlockXNA
        private void CompressColumn(int col)
        {
            BlockGroup freeGroup = null;
            bool foundEmptySpace = false;

            for (int i = NumRows - 1; i >= 0; i--)
            {
                //empty block means potential for free group to fall
                if (BlockIsEmpty(i,col))
                {
                    if (freeGroup != null)
                        _FreeBlocks.Add(freeGroup);

                    foundEmptySpace = true;
                    freeGroup = null;
                }
                else if (foundEmptySpace && _Blocks[i, col].State == BlockState.Normal)
                {
                    if (freeGroup == null)
                    {
                        //create a new free group to add blocks above the last empty space until the next empty space
                        //currently creates a group spanning the entire column - we can optimize this a little at the expense of readability
                        freeGroup = new BlockGroup(NumRows, 1, this);
                        freeGroup.Col = col;
                    }
                    freeGroup.Add(_Blocks[i, col], i, 0);
                    _Blocks[i, col] = null;
                }
            }

            if (freeGroup != null)
                _FreeBlocks.Add(freeGroup);
        }
コード例 #6
0
ファイル: BlockGrid.cs プロジェクト: DJSymBiotiX/BlockXNA
        private bool CheckCollision(BlockGroup bg)
        {
            bool Collision = false;

            //check collisions against bottom of grid
            if (bg.Row + bg.NumRows >= this.NumRows)
            {
                for (int i = 0; i < bg.NumCols; i++)
                {
                    if (bg.Blocks[bg.NumRows - (bg.Row + bg.NumRows - this.NumRows) - 1, i] != null)
                        return true;
                }
            }

            //check collisions against other blocks
            for (int r = 0; r < bg.NumRows; r++)
            for (int c = 0; c < bg.NumCols; c++)
                if (bg.Blocks[r, c] != null &&
                   (!InBounds(r + bg.Row + 1, c + bg.Col, this) && (r + bg.Row > 0) ||
                   (InBounds(r + bg.Row, c + bg.Col, this) && _Blocks[r + bg.Row + 1, c + bg.Col] != null)))
                {
                    return true;
                }

            return Collision;
        }
コード例 #7
0
ファイル: BlockGrid.cs プロジェクト: DJSymBiotiX/BlockXNA
        public void ExplodeBlock(int row, int col)
        {
            if (_Blocks[row, col] != null && _Blocks[row, col].State == BlockState.Normal)
            {
                BlockGroup bg = new BlockGroup(NumRows, NumCols, this);
                bg.Add(_Blocks[row, col], row, col);
                bg.Blocks[row, col].State = BlockState.Exploding;

                _ExplodeBlocks.Add(bg);
            }
        }
コード例 #8
0
ファイル: BlockGrid.cs プロジェクト: DJSymBiotiX/BlockXNA
 public void Drop(BlockGroup blockGroup, int col)
 {
     blockGroup.Parent = this;
     blockGroup.Col = col;
     blockGroup.Row = -blockGroup.NumRows;
     _FreeBlocks.Add(blockGroup);
 }
コード例 #9
0
ファイル: BlockTest.cs プロジェクト: DJSymBiotiX/BlockXNA
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            InputLimiter[HORIZONTAL].Update(gameTime);
            InputLimiter[VERTICAL].Update(gameTime);
            HandleInput(gameTime);

            //dropLimiter.Reset();
            //dropLimiter.Enabled = false;
            dropLimiter.Update(gameTime);
            if (dropLimiter.Ready)
            {
                BlockGroup bg = new BlockGroup(1, 1, blockGrid);
                BlockType bt = (BlockType)RNG.Next(4);
                bg.Add(new Block(bt), 0, 0);
                blockGrid.Drop(bg, RNG.Next(blockGrid.NumCols));
            }
        }