Exemplo n.º 1
0
        public void Render(IStateOwner pOwner, SKCanvas pRenderTarget, CharParticle Source, GameStateSkiaDrawParameters Element)
        {
            var Alphause           = TranslateAlpha(Source);
            var CharPoint          = TranslatePosition(pOwner, pRenderTarget, Source.Position, Element);
            var FontSizeTranslate  = new BCPoint(1, Source.FontInfo.FontSize);
            var TranslatedFontSize = TranslatePosition(pOwner, pRenderTarget, FontSizeTranslate, Element);
            var useColor           = new SKColor(Source.Color.R, Source.Color.G, Source.Color.B, Alphause);

            SKRect Bound = new SKRect();

            skp.MeasureText(Source.Text, ref Bound);
            skp.TextSize = TranslatedFontSize.Y;
            SKPaint Foreground = new SKPaint()
            {
                Color = useColor, TextSize = TranslatedFontSize.Y, Typeface = TetrisGame.RetroFontSK
            };
            SKPaint Background = new SKPaint()
            {
                Color = new SKColor(0, 0, 0, Alphause), TextSize = TranslatedFontSize.Y, Typeface = TetrisGame.RetroFontSK
            };
            DrawTextInformationSkia skinfo = new DrawTextInformationSkia()
            {
                Text             = Source.Text,
                Position         = CharPoint,
                CharacterHandler = new DrawCharacterHandlerSkia(new VerticalWavePositionCharacterPositionCalculatorSkia()
                {
                    Height = (float)(pOwner.ScaleFactor * 6)
                }),
                ForegroundPaint = Foreground,
                ShadowPaint     = Background
            };

            skinfo.DrawFont = new SKFontInfo(TetrisGame.RetroFontSK, TranslatedFontSize.Y);
            //pRenderTarget.DrawText(Source.Text, CharPoint.X,CharPoint.Y,TetrisGame.RetroFontSK,  skp);
            //pRenderTarget.DrawTextSK(Source.Text, CharPoint, TetrisGame.RetroFontSK, useColor, skp.TextSize,1);
            SKMatrix cloned = SKMatrix.Identity;

            if (Source.Angle != 0)
            {
                cloned = pRenderTarget.TotalMatrix;
                pRenderTarget.RotateDegrees((float)Source.Angle);
            }

            pRenderTarget.DrawTextSK(skinfo);

            if (Source.Angle != 0)
            {
                pRenderTarget.SetMatrix(cloned);
            }
            //CharPoint -= new BCPoint(skp)
            //    skp.MeasureText(Source.Character);
        }
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);
                }
            }
        }