Exemple #1
0
        public void Detonate()
        {
            if (CheckFlag(Flags.DELETE))
            {
                return;
            }
            RaiseFlag(Flags.DELETE);
            Body.CollisionGroup = Fox.FOX_NONE_COLLISION_GROUP;
            Body.IgnoreRayCast = true;
            Explosion exp = new Explosion(100, 500, 1.0f, 1.0f, scene.World, Position);
            exp.Initialize(BaseGame.Get.Content);
            scene.AddNode(exp);

            AudioQueue.PlayOnce("Sounds/Explosion");
        }
Exemple #2
0
        public override void OnPress(Vector2 pos)
        {
            base.OnPress(pos);
            RaiseFlag(Jabber.Flags.DELETE);
            Body.RaiseFlag(Jabber.Flags.DELETE);
            Body.IgnoreRayCast = true;
            Body.CollisionGroup = Fox.FOX_NONE_COLLISION_GROUP;
            Explosion exp = new Explosion(10, 300, 1.0f, 0.1f, scene.World, Position);
            exp.Initialize(Jabber.BaseGame.Get.Content);
            scene.AddNode(exp);

            List<Fox> foxes = new List<Fox>();
            for (int i = 0; i < scene.Nodes.Count; i++)
            {
                if (scene.Nodes[i] is Fox)
                {
                    Fox f = scene.Nodes[i] as Fox;
                    if (f.IsAlive)
                    {
                        foxes.Add(f);
                    }
                }
            }
            float Nearest = float.MaxValue;
            List<Vector2> nearestPos = new List<Vector2>();
            Vector2 curNearest = Vector2.Zero;
            int usingI = -1;
            for (int i = 0; i < foxes.Count; i++)
            {
                if ((Position - foxes[i].Position).Length() < Nearest)
                {
                    usingI = i;
                    Nearest = (Position - foxes[i].Position).Length();
                    curNearest = foxes[i].Position;
                }
            }
            if (usingI >= 0)
            {
                Nearest = float.MaxValue;
                foxes.RemoveAt(usingI);
                nearestPos.Add(curNearest);

                usingI = -1;
                if (foxes.Count > 0)
                {
                    for (int i = 0; i < foxes.Count; i++)
                    {
                        if ((Position - foxes[i].Position).Length() < Nearest)
                        {
                            usingI = i;
                            Nearest = (Position - foxes[i].Position).Length();
                            curNearest = foxes[i].Position;
                        }
                    }
                    if (usingI >= 0)
                    {
                        Nearest = float.MaxValue;
                        foxes.RemoveAt(usingI);
                        nearestPos.Add(curNearest);

                        usingI = -1;
                        if (foxes.Count > 0)
                        {
                            for (int i = 0; i < foxes.Count; i++)
                            {
                                if ((Position - foxes[i].Position).Length() < Nearest)
                                {
                                    usingI = i;
                                    Nearest = (Position - foxes[i].Position).Length();
                                    curNearest = foxes[i].Position;
                                }
                            }
                            if (usingI >= 0)
                            {
                                foxes.RemoveAt(usingI);
                                nearestPos.Add(curNearest);
                            }
                        }
                    }
                }
            }
            AudioQueue.PlayOnce("Sounds/Explode_Chicken");
            Deactivate();
            Vector2 bodypos = Body.Position;
            Body.PosX = -10000;
            for (int i = 0; i < nearestPos.Count; i++)
            {
                Chicken_Mini e = new Chicken_Mini(scene);
                e.Position = bodypos;
                e.Initialize(Jabber.BaseGame.Get.Content);
                scene.AddNode(e);

                Vector2 dir = (nearestPos[i] - bodypos);
                dir.Normalize();

                float dist = (nearestPos[i] - bodypos).Length();

                float ydif = Math.Abs(bodypos.Y - nearestPos[i].Y);
                float xdif = Math.Abs(bodypos.X - nearestPos[i].X);
                float curY = bodypos.Y;
                float tarX = nearestPos[i].X;

                float horizontalSpeed = (dir * dist * 0.01f).X;
                /*
                FarWorld f = new FarWorld();
                f.Initialize(World.Gravity);
                JabActor circle = f.CreateSphere(Width / 2.0f, bodypos, JabActor.BodyType.DYNAMIC);
                circle.Mass = Body.Mass;
                circle.Restitution = Body.Restitution;
                circle.LinearDamping = 0.5f;
                circle.LinearVelocity = new Vector2(horizontalSpeed, 0);

                float lastDist = float.MaxValue;
                float lastY = 0;
                while (true)
                {
                    f.Update(new GameTime(new TimeSpan(0, 0, 0, 0, 33), new TimeSpan(0, 0, 0, 0, 33)));
                    float curDist = Math.Abs(circle.PosX - tarX);
                    if (lastDist < curDist)
                    {
                        break;
                    }
                    lastY = circle.PosY;
                    lastDist = curDist;
                }

                float yAtDest = circle.PosY;
                float tarY = nearestPos[i].Y;

                float upWardRequired = (yAtDest - tarY) / 100.0f;
                */
                e.Body.LinearVelocity = dir * 20;// *0.03f;// new Vector2(horizontalSpeed, horizontalSpeed);
                e.vectorDir = dir * 20.0f;
            }
        }
Exemple #3
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            distTravelled += Body.LinearVelocity.Length();
            if (AsType.UniformScale < 0.69f)
            {
                AsType.UniformScale = JabMath.MoveTowards(AsType.UniformScale, 0.7f, 0.25f);
            }
            else
            {
                AsType.UniformScale = 0.7f;
            }
            if (distTravelled > 32)
            {
                Body.CollisionGroup = 0;
            }

            if (destructionTimer > 0)
            {
                destructionTimer -= gttf(gameTime);
                if (destructionTimer < 0)
                {
                    RaiseFlag(Jabber.Flags.DELETE);

                    Explosion exp = new Explosion(10, 300, 1.0f, 0.7f, scene.World, Position);
                    Body.IgnoreRayCast = true;
                    exp.Initialize(Jabber.BaseGame.Get.Content);
                    exp.Position = Position;
                    scene.AddNode(exp);
                    RaiseFlag(Jabber.Flags.DELETE);
                    Body.IgnoreRayCast = false;

                    AudioQueue.PlayOnce("Sounds/Explode_Chicken");
                }
                else
                {
                    float val = destructionTimer;
                    Colour = new Color(1.0f, val, val, 1.0f);

                   // AsType.UniformScale = (float)Math.Sin(destructionTimer * 5.0f * JabMath.PI) + 1;

                    AsType.UniformScale = JabMath.LinearInterpolate(0.8f, 0.85f, (float)Math.Sin(destructionTimer * 5.0f * JabMath.PI) + 1);
                    DoDimensions = false;
                    int k = 0;
                }
            }
            if (Body.LinearVelocity.Length() < 0.001f)
            {
                noMoveTimer += gttf(gameTime);
                if (noMoveTimer > 1.0f && destructionTimer < 0)
                {
                    destructionTimer = 1.0f;
                }
            }
            else
            {
                noMoveTimer = 0.0f;
            }
        }
Exemple #4
0
        public override void OnPress(Vector2 pos)
        {
            base.OnPress(pos);
            RaiseFlag(Jabber.Flags.DELETE);
            Body.RaiseFlag(Jabber.Flags.DELETE);
            Body.IgnoreRayCast  = true;
            Body.CollisionGroup = Fox.FOX_NONE_COLLISION_GROUP;
            Explosion exp = new Explosion(10, 300, 1.0f, 0.1f, scene.World, Position);

            exp.Initialize(Jabber.BaseGame.Get.Content);
            scene.AddNode(exp);

            List <Fox> foxes = new List <Fox>();

            for (int i = 0; i < scene.Nodes.Count; i++)
            {
                if (scene.Nodes[i] is Fox)
                {
                    Fox f = scene.Nodes[i] as Fox;
                    if (f.IsAlive)
                    {
                        foxes.Add(f);
                    }
                }
            }
            float          Nearest    = float.MaxValue;
            List <Vector2> nearestPos = new List <Vector2>();
            Vector2        curNearest = Vector2.Zero;
            int            usingI     = -1;

            for (int i = 0; i < foxes.Count; i++)
            {
                if ((Position - foxes[i].Position).Length() < Nearest)
                {
                    usingI     = i;
                    Nearest    = (Position - foxes[i].Position).Length();
                    curNearest = foxes[i].Position;
                }
            }
            if (usingI >= 0)
            {
                Nearest = float.MaxValue;
                foxes.RemoveAt(usingI);
                nearestPos.Add(curNearest);

                usingI = -1;
                if (foxes.Count > 0)
                {
                    for (int i = 0; i < foxes.Count; i++)
                    {
                        if ((Position - foxes[i].Position).Length() < Nearest)
                        {
                            usingI     = i;
                            Nearest    = (Position - foxes[i].Position).Length();
                            curNearest = foxes[i].Position;
                        }
                    }
                    if (usingI >= 0)
                    {
                        Nearest = float.MaxValue;
                        foxes.RemoveAt(usingI);
                        nearestPos.Add(curNearest);

                        usingI = -1;
                        if (foxes.Count > 0)
                        {
                            for (int i = 0; i < foxes.Count; i++)
                            {
                                if ((Position - foxes[i].Position).Length() < Nearest)
                                {
                                    usingI     = i;
                                    Nearest    = (Position - foxes[i].Position).Length();
                                    curNearest = foxes[i].Position;
                                }
                            }
                            if (usingI >= 0)
                            {
                                foxes.RemoveAt(usingI);
                                nearestPos.Add(curNearest);
                            }
                        }
                    }
                }
            }
            AudioQueue.PlayOnce("Sounds/Explode_Chicken");
            Deactivate();
            Vector2 bodypos = Body.Position;

            Body.PosX = -10000;
            for (int i = 0; i < nearestPos.Count; i++)
            {
                Chicken_Mini e = new Chicken_Mini(scene);
                e.Position = bodypos;
                e.Initialize(Jabber.BaseGame.Get.Content);
                scene.AddNode(e);

                Vector2 dir = (nearestPos[i] - bodypos);
                dir.Normalize();

                float dist = (nearestPos[i] - bodypos).Length();

                float ydif = Math.Abs(bodypos.Y - nearestPos[i].Y);
                float xdif = Math.Abs(bodypos.X - nearestPos[i].X);
                float curY = bodypos.Y;
                float tarX = nearestPos[i].X;

                float horizontalSpeed = (dir * dist * 0.01f).X;

                /*
                 * FarWorld f = new FarWorld();
                 * f.Initialize(World.Gravity);
                 * JabActor circle = f.CreateSphere(Width / 2.0f, bodypos, JabActor.BodyType.DYNAMIC);
                 * circle.Mass = Body.Mass;
                 * circle.Restitution = Body.Restitution;
                 * circle.LinearDamping = 0.5f;
                 * circle.LinearVelocity = new Vector2(horizontalSpeed, 0);
                 *
                 * float lastDist = float.MaxValue;
                 * float lastY = 0;
                 * while (true)
                 * {
                 *  f.Update(new GameTime(new TimeSpan(0, 0, 0, 0, 33), new TimeSpan(0, 0, 0, 0, 33)));
                 *  float curDist = Math.Abs(circle.PosX - tarX);
                 *  if (lastDist < curDist)
                 *  {
                 *      break;
                 *  }
                 *  lastY = circle.PosY;
                 *  lastDist = curDist;
                 * }
                 *
                 * float yAtDest = circle.PosY;
                 * float tarY = nearestPos[i].Y;
                 *
                 * float upWardRequired = (yAtDest - tarY) / 100.0f;
                 */
                e.Body.LinearVelocity = dir * 20;// *0.03f;// new Vector2(horizontalSpeed, horizontalSpeed);
                e.vectorDir           = dir * 20.0f;
            }
        }
        public override void OnPress(Vector2 pos)
        {
            base.OnPress(pos);

            if (active)
            {
                active = false;
                Body.IgnoreRayCast = true;
                /*
                int angleIterations = 32;
                for (int j = 0; j <= angleIterations; j++)
                {
                    float part = (float)j / (float)angleIterations * 2.0f * (float)Math.PI;

                    Vector2 dir = new Vector2((float)Math.Cos((float)part), (float)Math.Sin((float)part));
                    dir.Normalize();

                    RayCastHit hit = World.RayCast(Position, Position + dir * 1000);
                    if (hit.actor != null)
                    {
                        float totalDistProportion = hit.Distance / 1000.0f;
                        hit.actor.AddLinearImpulse(dir * 10 * totalDistProportion, hit.worldImpact);
                    }
                }*/

                Explosion exp = new Explosion(10, 300, 1.0f, 1.5f, scene.World, Position);
                Body.IgnoreRayCast = true;
                exp.Initialize(Jabber.BaseGame.Get.Content);
                scene.AddNode(exp);
                RaiseFlag(Jabber.Flags.DELETE);
                Body.IgnoreRayCast = false;

                AudioQueue.PlayOnce("Sounds/Explosion");
            }
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (Body.LinearVelocity.Length() + Math.Abs(Body.AngularVelocity) < 0.00001f || !active)
            {
                idleTimer += gttf(gameTime);
                if (idleTimer > 0.1f)
                {
                    Explosion exp = new Explosion(10, 300, 1.0f, 1.0f, scene.World, Position);
                    Body.IgnoreRayCast = true;
                    exp.Initialize(Jabber.BaseGame.Get.Content);
                    scene.AddNode(exp);
                    RaiseFlag(Jabber.Flags.DELETE);
                    Body.IgnoreRayCast = false;

                    AudioQueue.PlayOnce("Sounds/Explosion");
                }
            }
        }