예제 #1
0
        protected override Particle GenerateNewParticle()
        {
            int index = _rand.Next(0, 3);
            int ttl = _rand.Next(40, 80);
            //Rotate the point based on the center of the sprite
            // p = unrotated point, o = rotation origin
            //p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
            //p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy

            var origin = Entity.Body.Position + Entity.Render.Origin * Entity.Render.Scale;

            var unrotatedposition = new Vector2(
                Entity.Body.BoundingBox.X + Entity.Render.Origin.X * Entity.Render.Scale,
                Entity.Body.BoundingBox.Bottom);
            var angle = Entity.Body.Angle;

            var position = new Vector2(
                (float)(Math.Cos(angle) * (unrotatedposition.X - origin.X) - Math.Sin(angle) * (unrotatedposition.Y - origin.Y) + origin.X),
                (float)(Math.Sin(angle) * (unrotatedposition.X - origin.X) + Math.Cos(angle) * (unrotatedposition.Y - origin.Y) + origin.Y)
            );

            FadeParticle p = new FadeParticle(index, position, 10, ttl, this);
            p.Body.Angle = (float)_rand.NextDouble() / 2 - .25f;
            p.Physics.Thrust((float)_rand.NextDouble() + .1f);
            p.Render.Layer = .5f;
            p.Render.Color = Colors[_rand.Next(0, Colors.Count)];
            return p;
        }
예제 #2
0
        public override void Emit(int amount)
        {
            var random = new Random(DateTime.Now.Millisecond);
            float pislice = MathHelper.TwoPi / amount;
            for (int i = 0; i < amount; i++)
            {
                int index = random.Next(0, 3);

                float angle = pislice * i;
                Vector2 position = Entity.Body.Position;

                var p = new FadeParticle(index, position, 40, this)
                    {
                        Body = {Angle = angle},
                        TimeToLive = 50 + Entity.Health.HitPoints*20,
                        Physics = {Drag = 0.99f}
                    };
                p.Physics.Thrust(random.Next(1, 4));
                p.Render.Scale = (float)random.NextDouble() + .5f;
                Entity.AddEntity(p);
            }
        }
예제 #3
0
        public override void Emit(int amount)
        {
            var random = new Random(DateTime.Now.Millisecond);
            var pislice = MathHelper.TwoPi / amount;
            for (var i = 0; i < amount; i++)
            {
                var index = random.Next(0, 3);

                var angle = pislice * i;
                var position = Entity.Body.Position;

                var p = new FadeParticle(index, position, 40, this)
                    {
                        Body = {Angle = angle - (float) random.NextDouble()},
                        Physics = {AngularVelocity = (float) random.NextDouble()*.5f - .1f},
                        TimeToLive = 200
                    };
                p.Physics.Drag = 0.99f;
                p.Physics.Thrust((float)random.NextDouble() * 2.0f + 1f);
                p.Render.Scale = (float)random.NextDouble() + .75f;
                Entity.AddEntity(p);
            }
        }
예제 #4
0
        protected override Particle GenerateNewParticle()
        {
            int index = _rand.Next(0, 3);

            Particle p = new FadeParticle(index, Entity.Body.Position, 40, this);
            p.TimeToLive = 100;
            float angle = (float)_rand.NextDouble() * MathHelper.PiOver2;
            var anglev = (float)((_rand.NextDouble() - .5f) * 1.25f);
            p.Body.Angle = angle - anglev;
            p.Physics.Thrust((float)_rand.NextDouble() * 2);
            p.Render.Scale = .25f * Entity.Health.HitPoints + .75f;
            return p;
        }