Ejemplo n.º 1
0
        public override void Render(IStateOwner pOwner, SKCanvas pRenderTarget, BaseParticle Source, GameStateSkiaDrawParameters Element)
        {
            if (Source.Color.R == 255 && Source.Color.B == 0 && Source.Color.G == 0)
            {
                ;
            }
            BCPoint usePosition = new BCPoint(Source.Position.X, Source.Position.Y);

            //have to try to get the standardRenderingProvider. If we can then we will use the coordinates as if they are a block position- otherwise, we use the coordinates directly.
            usePosition = TranslatePosition(pOwner, pRenderTarget, Source.Position, Element);

            BCPoint PrevPosition = TranslatePosition(pOwner, pRenderTarget, Source.Position - Source.Velocity, Element);

            byte useAlpha = TranslateAlpha(Source);

            if (SharePaint == null)
            {
                SharePaint = new SKPaint()
                {
                    Color = new SKColor(Source.Color.R, Source.Color.G, Source.Color.B, useAlpha), StrokeWidth = 1.2f
                }
            }
            ;
            else
            {
                SharePaint.Color = new SKColor(Source.Color.R, Source.Color.G, Source.Color.B, useAlpha);
            }
            pRenderTarget.DrawLine(PrevPosition, usePosition, SharePaint);
            //pRenderTarget.DrawRect(new SKRect(usePosition.X, usePosition.Y, usePosition.X + 2, usePosition.Y + 2), skp);
        }
Ejemplo n.º 2
0
        public BCRect GetBlockBounds(IStateOwner pOwner, SKRect Bounds, BCPointI TopLeft, BCPointI BottomRight)
        {
            float BlockWidth  = (float)(GetBlockWidth(Bounds));
            float BlockHeight = (float)(GetBlockHeight(Bounds));


            BCPoint TopLeftF     = new BCPoint((float)TopLeft.X * BlockWidth, (float)TopLeft.Y * BlockHeight);
            BCPoint BottomRightF = new BCPoint((float)BottomRight.X + BlockWidth + BlockWidth, (float)TopLeft.Y * BlockHeight + BlockHeight);

            return(new BCRect(TopLeftF.X, TopLeftF.Y, BottomRightF.X, BottomRightF.Y));
        }
Ejemplo n.º 3
0
        //GeneratePopParticles(pOwner, state, iterate);
        private void GeneratePopParticles(IStateOwner pOwner, GameplayGameState gstate, SKPointI pt)
        {
            var rgen    = TetrisGame.rgen;
            var popItem = gstate.PlayField.Contents[pt.Y][pt.X];

            BCColor[] useColor = YellowColors;
            if (popItem is LineSeriesBlock lsb)
            {
                switch (lsb.CombiningIndex)
                {
                case LineSeriesBlock.CombiningTypes.Red:
                    useColor = RedColors;
                    break;

                case LineSeriesBlock.CombiningTypes.Blue:
                    useColor = BlueColors;
                    break;

                case LineSeriesBlock.CombiningTypes.Yellow:
                    useColor = YellowColors;
                    break;

                case LineSeriesBlock.CombiningTypes.Orange:
                    useColor = OrangeColors;
                    break;

                case LineSeriesBlock.CombiningTypes.Magenta:
                    useColor = MagentaColors;
                    break;

                case LineSeriesBlock.CombiningTypes.Green:
                    useColor = GreenColors;
                    break;
                }
                for (int i = 0; i < ParticlesPerPop; i++)
                {
                    PointF  Offset   = new PointF((float)rgen.NextDouble(), (float)rgen.NextDouble());
                    BCColor selColor = TetrisGame.Choose(useColor);
                    BCPoint Velocity = TetrisGame.Choose(CardinalOptions);
                    float   Speed    = (float)rgen.NextDouble() * (MAX_SPEED - MIN_SPEED) + MIN_SPEED;
                    float   Sign     = TetrisGame.Choose(new float[] { -1f, 1f });

                    BCPoint VelocityUse = new BCPoint(Velocity.X * Speed * Sign, Velocity.Y * Speed * Sign);

                    BaseParticle bp = new BaseParticle(new BCPoint(pt.X + Offset.X, pt.Y + Offset.Y), VelocityUse, selColor);
                    gstate.Particles.Add(bp);
                }
            }

            /*for (int i=0;i<ParticlesPerPop;i++)
             * {
             *
             * }*/
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
            }
        }
 private void GenerateDropParticles(BCPoint Location, int NumGenerate, Func <BCPoint> VelocityGenerator, Func <float, float, BCColor> ColorFunc)
 {
     lock (Particles)
     {
         for (int i = 0; i < NumGenerate; i++)
         {
             var          genX         = (float)rgen.NextDouble();
             var          genY         = (float)rgen.NextDouble();
             BCPoint      Genpos       = new BCPoint(Location.X + genX, Location.Y + genY);
             BCColor      ChosenColor  = ColorFunc(genX, genY);
             BaseParticle MakeParticle = new BaseParticle(Genpos, VelocityGenerator(), ChosenColor);
             Particles.Add(MakeParticle);
         }
     }
 }
Ejemplo n.º 7
0
        protected BCPoint TranslatePosition(IStateOwner pOwner, SKCanvas pRenderTarget, BCPoint Position, GameStateSkiaDrawParameters Element)
        {
            BCPoint           Result        = Position;
            GameplayGameState foundstandard = null;

            if (pOwner.CurrentState is GameplayGameState standard)
            {
                foundstandard = standard;
            }
            else if (pOwner.CurrentState is ICompositeState <GameplayGameState> composite)
            {
                foundstandard = composite.GetComposite();
            }

            if (foundstandard != null)
            {
                Result.X = foundstandard.PlayField.GetBlockWidth(Element.Bounds) * Position.X;
                Result.Y = foundstandard.PlayField.GetBlockHeight(Element.Bounds) * Position.Y;
            }
            return(Result);
        }
Ejemplo n.º 8
0
 public override bool GameProc(IStateOwner pOwner)
 {
     EndPoint += Velocity;
     return(base.GameProc(pOwner));
 }
Ejemplo n.º 9
0
 public LineParticle(BCPoint StartPoint, BCPoint EndPoint, BCPoint pVelocity, BCColor pColor) : base(StartPoint, pVelocity, pColor)
 {
 }
Ejemplo n.º 10
0
 public BaseParticle(BCPoint pPosition, BCPoint pVelocity, BCColor pColor)
 {
     Position = pPosition;
     Velocity = pVelocity;
     Color    = pColor;
 }
Ejemplo n.º 11
0
        public CharParticle(BCPoint pPosition, BCPoint pVelocity, BCColor pColor, String pText) : base(pPosition, pVelocity, pColor)
        {
            Text = pText;

            FontInfo = new BCFont(useFont.FontFamily.Name, 1, BCFont.BCFontStyle.Regular);
        }
Ejemplo n.º 12
0
 public BitmapParticle(BCPoint pPosition, BCPoint pVelocity, BCColor pColor, BCImage img) : base(pPosition, pVelocity, pColor)
 {
     Image = img;
 }
Ejemplo n.º 13
0
 protected RotatableBaseParticle(BCPoint pPosition, BCPoint pVelocity, BCColor pColor) : base(pPosition, pVelocity, pColor)
 {
 }
Ejemplo n.º 14
0
 public void MouseMove(BCPoint Position)
 {
     LastMouseMovement = Position;
 }
Ejemplo n.º 15
0
 public void MouseUp(StateMouseButtons ButtonUp, BCPoint Position)
 {
     //throw new NotImplementedException();
 }