private void updateParticle2(float step_time, Particle p, cWorld world)
        {
            p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time));

            // p.Vel.X *= p.SlowDown;
            // p.Vel.Y *= p.SlowDown;

            AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed);

            //world.collideParticleSAT(p, step_time, false);

            //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel);
            p.LastPos = p.Pos;
            p.Pos.X  += p.Vel.X * step_time;
            p.Pos.Y  += p.Vel.Y * step_time;

            if (!AppMath.Vec2IsZero(p.Vel))
            {
                p.Heading  = AppMath.Vec2NormalizeReturn(p.Vel);
                p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading);
            }

            world.collideParticleRayTrace(p, step_time);


            p.Opacity -= p.Fade * step_time;
        }
        public override void Update(float step_time)
        {
            lastPosition.X = position.X;
            lastPosition.Y = position.Y;
            //velocity.Y += (Constants.GRAVITY/2.0f) * step_time;
            position.X += velocity.X * step_time;
            position.Y += velocity.Y * step_time;



            this.Bounds.SetPosByTopLeft(position);
            this.hitCollisionRect = Bounds;

            var world = Scene.World;

            world.collideSAT(this, step_time, false, () => {
                velocity = new Vector2f(0.0f, 0.0f);
                this.Scene.QueueAction(() =>
                {
                    this.Scene.Effects.Place(position, "simple-explosion2");
                });

                this.kill();
            });

            /*
             * if (this.checkCollisionWithWorld(owner.Scene.World, ref intersection))
             * {
             *  //this.alive = false; // if not set to false, bullets will be shown
             *  position.X = intersection.X;
             *  position.Y = intersection.Y;
             *  velocity = new Vector2f(0.0f, 0.0f);
             *  //cAssetManager.playSound("wallhit", 5);
             *
             *  this.Scene.QueueAction(() =>
             *  {
             *      this.Scene.Effects.Place(intersection, "simple-explosion2");
             *  });
             *
             *  this.kill();
             * }
             */

            if (!AppMath.Vec2IsZero(velocity))
            {
                heading = AppMath.Vec2NormalizeReturn(velocity);
                //orientation = cAppMath.GetAngleOfVector(heading);
                //Side = Math->Vec2Perp(Heading);
            }
        }
Exemple #3
0
        public override void Update(float step_time)
        {
            cWorld world = particleManager.Scene.World;

            for (int i = 0; i < pool.CountActive; ++i)
            {
                Particle p = pool.get(i);

                if (!p.Intersects)
                {
                    /*
                     * p.Dims.Y += p.ScaleSpeed * step_time; //+=
                     * p.Dims.y += p.ScaleSpeed * step_time; //+=
                     */
                    AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f);


                    p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time));

                    p.Vel.X *= p.SlowDown;
                    p.Vel.Y *= p.SlowDown;

                    //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel);
                    p.LastPos = p.Pos;
                    p.Pos.X  += p.Vel.X * step_time;
                    p.Pos.Y  += p.Vel.Y * step_time;



                    if (!AppMath.Vec2IsZero(p.Vel))
                    {
                        p.Heading  = AppMath.Vec2NormalizeReturn(p.Vel);
                        p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading);
                    }

                    world.collideParticleRayTrace(p, step_time);
                }

                p.Opacity -= p.Fade * step_time;

                if (p.Opacity <= 0.0f)
                {
                    p.Opacity = 0.0f;

                    pool.deactivate(i);
                }

                p.Color.A = (byte)p.Opacity;
            }
        }
        protected override void initParticle(EmissionInfo emission)
        {
            Particle particle = emission.Particle;

            particle.Pos      = emission.StartPosition;
            particle.LastPos  = particle.Pos;
            particle.ViewPos  = particle.Pos;
            particle.MaxSpeed = AppMath.GetRandomNumber(minSpeed, maxSpeed); //700, 900 | (400, 600); //3, 8//Math->GetRandomNumber(510, 800); // 2000.0f

            if (!AppMath.Vec2IsZero(emission.EmitDirection))
            {
                Vector2f particleDirection = AppMath.GetRandomVecBySpread(emission.EmitDirection, this.maxSpread);
                particle.Vel = new Vector2f(particleDirection.X * particle.MaxSpeed, particleDirection.Y * particle.MaxSpeed);
            }
            else
            {
                // float angle = (float)cAppMath.DegressToRadian(cAppMath.GetRandomNumber(0, 360));//sDivisions * m_Angles;

                particle.Vel = AppMath.GetRandomUnitVec() * particle.MaxSpeed;
                // particle.Vel = new Vector2f((float)Math.Cos(angle) * particle.MaxSpeed, (float)Math.Sin(angle) * particle.MaxSpeed);
            }

            //float dir = Math->GetRandomClamped();



            //particle.m_Vel = sf::Vector2f(Math->GetRandomClamped() * particle.m_MaxSpeed, Math->GetRandomClamped() *particle.m_MaxSpeed);
            particle.SlowDown = slowDown; //0.92f;
                                          //particle.m_SlowDown = (float)Math->GetRandomDoubleInRange(0.55, 0.7); //0.6f;
                                          //phs->AddForce( sf::Vector2f(Math->GetRandomClamped() * phs->MaxSpeed, Math->GetRandomClamped() * phs->MaxSpeed) );

            Vector2u uSize = this.renderStates.Texture.Size;

            particle.Scale = (float)AppMath.GetRandomDoubleInRange(this.minScale, this.maxScale);
            particle.Dims  = new Vector2f(uSize.X * particle.Scale, uSize.Y * particle.Scale);

            particle.ScaleSpeed = -AppMath.GetRandomNumber(5, 20); //10.50
            particle.Color      = Utils.GetRandomBlueColor();
            particle.Opacity    = 255.0f;
            particle.Life       = 1.0f;
            particle.Fade       = 80; // 90; //Math->GetRandomNumber(100, 240);

            particle.Intersects = false;
        }
        /// <summary>
        /// Main update protocol.
        /// </summary>
        /// <param name="step_time"></param>
        /// <param name="p"></param>
        /// <param name="world"></param>
        private void updateParticle1(float step_time, Particle p, cWorld world)
        {
            // Particle's update code comes here.


            p.Dims.X += p.ScaleSpeed * step_time; //+=
            p.Dims.Y += p.ScaleSpeed * step_time; //+=

            if (AppMath.Vec2Length(p.Dims) < 0.5f)
            {
                p.Dims.X = 0.0f;
                p.Dims.Y = 0.0f;
            }

            p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time));

            p.Vel.X *= p.SlowDown;
            p.Vel.Y *= p.SlowDown;

            AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f);

            // world.collideParticleSAT(p, step_time, false);

            //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel);
            p.LastPos = p.Pos;
            p.Pos.X  += p.Vel.X * step_time;
            p.Pos.Y  += p.Vel.Y * step_time;

            if (!AppMath.Vec2IsZero(p.Vel))
            {
                p.Heading  = AppMath.Vec2NormalizeReturn(p.Vel);
                p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading);
            }

            world.collideParticleRayTrace(p, step_time);


            p.Opacity -= p.Fade * step_time;
        }
        public override void Update(float step_time)
        {
            this.renderer.Update(step_time);

            cPlayer player = Scene.Player;

            if (this.pulling)
            {
                Vector2f predicted = AppMath.Vec2NormalizeReturn((player.Bounds.center + (player.Velocity * step_time)) - this.Bounds.center);
                // pull pickup
                //Vector2f toPlayer = cAppMath.Vec2NormalizeReturn(player.Bounds.center - this.Bounds.center);

                // G * ((m1*m2) / (d*d))
                float f = PULL_FORCE * 150f; // * (100000.0f / ( d*d) );
                this.AddForce(predicted * f);
            }

            /*
             * else
             * {
             *  this.pulling = false;
             * }
             */

            // applying some gravity
            force.Y += (false == pulling) ? (Constants.GRAVITY * 40.0f * step_time) : 0.0f;

            velocity.X += force.X * step_time;
            velocity.Y += force.Y * step_time;

            //velocity.X = Math.Abs(velocity.X) < 0.05f ? 0.0f : velocity.X;
            //velocity.Y = Math.Abs(velocity.Y) < 0.05f ? 0.0f : velocity.Y;

            double len = AppMath.Vec2Length(velocity);

            if (len < 0.1)
            {
                velocity = new Vector2f(0.0f, 0.0f);
            }

            AppMath.Vec2Truncate(ref velocity, MaxSpeed);

            // get more precise result calling it here (because of the updated velocity)
            // instead of calling at the beginning of this update method
            checkCollisionWithWorld(step_time);

            lastPosition = position;
            position.X  += velocity.X * step_time;
            position.Y  += velocity.Y * step_time;

            Bounds.SetPosByCenter(position);
            this.hitCollisionRect = Bounds;

            if (!AppMath.Vec2IsZero(velocity))
            {
                heading     = AppMath.Vec2NormalizeReturn(velocity);
                orientation = AppMath.GetAngleOfVector(heading);
            }

            force = new Vector2f(0.0f, 0.0f);
        }
        public override void Update(float step_time)
        {
            cWorld world = particleManager.Scene.World;

            /*
             * if(emiting && this.emitTimer.isReady())
             * {
             * // initParticle();
             *  remaining -= 1;
             *  emiting = remaining > 0;
             * }
             */

            for (int i = 0; i < pool.CountActive; ++i)
            {
                Particle p = pool.get(i);

                // p.Vel.Y += (Constants.GRAVITY*30 * (step_time * step_time));

                p.Vel.X *= p.SlowDown;
                p.Vel.Y *= p.SlowDown;

                AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed);

                //world.collideParticleSAT(p, step_time);

                //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel);

                Vector2u uSize = this.renderStates.Texture.Size;
                p.Scale -= p.ScaleSpeed * step_time;
                p.Dims   = new Vector2f(uSize.X * p.Scale, uSize.Y * p.Scale);

                p.LastPos = p.Pos;
                p.Pos.X  += p.Vel.X * step_time;
                p.Pos.Y  += p.Vel.Y * step_time;

                if (!AppMath.Vec2IsZero(p.Vel))
                {
                    p.Heading = AppMath.Vec2NormalizeReturn(p.Vel);
                    // p.Rotation = (float)cAppMath.GetAngleOfVector(p.Heading);
                }

                world.collideParticleRayTrace(p, step_time, true, false);

                p.Opacity -= p.Fade * step_time;

                if (p.Opacity <= 0.0f || p.Scale <= 0.0f)
                {
                    p.Opacity = 0.0f;
                    p.Scale   = 0.0f;
                    p.Life   -= 1.0f;

                    if (p.Life <= 0.0f)
                    {
                        pool.deactivate(i);
                    }
                    else
                    {
                        this.reinit(p);
                    }
                }

                p.Color.A = (byte)p.Opacity;
            }
        }