/// <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;
        }
Exemple #2
0
        public override void Kill(cGameObject by)
        {
            this.Scene.LightMap.remove(this.p_followLight);
            this.Scene.LightMap.remove(this.eye);
            // this.spriteControl.ChangeState(new cSpriteState(MotionType.LIE, this.spriteControl.getCurrentState().HorizontalFacing));

            this.health = 0;
            this.killed = true;

            // int y = AppRandom.Choose<int>(new[] { 1,-1});

            this.Scene.QueueAction(() =>
            {
                Vector2f emitDirection = AppMath.Vec2NormalizeReturn(by.Velocity); //  new Vector2f(0.0f, y);

                float len   = (float)AppMath.Vec2Length(this.Velocity);
                float speed = len > 1.0f ? len : 0.0f;


                ShakeScreen.Init(this.pscene.Camera.ActualPosition);
                ShakeScreen.StartShake();


                Scene.Assets.PlaySound("blood_hit2", 25, this.position);
                //pscene.ParticleManager.Fireworks.NormalExplosion(new Particles.cEmissionInfo(this.Bounds.center, emitDirection));
                var e = pscene.ParticleManager["explosions"] as cExplosionController;
                e.NormalBlood(new EmissionInfo(this.Bounds.center, emitDirection, speed));

                e.Line(new EmissionInfo(this.Bounds.center, emitDirection));

                this.Scene.QueueAction(() =>
                {
                    /*
                     * if (this.IsOnGround)
                     * {
                     *  this.Scene.Effects.PlaceGround(this.Bounds.center.X, this.Bounds.rightBottom.Y, "side-explosion1");
                     * }
                     * else
                     */
                    {
                        this.Scene.Effects.Place(this.Bounds.center, "simple-explosion3");     // flash-black
                    }



                    // this.Scene.Effects.Place(intersection, "fire1");
                });

                // e.FastBlood(new EmissionInfo(this.Bounds.center,new Vector2f(0.0f, 0.0f)));

                //float gy = this.Bounds.rightBottom.Y; // ground y

                //pscene.Effects.PlaceGround(this.Bounds.center.X, gy, "side-explosion1");

                //pscene.EntityPool.getEntitiesInRadius()
                // pscene.Effects.Place(this.bounds.center, "simple-explosion2");
            }

                                   );

            this.Scene.QueueAction(() =>
            {
                Scene.Assets.PlaySound("coin_drop1", 20);

                ProbabilityRoll <int> numPickables = new ProbabilityRoll <int>();
                numPickables.add(70, 2);
                numPickables.add(30, 3);

                int num = numPickables.roll();
                for (int i = 0; i < num; ++i)
                {
                    pscene.EntityPool.AddPickup(
                        new cPickupAble(
                            this.Scene,
                            this.Bounds.center,
                            AppMath.GetRandomUnitVec(),                     // emitDirection,
                            PickupInfo.PickupType.COIN_GOLD)
                        );
                }
            });

            /*
             * new platformerGame.GameCommands.comPlacePickup(
             *  this.Scene,
             *  new GameObjects.cPickupAble(
             *      this.Scene,
             *      this.Scene.EntityPool.SpatialGrid,
             *      this.Bounds.center,
             *      emitDirection) )
             */
        }
        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);
        }