Пример #1
0
        public void GenerateBallStop(Sprite sprite, Color color)
        {
            if (sprite is MoveableSprite)
            {
                MoveableSprite movsprite = (MoveableSprite)sprite;
                Texture2D      texture   = sprite.Texture.Texture;
                Random         r         = Program.Game.Random;

                float         scale = (float)sprite.CollisionArea.Width / texture.Width;
                int           ps = 32;
                int           w = texture.Width / ps, h = texture.Height / ps;
                ParticleForce gravity = new GravityPoint(new Vector2(sprite.CollisionArea.X + sprite.CollisionArea.Width / 2, sprite.CollisionArea.Y + sprite.CollisionArea.Height / 2), 0.5f, false);

                for (int i = 0; i < 6; i++)
                {
                    for (int y = 0; y < h; y++)
                    {
                        for (int x = 0; x < w; x++)
                        {
                            if ((x + y) % 1 == 0)
                            {
                                particles.Add(new Particle(new TextureSource(texture, new Rectangle(x * ps, y * ps, ps, ps)), r.Next(500),
                                                           sprite.Position + new Vector2(x * ps * scale, y * ps * scale),
                                                           movsprite.Velocity.X * 20 * ((float)r.NextDouble() - 0.5f),
                                                           movsprite.Velocity.Y * 20 * ((float)r.NextDouble() - 0.5f),
                                                           0.95f, 0.95f,
                                                           color, scale, gravity));
                            }
                        }
                    }
                }
            }
        }
        public ISprite Add(IApiHelper coreApiHelper, Texture2D texture, Rectangle sourceRectangle)
        {
            MoveableSprite moveableSprite = new MoveableSprite(this._sprites.Count, this, texture, sourceRectangle);

            this._sprites.Add(moveableSprite);
            this._dirty = true;

            if (this._warnOnAdd)
            {
                coreApiHelper.Log("A sprite was added to the custom item sprite sheet after initialization. The sprite sheet will be regenerated the next time it is used. Item sprites should only be registered during initialization so the sprite sheet doesn't need to be constantly regenerated.", LogLevel.Warn);
            }
            else
            {
                coreApiHelper.Log($"Added a sprite to the custom item sprite sheet with index {moveableSprite.Index}", LogLevel.Trace);
            }

            return(moveableSprite);
        }
 public MoveableSprite(int index, ISpriteSheet parentSheet, Texture2D texture, Rectangle sourceRectangle) : base(index, parentSheet)
 {
     this._sourceRectangle = sourceRectangle;
     this.Data             = MoveableSprite.GetDataFromTexture(texture, sourceRectangle);
 }