コード例 #1
0
ファイル: Game1.cs プロジェクト: Sweetwater/TetrisXNA
        private void CheckLine()
        {
            Vector3 linePosition = new Vector3(-0.6f, floorPosition.Y, 0);
            Vector3 lineDirection = new Vector3(1, 0, 0);

            Ray line = new Ray(linePosition, lineDirection);
            Vector3[] vanishPositions = new Vector3[4];
            int vanishPositionNum = 0;
            for (int i = 0; i < 20; i++)
            {
                line.Position.Y += blockSize;
                int intersectsNum = 0;
                Block[] lineBlocks = new Block[10];

                foreach (Block block in blocks)
                {
                    bool isIntersects = (null != block.Bounding.Intersects(line));
                    if (isIntersects)
                    {
                        lineBlocks[intersectsNum] = block;
                        intersectsNum++;
                    }

                    if (intersectsNum == 10) {
                        vanishPositions[vanishPositionNum] = line.Position;
                        vanishPositionNum++;
                        foreach (Block lineBlock in lineBlocks)
                        {
                            VanishBlock vanishBlock = new VanishBlock(this, lineBlock.Model);
                            vanishBlock.Position = lineBlock.Position;
                            blocks.Remove(lineBlock);
                            vanishBlocks.Add(vanishBlock);
                        }
                        state = State.Vanish;
                        break;
                    }
                }
            }

            int index;
            vanishDownY = new float[blocks.Count];
            for (int i = 0; i < vanishPositionNum; i++)
            {
                float y = vanishPositions[i].Y;
                index = 0;
                foreach (Block block in blocks)
                {
                    if (block.Position.Y > y)
                    {
                        vanishDownY[index] += blockSize;
                    }
                    index++;
                }
            }
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: Sweetwater/TetrisXNA
        private void CorrectionBlockPosition(Block[] correctBlocks)
        {
            for (int i = 0; i < correctBlocks.Length; i++)
            {
                float blockY = correctBlocks[i].Position.Y;
                float distance = blockY - floorPosition.Y;
                double value = distance * 10.0f;
                value = Math.Ceiling(value);
                float offsetY = (float)value / 10.0f;

                correctBlocks[i].Position.Y = floorPosition.Y + offsetY;
                blocks.Add(correctBlocks[i]);
            }
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: Sweetwater/TetrisXNA
        private bool CheckFrameCollision(Block[] blocks)
        {
            BoundingBox[] frameBoundings = { leftFrameBounding, rightFrameBounding };

            foreach (Block block in blocks)
            {
                BoundingSphere blockBounding = block.Bounding;
                foreach (BoundingBox frameBounding in frameBoundings)
                {
                    bool isIntersects = blockBounding.Intersects(frameBounding);
                    if (isIntersects) return true;
                }
            }
            return false;
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: Sweetwater/TetrisXNA
 private bool CheckBlockCollision(Block[] checkBlocks)
 {
     foreach (Block checkBlock in checkBlocks)
     {
         BoundingSphere checkBounding = checkBlock.Bounding;
         foreach (Block block in blocks)
         {
             bool isIntersects = checkBounding.Intersects(block.Bounding);
             if (isIntersects) return true;
         }
     }
     return false;
 }
コード例 #5
0
ファイル: Tetrimino.cs プロジェクト: Sweetwater/TetrisXNA
        //public BoundingBox[] BoundingBox
        //{
        //    get
        //    {
        //        BoundingBox[] boundings = new BoundingBox[blocks.Length];
        //        for (int i = 0; i < blocks.Length; i++)
        //        {
        //            boundings[i] = blocks[i].Bounding;
        //        }
        //        return boundings;
        //    }
        //}
        public Tetrimino(Game1 game, Model model, int type)
        {
            this.game = game;
            this.rotation = 0;
            this.type = type;
            this.Position.X = 0.05f;

            blocks = new Block[layouts[type].Length];

            for (int i = 0; i < layouts[type].Length; i++)
            {
                Vector3 position = this.Position + layouts[type][i];
                blocks[i] = new Block(game, model);
                blocks[i].Position = position;
            }
        }
コード例 #6
0
ファイル: Tetrimino.cs プロジェクト: Sweetwater/TetrisXNA
        public Block[] GetRotationBlocks(float rotation)
        {
            Matrix rotationMatrix = Matrix.CreateRotationZ(this.rotation + rotation);

            Block[] rotationBlocks = new Block[layouts[type].Length];
            for (int i = 0; i < layouts[type].Length; i++)
            {
                rotationBlocks[i] = new Block(game, null);
                rotationBlocks[i].Position = this.Position + Vector3.Transform(layouts[type][i], rotationMatrix);
            }
            return rotationBlocks;
        }
コード例 #7
0
ファイル: Tetrimino.cs プロジェクト: Sweetwater/TetrisXNA
 public Block[] GetMoveBlocks(Vector3 moveVector)
 {
     Block[] moveBlocks = new Block[layouts[type].Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         moveBlocks[i] = new Block(game, null);
         moveBlocks[i].Position = blocks[i].Position + moveVector;
     }
     return moveBlocks;
 }