Exemplo n.º 1
0
        private void AddParticles(IStateOwner pOwner, int BlockX, int BlockY, int DirectionMultiplier, int RowsCleared)
        {
            //the actual block we are clearing...
            var     ClearingBlock = _BaseState.PlayField.Contents[BlockY][BlockX];
            SKColor baseColor     = TetrisGame.Choose(ClearLineParticleColours);
            Bitmap  sourcebitmap  = null;

            if (ClearingBlock != null && ClearingBlock is ImageBlock ib)
            {
                sourcebitmap = new Bitmap(ib._RotationImages[MathHelper.mod(ib.Rotation, ib._RotationImages.Length)]);
            }
            var blockWidth  = _BaseState.PlayField.GetBlockWidth((SKRect)pOwner.LastDrawBounds);
            var blockHeight = _BaseState.PlayField.GetBlockHeight((SKRect)pOwner.LastDrawBounds);
            var CoordPos    = new BCPoint(BlockX,
                                          BlockY - 2);

            lock (_BaseState.Particles)
            {
                List <BaseParticle> ToAdd = new List <BaseParticle>(ParticleCountPerBlock);
                for (int i = 0; i < ParticleCountPerBlock; i++)
                {
                    BCPoint ParticlePos = new BCPoint((float)TetrisGame.rgen.NextDouble(), (float)TetrisGame.rgen.NextDouble());
                    //choose a new random position within the block.
                    BCPoint NewParticlePoint = new BCPoint(CoordPos.X + ParticlePos.X, CoordPos.Y + ParticlePos.Y);
                    BCPoint Velocity         = new BCPoint(

                        (float)(DirectionMultiplier * (TetrisGame.rgen.NextDouble() * 1 + (Math.Abs(BlockX - (_BaseState.PlayField.ColCount / 2)) / 5))), 0

                        );
                    BCColor ChosenColor = baseColor;

                    if (sourcebitmap != null)
                    {
                        Point TargetPixel = new Point((int)(ParticlePos.X * sourcebitmap.Width), (int)(ParticlePos.Y * sourcebitmap.Height));
                        ChosenColor = sourcebitmap.GetPixel(TargetPixel.X, TargetPixel.Y);
                    }


                    BaseParticle p = new BaseParticle(NewParticlePoint, Velocity, ChosenColor);
                    if (RowsCleared >= 4)
                    {
                        if (TetrisGame.rgen.NextDouble() > 0.25d)
                        {
                            p.ColorCalculatorFunction = BaseParticle.GetRainbowColorFunc(pOwner, 500);
                        }
                    }
                    p.TTL = (uint)ClearParticleTTL;
                    ToAdd.Add(p);
                }
                _BaseState.Particles.AddRange(ToAdd);
            }
        }
Exemplo n.º 2
0
        private void AddParticles_Row(IStateOwner pOwner, BCRect RowBounds, int Lines = 1)
        {
            String UseText = RowClearText?[Lines] ?? $"{Lines}LINE";
            Func <BaseParticle, BCColor> TetrisColorFunc     = BaseParticle.GetRainbowColorFunc(pOwner);
            Func <BaseParticle, BCColor> SingleLineColorFunc = (o) =>
            {
                int    timebase      = 2000;
                double DarknessValue = (Math.Sin((float)pOwner.GetElapsedTime().Ticks / 2000) / 2) + 1;

                BCColor usecolor = (Color) new HSLColor(0, 120, DarknessValue * 120);

                return(usecolor);
            };

            Func <BaseParticle, BCColor> DoubleLineColorFunc = (o) =>
            {
                int    timebase      = 2000;
                double DarknessValue = Math.Sin((float)pOwner.GetElapsedTime().Ticks / 2000);

                BCColor usecolor = (Color) new HSLColor(75, 120, DarknessValue * 120);

                return(usecolor);
            };
            Func <BaseParticle, BCColor> TripleLineColorFunc = (o) =>
            {
                int    timebase      = 2000;
                double DarknessValue = Math.Sin((float)pOwner.GetElapsedTime().Ticks / 2000);

                BCColor usecolor = (Color) new HSLColor(150, 120, DarknessValue * 120);

                return(usecolor);
            };


            Func <BaseParticle, BCColor>[] LineFuncs = new Func <BaseParticle, BCColor>[]
            {
                SingleLineColorFunc, DoubleLineColorFunc, TripleLineColorFunc, TetrisColorFunc
            };
            //split the text into characters...

            char[] CharsToShow = UseText.ToCharArray();

            float XOffset = (int)((float)RowBounds.Width / 2 - ((float)CharsToShow.Length / 2)); //one character per block, ideally.

            List <CharParticle> MakeParticles = new List <CharParticle>();

            for (int x = 0; x < CharsToShow.Length; x++)
            {
                int          i            = x % CharsToShow.Length;
                CharParticle makeparticle = new CharParticle(new BCPoint(RowBounds.Left + XOffset + x, RowBounds.Top + RowBounds.Height / 2), new BCPoint(0, -0.05f), Color.Red, CharsToShow[i].ToString());
                makeparticle.TTL = 1500;
                //makeparticle.Decay = new BCPoint(0.5f, 0.5f);
                MakeParticles.Add(makeparticle);
                Lines = Lines > 4 ? Lines = 4:Lines;
                if (Lines >= 4)
                {
                    makeparticle.ColorCalculatorFunction = LineFuncs[Lines - 1];
                }

                else
                {
                    makeparticle.Color = new Color[] { Color.Red, Color.Green, Color.Yellow }[Lines - 1];
                }



                lock (_BaseState.TopParticles)
                {
                    _BaseState.TopParticles.AddRange(MakeParticles);
                }
            }
        }