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;
        }
Ejemplo n.º 2
0
        public override bool Fire(Vector2f target)
        {
            if (this.isReadForNextShot())
            {
                Vector2f dir            = AppMath.Vec2NormalizeReturn(target - owner.Bounds.center);
                Vector2f toSpreadTarget = AppMath.GetRandomVecBySpread(dir, spread);


                this.Shot(toSpreadTarget);
                decreaseAmmo();


                owner.Scene.Assets.PlaySound("cg1", 2);

                /*
                 * this.owner.Scene.QueueAction(() =>
                 * {
                 *  var e = this.owner.Scene.ParticleManager["explosions"] as cExplosionController;
                 *  e.Line(new EmissionInfo(this.owner.Bounds.center, toSpreadTarget));
                 *
                 * });
                 */
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override void Hit(int amount, cGameObject entity_by)
        {
            base.Hit(amount, entity_by);

            if (this.health <= 0)
            {
                this.Kill(entity_by);
                //this.Scene.ParticleManager.AddNormalBloodExplosion(this.Bounds.center);


                return;
            }

            //this.spriteControl.ChangeState(new cSpriteState(MotionType.FALL, this.spriteControl.getCurrentState().HorizontalFacing));
            //this.Scene.ParticleManager.AddLittleBloodExplosion(this.Bounds.center, 3);

            this.Scene.QueueAction(
                () =>
            {
                Scene.Assets.PlaySound("body_hit1", 8);
                var e = pscene.ParticleManager["explosions"] as cExplosionController;
                // e.LittleBlood(new Particles.EmissionInfo(this.Bounds.center));
                var dir = AppMath.Vec2NormalizeReturn(entity_by.Velocity);

                float maxLen = (float)AppMath.GetRandomDoubleInRange(10.0, this.Bounds.diagonalLength());
                Vector2f end = AppMath.ScaleVector(entity_by.Position, AppMath.Vec2NormalizeReturn(dir), maxLen);

                // approximately:
                Vector2f point = AppMath.GetRandomPointOnLine(entity_by.Position, end);
                e.LittleLine(new Particles.EmissionInfo(point, dir));
            });
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
0
        public override void Update(float step_time)
        {
            double dist = AppMath.Vec2Distance(Scene.Player.Bounds.center, this.Bounds.center);

            if (dist <= SPOT_DISTANCE)
            {
                Vector2f toTarget = AppMath.Vec2NormalizeReturn((Scene.Player.Bounds.center + Scene.Player.Velocity) - this.Bounds.center);


                float      ang = AppMath.GetAngleBetwenVecs(toTarget, gunFacingDirection);
                Quaternion q   = Quaternion.CreateFromAxisAngle(new Vector3f(toTarget.X, toTarget.Y, 0.0f), ang);
                Quaternion q2  = Quaternion.CreateFromAxisAngle(new Vector3f(gunFacingDirection.X, gunFacingDirection.Y, 0.0f), ang);
                q = Quaternion.Slerp(q, q2, ang);

                gunFacingDirection = new Vector2f(q.X, q.Y); //  toTarget;
                gun.Fire(Scene.Player.Bounds.center /*+ Scene.Player.Velocity * step_time*/);
            }
        }
Ejemplo n.º 7
0
        public void Update(Vector2f target, AABB region_bounds, float step_time = Constants.STEP_TIME)
        {
            this.Target      = target;
            PreviousPosition = ActualPosition;
            if (Smooth)
            {
                Vector2f dir = AppMath.Vec2NormalizeReturn(Target - ActualPosition);
                float    len = (float)AppMath.Vec2Distance(ActualPosition, Target);
                Vector2f vel = dir * (len * Smoothness);
                //AppMath.Vec2Truncate(ref vel, 2.0f);
                //vel += ShakeScreen.Offset;
                ActualPosition += vel;
            }
            else
            {
                ActualPosition = Target + ShakeScreen.Offset;
            }

            checkBounds(region_bounds);
        }
        /// <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;
        }
Ejemplo n.º 9
0
        public override bool Fire(Vector2f target)
        {
            if (this.isReadForNextShot())
            {
                Vector2f dir       = AppMath.Vec2NormalizeReturn(target - owner.Bounds.center);
                float    dirAngle  = (float)AppMath.GetAngleOfVector(dir);
                float    unitAngle = spread / bulletsPerShot;
                float    tangle    = dirAngle - ((bulletsPerShot / 2.0f) * unitAngle);
                for (int i = 0; i < bulletsPerShot; ++i)
                {
                    tangle += i * unitAngle;
                    //Vector2f toSpreadTarget = cAppMath.GetRandomVecBySpread(dir, spread);
                    Vector2f toSpreadTarget = new Vector2f((float)Math.Cos(tangle), (float)Math.Sin(tangle));

                    this.Shot(toSpreadTarget);
                }

                owner.Scene.Assets.PlaySound("shotgun", 3);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
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) )
             */
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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;
            }
        }