コード例 #1
0
ファイル: ExplosionEffect.cs プロジェクト: VN0/Pong-Game
        /*-------------------------------------
         * PUBLIC METHODS
         *-----------------------------------*/

        public override void Begin()
        {
            base.Begin();

            for (var i = 0; i < m_NumParticles; i++)
            {
                var size     = 0.02f + 0.02f * (float)s_Random.NextDouble();
                var particle = new RectangleEntity(m_X, m_Y, size, size);
                var theta    = 2.0f * (float)Math.PI * (float)s_Random.NextDouble();
                var r        = 0.4f + 0.4f * (float)s_Random.NextDouble();
                var a        = 0.2f + 0.2f * (float)s_Random.NextDouble();
                var w        = ((float)s_Random.NextDouble() - 0.5f) * 2.0f * (float)Math.PI * 6.0f;
                var vx       = (float)Math.Cos(theta) * r;
                var vy       = (float)Math.Sin(theta) * r;
                var body     = particle.GetComponent <BodyComponent>();

                body.Angle           = theta;
                body.AngularVelocity = w;
                body.Velocity        = new Vector2(vx, vy);

                particle.AddComponents(
                    new LifetimeComponent {
                    Lifetime = a
                }
                    );

                Game.Inst.Scene.AddEntity(particle);
            }
        }
コード例 #2
0
        /*-------------------------------------
         * NON-PUBLIC METHODS
         *-----------------------------------*/

        private void SpawnParticles()
        {
            if (!DisableAll)
            {
                Game.Inst.SetTimeout(() => Begin(), 0.1f);
            }

            var ball = m_Ball.GetComponent <BodyComponent>();

            if (ball.IsStatic)
            {
                return;
            }

            var p = ball.Position;
            var v = ball.Velocity;

            for (var i = 0; i < m_NumParticles; i++)
            {
                var x        = 0.08f * (Pong.Rnd() - 0.5f);
                var y        = 0.08f * (Pong.Rnd() - 0.5f);
                var size     = 0.01f + 0.01f * Pong.Rnd();
                var particle = new RectangleEntity(p.X + x, p.Y + y, size, size);
                var theta    = 2.0f * (float)Math.PI * Pong.Rnd();
                var r        = 0.05f + 0.1f * Pong.Rnd();
                var a        = 0.5f + 0.6f * Pong.Rnd();
                var w        = (Pong.Rnd() - 0.5f) * 2.0f * (float)Math.PI * 4.0f;
                var vx       = 0.3f * v.X + (float)Math.Cos(theta) * r;
                var vy       = 0.3f * v.Y + (float)Math.Sin(theta) * r;
                var body     = particle.GetComponent <BodyComponent>();

                body.Angle           = theta;
                body.AngularVelocity = w;
                body.Velocity        = new Vector2(vx, vy);

                particle.AddComponents(
                    new LifetimeComponent {
                    Lifetime = a
                },
                    new Components.GlowComponent()
                    );

                Game.Inst.Scene.AddEntity(particle);
            }
        }