Esempio n. 1
0
 public Cluster(Vector2 position, float blockSize)
 {
     FirstBlock = new Block((BlockType)PuzzleGame.r.Next(0, 6), new Vector2(position.X, position.Y + blockSize / 2), blockSize);
     SecondBlock = new Block((BlockType)PuzzleGame.r.Next(0, 6), new Vector2(position.X, position.Y - blockSize / 2), blockSize);
     this.blockSize = blockSize;
     firstOldPosition = FirstBlock.Position;
     secondOldPosition = SecondBlock.Position;
 }
Esempio n. 2
0
 public Block[] Separate()
 {
     Block[] blocks = new Block[2];
     blocks[0] = FirstBlock;
     blocks[1] = SecondBlock;
     IsMoving = false;
     return blocks;
 }
Esempio n. 3
0
        /// <summary>
        /// Determines number of blocks of same color connected to and explodes them if needed
        /// </summary>
        private void CheckBlock(Block block)
        {
            if (block.BlockType != BlockType.Black)
            {
                List<Block> sameColorChain = new List<Block>();
                sameColorChain = CheckForChain(block, block.BlockType, sameColorChain);

                int notBlackCount = sameColorChain.FindAll(b => b.BlockType != BlockType.Black).Count;

                if (notBlackCount > 3)
                    ExplodeChain(sameColorChain);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds block if of right type and recursively checks neighbours
        /// </summary>
        /// <param name="block"></param>
        /// <param name="type"></param>
        /// <param name="chain"></param>
        /// <returns></returns>
        private List<Block> CheckForChain(Block block, BlockType type, List<Block> chain)
        {
            if (block != null && !chain.Contains(block))
            {
                if (block.BlockType == type || block.BlockType == BlockType.Black)
                {
                    chain.Add(block);

                    if (block.BlockType != BlockType.Black)
                    {
                        int blockX = GridPositionX(block.Position);
                        int blockY = GridPositionY(block.Position);
                        if (blockX - 1 >= 0)
                            chain = CheckForChain(staticBlocks[blockX - 1, blockY], type, chain);
                        if (blockX + 1 < staticBlocks.GetLength(0))
                            chain = CheckForChain(staticBlocks[blockX + 1, blockY], type, chain);
                        if (blockY - 1 >= 0)
                            chain = CheckForChain(staticBlocks[blockX, blockY - 1], type, chain);
                        if (blockY + 1 < staticBlocks.GetLength(1))
                            chain = CheckForChain(staticBlocks[blockX, blockY + 1], type, chain);
                    }
                }
            }
            return chain;
        }
Esempio n. 5
0
        /// <summary>
        /// Checks if a block collides with anything
        /// </summary>
        /// <param name="block"></param>
        protected void CheckForBlockCollision(Block block)
        {
            int posX = GridPositionX(block.Position);
            int posY = GridPositionY(block.Position);

            Vector2 pos = GetStaticPosition(block, posY);

            if (BlockHasCollided(block))
            {
                block.Attach(pos);
                staticBlocks[posX, posY] = block;

                if (BlackBlockCollision != null)
                    if (block.BlockType == BlockType.Black)
                        BlackBlockCollision(this, new BlackBlockCollisionEventArgs(pos));
            }
        }
Esempio n. 6
0
 protected Block CreateBlackBlock(int gridIndex)
 {
     Block blackBlock = new Block(BlockType.Black,
                 GridOrigin() + new Vector2(gridIndex * blockSize, 0), blockSize);
     blackBlock.IsMoving = true;
     blackBlock.DropSpeed = BaseDropSpeed * dropSpeedBonus;
     return blackBlock;
 }
Esempio n. 7
0
 /// <summary>
 /// Determines if a moving block collides with the bottom or a static block.
 /// </summary>
 /// <param name="block"></param>
 /// <returns></returns>
 protected bool BlockHasCollided(Block block)
 {
     int posX = GridPositionX(block.Position);
     int posY = GridPositionY(block.Position);
     //bottom collision (left) & block collision (right)
     return block.Position.Y >= Position.Y + 0.5 * (Height - blockSize) || staticBlocks[posX, posY - 1] != null;
 }
Esempio n. 8
0
 private Vector2 GetStaticPosition(Block block, int gridPosY)
 {
     return new Vector2(block.Position.X, Position.Y + 0.5f * Height - (gridPosY + 0.5f) * blockSize + 0.005f);
 }
Esempio n. 9
0
 private Image GetImage(Block block)
 {
     if (block.IsExploding)
         return explosionAnimation;
     return blockImages[(int)block.BlockType];
 }
Esempio n. 10
0
        /// <summary>
        /// Explodes a block and increments score counter
        /// </summary>
        /// <param name="block"></param>
        private void ExplodeBlockAndScore(Block block)
        {
            int blockX = GridPositionX(block.Position);
            int blockY = GridPositionY(block.Position);
            staticBlocks[blockX, blockY] = null;
            block.Explode();
            explodingBlocks.Add(block);

            if (block.BlockType != BlockType.Black)
                scoreCounter.Score += 50 * scoreMultiplier * SpeedMultiplier;
        }
Esempio n. 11
0
 private void DrawBlock(Block block, GameTime gameTime)
 {
     if (!block.IsDisposing)
         block.Draw(gameTime, GetImage(block));
 }