Пример #1
0
 public void OnContact(Collision col)
 {
     if (col.HasActor(Body) != null)
     {
         Body.LinearDamping = 0.5f;
         JabActor other = col.HasActor(Body);
         if (!(other.UserData is Chicken) && !World.IsEntityGroup(other.CollisionGroup))
         {
             hasCollidedOnce = true;
         }
         if (other.Friction <= 0.005f)
         {
             Body.Restitution = 0.0f;
             if (Body.LinearVelocity.Length() > 0.5f && !IsSliding)
             {
                 AudioQueue.PlaySlide(true);
                 IsSliding = true;
             }
             else if (IsSliding)
             {
                 IsSliding = false;
                 AudioQueue.PlaySlide(false);
             }
         }
         else
         {
             if (IsSliding)
             {
                 IsSliding = false;
                 AudioQueue.PlaySlide(false);
             }
             Body.Restitution = 0.5f;
         }
     }
 }
Пример #2
0
        public override void ProcessEvent(Event ev)
        {
            base.ProcessEvent(ev);

            if (ev is CollisionEvent)
            {
                JabActor other = (ev as CollisionEvent).ActorPresent(Body);
                if (other != null)
                {
                    if (!other.CheckFlag(Jabber.Flags.DELETE))
                    {
                        if ((ev as CollisionEvent).ActorPresent(Body) != null && other.CollisionGroup != Fox.FOX_NONE_COLLISION_GROUP && other.CollisionGroup != Fan.FanEntitySpaceGroup && !World.IsEntityGroup(Body.CollisionGroup) &&
                            other.CollisionGroup != Donut.DonutCollisionGroup && other.Friction > 0.005f && !(other.UserData is Chicken))
                        {
                            if (destructionTimer < 0)
                            {
                                destructionTimer = 1.0f;
                            }
                        }
                    }
                }
                if (other != null)
                {
                    Body.LinearDamping = 0.3f;
                    AudioQueue.PlayOnce("Sounds/Hit_Egg_0" + Jabber.BaseGame.Random.Next(1, 3));
                }
            }
        }
Пример #3
0
        public override void ProcessEvent(Event ev)
        {
            base.ProcessEvent(ev);

            if (ev is CollisionEvent)
            {
                CollisionEvent e = ev as CollisionEvent;
                if (e.ActorPresent(box) != null)
                {
                    if (e.ActorPresent(box).UserData is Chicken || e.ActorPresent(box).UserData is Fox || (e.ActorPresent(box).BodyState == JabActor.BodyType.DYNAMIC))
                    {
                        JabActor actor = e.ActorPresent(box);

                        float dist = (actor.Position - Position).Length();

                        float maxdist = (float)Math.Sqrt((float)(Height * Height + Width * Width));
                        float prop    = dist / maxdist;
                        prop = 1.0f - prop;
                        if (prop <= 0)
                        {
                        }
                        else
                        {
                            actor.AddForce((prop * Direction * 100.0f));
                        }
                        if (actor.UserData is Chicken)
                        {
                            int k = 0;
                        }
                    }
                }
            }
        }
Пример #4
0
        void OnContact(Collision col)
        {
            JabActor other = col.HasActor(Body);

            if (other != null && !World.IsEntityGroup(other.CollisionGroup))
            {
                if ((other.LinearVelocity - Body.LinearVelocity).Length() + Math.Abs(Body.AngularVelocity - other.AngularVelocity) > 2.5f)
                {
                    Detonate();
                }
            }
        }
Пример #5
0
 public void EndContact(Collision col)
 {
     if (col.HasActor(Body) != null)
     {
         JabActor other = col.HasActor(Body);
         if (IsSliding)
         {
             IsSliding = false;
             AudioQueue.PlaySlide(false);
         }
     }
 }
Пример #6
0
 public override void ProcessEvent(Event ev)
 {
     if (ev is CollisionEvent)
     {
         JabActor other = (ev as CollisionEvent).ActorPresent(Body);
         if (other != null && !(other.UserData is Chicken))
         {
             hasHit = true;
             Body.CollisionGroup  = 0;
             Body.AngularVelocity = RandomFloatInRange(-6.0f, 6.0f);
         }
     }
 }
Пример #7
0
        public override void ProcessEvent(Event ev)
        {
            base.ProcessEvent(ev);

            if (ev is CollisionEvent)
            {
                if ((ev as CollisionEvent).ActorPresent(Body) != null)
                {
                    if (!World.IsEntityGroup((ev as CollisionEvent).ActorPresent(Body).CollisionGroup))
                    {
                        if ((ev as CollisionEvent).contactType == CollisionEvent.ContactType.ONCONTACT)
                        {
                            ++numContacts;
                        }
                        else
                        {
                            --numContacts;
                        }
                    }
                    JabActor other = (ev as CollisionEvent).ActorPresent(Body);

                    if (launchInst.Volume == 1.0f && !World.IsEntityGroup(other.CollisionGroup))
                    {
                        launchInst.Volume = 0.99999f;
                    }
                    if ((Body.LinearVelocity - other.LinearVelocity).Length() > 2.0f && !World.IsEntityGroup(other.CollisionGroup))
                    {
                        if (hitTimer < 0.0f && other.BodyState == JabActor.BodyType.STATIC)
                        {
                            AudioQueue.PlayOnce("Sounds/Hit_Chicken_" + BaseGame.Random.Next(2, 5));
                            hitTimer = 0.1f;
                        }
                    }

                    if (numContacts > 1)
                    {
                        targetDamping = 4.5f;
                    }
                    else
                    {
                        targetDamping = 1.5f;
                        hasHitContact = true;
                        if (Body.LinearVelocity.Length() > 5.0f)
                        {
                        }
                    }
                }
            }
        }
Пример #8
0
        public void LoadBreakableBody(XElement elements)
        {
            List <Sprite>   sprites = CreateSprites(elements);
            List <JabActor> bodies  = new List <JabActor>();

            for (int i = 0; i < sprites.Count; i++)
            {
                sprites[i].Width  = 20;
                sprites[i].Height = 100;

                JabActor act = World.CreateBox(sprites[i].Dimension * sprites[i].Scale, sprites[i].Position, JabActor.BodyType.DYNAMIC);
                act.Rot = sprites[i].Rot;
                bodies.Add(act);
            }
            // LoadBreakableBodies(elements);



            for (int i = 0; i < sprites.Count; i++)
            {
                string        name = (sprites[i]).CurrentFrame;
                BreakableBody s    = null;

                if (name == "wood")
                {
                    s = new BreakableBody(BreakableBody.BodyMaterial.WOOD, this);
                }
                else if (name == "cement")
                {
                    s = new BreakableBody(BreakableBody.BodyMaterial.CONCRETE, this);
                }
                else if (name == "glass")
                {
                    s = new BreakableBody(BreakableBody.BodyMaterial.GLASS, this);
                }



                s.World  = World;
                s.Body   = bodies[i];
                s.Sprite = sprites[i];
                s.Initialize(Content);

                AddNode(s);
            }
        }
Пример #9
0
        public PhysicSprite(float radius, Vector2 pos, bool dynamic, JabWorld world, string imagedir)
            : base()
        {
            TextureDir = imagedir;
            Width      = radius;
            Height     = radius;
            JabActor.BodyType type = JabActor.BodyType.DYNAMIC;
            if (!dynamic)
            {
                type = JabActor.BodyType.STATIC;
            }
            body          = world.CreateSphere(radius / 2.0f, pos, type);
            body.UserData = this;
            this.world    = world;

            // Initialize();
        }
Пример #10
0
        public override void ProcessEvent(Event ev)
        {
            //base.ProcessEvent(ev);

            if (ev is CollisionEvent)
            {
                JabActor other = (ev as CollisionEvent).ActorPresent(Body);
                if (other != null)
                {
                    if ((Body.LinearVelocity - other.LinearVelocity).Length() > 3.0f)
                    {
                        AudioQueue.PlayOnce("Sounds/Hit_Egg_01");
                    }
                    //hasCollided = true;
                }
            }
        }
Пример #11
0
        void AfterContact(Collision col)
        {
            JabActor other = col.HasActor(Body);

            if (other != null && health > 0)
            {
                Vector2 relativeForce = other.LinearVelocity * other.Mass - Body.LinearVelocity * Body.Mass;

                if (health <= 0)
                {
                }
                else if (other.UserData is Chicken && health > 0)
                {
                    (other.UserData as Chicken).AfterBreakableHit(this);
                }
            }
        }
Пример #12
0
 public PhysicSprite(Vector2 dim, Vector2 pos, bool dynamic, JabWorld world, string imagedir)
     : base()
 {
     TextureDir = imagedir;
     Width      = dim.X;
     Height     = dim.Y;
     JabActor.BodyType type = JabActor.BodyType.DYNAMIC;
     if (!dynamic)
     {
         type = JabActor.BodyType.STATIC;
     }
     body          = world.CreateBox(dim, pos, type);
     body.UserData = this;
     this.world    = world;
     DoDimensions  = true;
     DoHandle      = true;
 }
Пример #13
0
        void UpdateTrajectory()
        {
            if (currentFireDir == LastDir)
            {
                return;
            }

            LastDir = currentFireDir;
            trajectorypositions.Clear();

            if (currentFireDir.Length() > 0)
            {
                JabActor circle = projectileWorld.CreateSphere(75, Position, JabActor.BodyType.DYNAMIC);
                circle.LinearVelocity = (currentFireDir);

                Vector2 LastPos = Vector2.Zero;
                for (int i = 0; i < 200; i++)
                {
                    if (i > 0 && i % 4 == 0)
                    {
                        RayCastHit hit = screen.withChicks.World.RayCast(LastPos, circle.Position);
                        if (hit.actor != null)
                        {
                            trajectorypositions.Add(hit.worldImpact);
                            break;
                        }
                    }
                    if (circle.PosY < 0)
                    {
                        break;
                    }
                    if (i % 4 == 0)
                    {
                        trajectorypositions.Add(circle.Position);
                        LastPos = circle.Position;
                    }

                    projectileWorld.Update(new GameTime(new TimeSpan(0, 0, 0, 0, 33), new TimeSpan(0, 0, 0, 0, 33)));
                }
                circle.RaiseFlag(Jabber.Flags.DELETE);
            }
        }
Пример #14
0
        public override void ProcessEvent(Event ev)
        {
            base.ProcessEvent(ev);

            if (ev is CollisionEvent)
            {
                JabActor other = (ev as CollisionEvent).ActorPresent(box);
                if (other != null && (other.UserData is Chicken || other.UserData is Fox))
                {
                    if (!Chosen)
                    {
                        AudioQueue.PlayOnce("Sounds/pop");
                    }
                    Chosen = true;
                }
                if (other != null && other.UserData is Fan)
                {
                    InFan = true;
                }
            }
        }
Пример #15
0
        void OnContact(Collision col)
        {
            JabActor other = col.HasActor(Body);

            if (other != null && health > 0 && !World.IsEntityGroup(other.CollisionGroup))
            {
                Vector2 relativeForce = other.LinearVelocity * other.Mass - Body.LinearVelocity * Body.Mass;

                if (other.UserData is BreakableBody) // || other.UserData is Fox)
                {
                    relativeForce /= 30.0f;          //reduced once because of uluru 9, concrete falling on glass failed to break it
                }
                else if (other.UserData is Fox)
                {
                    relativeForce /= 10.0f;
                }
                else
                {
                    relativeForce /= 6.0f;
                }
                if (relativeForce.Length() > 0.1f)
                {
                    health -= relativeForce.Length();
                    Event e = new BreakableHit(material);
                    e.Position = Body.Position;
                    EventManager.Get.SendEvent(e);
                    PlayHitSFXForMaterial(material);
                }
                if (health <= 0)
                {
                    Event e = new BreakableDestroyed(material);
                    e.Position = Body.Position;
                    EventManager.Get.SendEvent(e);
                    PlaySFXBreakForMaterial(material);
                    health = 0;
                    if (!SplintersCreated)
                    {
                        CreateSplinters();
                        SplintersCreated = true;
                    }
                    if (other.UserData is Chicken)
                    {
                        (other.UserData as Chicken).OnBreakableDestroyed(this);
                    }
                    else if (other.UserData is Fox)
                    {
                        other.LinearVelocity *= 0.5f;
                    }

                    RaiseFlag(Jabber.Flags.DELETE);
                    Body.CollisionGroup = BodyNoneCollisionGroup;
                    Body.IgnoreRayCast  = true;
                }
                else if (other.UserData is Chicken && health > 0)
                {
                    (other.UserData as Chicken).OnBreakableHit(this);
                }
            }
            else if (other != null && World.IsEntityGroup(other.CollisionGroup) && other.UserData is Fan)
            {
                if (other.Rot == 0.0f)
                {
                    InFan = true;
                }
                else
                {
                    InBentFan = true;
                }
            }
        }
Пример #16
0
        public void Load3DShapes(XElement elements)
        {
            var items   = elements.Descendants("Items");
            var element = elements.Descendants("CustomProperties").Descendants("Property");

            float  tileSize    = 0;
            float  layerDepth  = 0;
            float  friction    = 10.2f;
            string tileTexture = "";

            foreach (var property in element)
            {
                if (property.Attribute("Name") != null)
                {
                    string name = property.Attribute("Name").Value;
                    if (name == "TileSize")
                    {
                        tileSize = float.Parse(property.Attribute("Description").Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Texture")
                    {
                        tileTexture = property.Attribute("Description").Value;
                    }
                    else if (name == "LayerDepth")
                    {
                        if (property.Descendants("string").First <XElement>().Value == "")
                        {
                            layerDepth = 0.0000002f;
                        }
                        else
                        {
                            layerDepth = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);

                            if (layerDepth == 2)
                            {
                                layerDepth = 0.0000002f;
                            }
                        }
                    }
                    else if (name == "Friction")
                    {
                        friction = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                }
            }
            layerDepth = 0.0000002f;

            PhysicShape shape = new PhysicShape(world, JabActor.BodyType.STATIC);

            shape.TextureDir = tileTexture;
            shape.TileSize   = 256;// tileSize * 50.0f;
            shape.Initialize(Content);
            foreach (var item in items)
            {
                var parts = item.Descendants("Item");

                foreach (var part in parts)
                {
                    if (part.Name == "Item")
                    {
                        element = part.Descendants("Position");
                        float posx = float.Parse(element.Elements("X").ElementAt(0).Value, CultureInfo.InvariantCulture);
                        float posy = float.Parse(element.Elements("Y").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        //element = part.Descendants("Rotation");
                        float rot = -float.Parse(part.Elements("Rotation").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        element = part.Descendants("Scale");
                        float width  = (float)double.Parse(element.Elements("X").ElementAt(0).Value, CultureInfo.InvariantCulture);
                        float height = float.Parse(element.Elements("Y").ElementAt(0).Value, CultureInfo.InvariantCulture);

                        JabActor box = world.CreateBox(new Vector2(width, height), new Vector2(posx, -posy), JabActor.BodyType.STATIC);
                        box.Friction = friction;
                        box.Rot      = -rot;
                        shape.AddRectangle(new Vector3(posx, -posy, 0), new Vector2(width, height), rot);
                    }
                }
            }
            shape.Layer = BaseSprite.SpriteLayer.LAYER9;
            shape.FinalizeVertices();
            shape.PosZ = layerDepth;
            AddNode(shape);

            //shape.Friction = friction;
        }
Пример #17
0
        public override void ProcessEvent(Event ev)
        {
            if (invincibilityTime < maxTime)
            {
                if (ev is CollisionEvent)
                {
                    CollisionEvent e = ev as CollisionEvent;

                    {
                        if (e.ActorPresent(Body) != null)
                        {
                            if (e.ActorPresent(Body).UserData is Fan)
                            {
                                InFan = true;
                            }
                        }
                    }
                }
                return;
            }
            base.ProcessEvent(ev);

            if (ev is CollisionEvent)
            {
                CollisionEvent e = ev as CollisionEvent;

                if (e.ActorPresent(Body) != null && !World.IsEntityGroup(e.ActorPresent(Body).CollisionGroup))
                {
                    JabActor other = e.ActorPresent(Body);

                    Vector2 relHit   = other.LinearVelocity - Body.LinearVelocity;
                    float   speedHit = (relHit).Length();

                    if (other.UserData is PhysicSprite)
                    {
                        if (((other.UserData as PhysicSprite).Sprite as Sprite).CurrentFrame.Contains("cow"))
                        {
                            if (Math.Abs(Body.AngularVelocity) < 0.5f)
                            {
                                AudioQueue.PlayOnce("Sounds/Hit_Chicken_1");
                            }

                            if (health <= 0)
                            {
                                if (++NumTimesOnCowJumpAfterHealthHitZero > 5)
                                {
                                    if (AsType.Animation != "Die")
                                    {
                                        AudioQueue.PlayOnce("Sounds/Fox_Death_2" + Jabber.BaseGame.Random.Next(0, 3));
                                    }
                                    AsType.Animation = "Die";
                                }
                            }
                            return;
                        }
                    }
                    if (speedHit > 1.0f && other.Name != "cow")
                    {
                        health = -1;
                    }
                    else if (speedHit > 0.5f && other.UserData is Fox)
                    {
                        health = -1;
                    }

                    if (other.UserData is Chicken)
                    {
                        AudioQueue.PlayOnce("Sounds/punch_0" + Jabber.BaseGame.Random.Next(1, 5));
                    }
                    else if (speedHit > 1.0f && screen.screenCamera.IsVisible(this))
                    {
                        if (Math.Abs(Body.AngularVelocity) < 0.5f)
                        {
                            AudioQueue.PlayOnce("Sounds/Hit_Chicken_1");// + Jabber.BaseGame.Random.Next(1, 5));
                        }
                    }

                    if (speedHit > 0.25f)
                    {
                        /*  if (hitSound == null)
                         * {
                         *    //hitSound = AudioManager.CreateSound("Sounds/Hit_Chicken_1");
                         * }
                         * if (!hitSound.IsPlaying)
                         * {
                         *    if(other.UserData is Chicken || other.BodyState == JabActor.BodyType.STATIC)
                         *        hitSound.Play(0.2f);
                         * }*/
                        //AudioManager.PlayOnce("Sounds/Hit_Chicken_1");
                    }
                }
                else if (e.ActorPresent(Body) != null)
                {
                    if (e.ActorPresent(Body).UserData is Fan)
                    {
                        InFan = true;
                    }
                }
            }
        }
Пример #18
0
        public List <JabActor> CreateBodies(XElement elements)
        {
            List <JabActor> bodies  = new List <JabActor>();
            var             items   = elements.Descendants("Items");
            var             element = elements.Descendants("CustomProperties").Descendants("Property");

            float  layerDepth     = 0;
            float  mass           = 0.25f;
            string type           = "";
            float  friction       = 0.5f;
            float  density        = 15.0f;
            float  restitution    = 0;
            bool   dynamic        = true;
            float  angulardamping = 0;

            foreach (var property in element)
            {
                if (property.Attribute("Name") != null)
                {
                    string name = property.Attribute("Name").Value;
                    if (name == "LayerDepth")
                    {
                        layerDepth = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Mass")
                    {
                        mass = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Friction")
                    {
                        friction = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Type")
                    {
                        type = property.Descendants("string").First <XElement>().Value;
                    }
                    else if (name == "Density")
                    {
                        density = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Restitution")
                    {
                        restitution = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Dynamic")
                    {
                        dynamic = property.Descendants("string").First <XElement>().Value.ToLowerInvariant() == "true";
                    }
                    else if (name == "AngularDamping")
                    {
                        angulardamping = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                }
            }

            List <Sprite> baseSprites = CreateSprites(elements);

            for (int i = 0; i < baseSprites.Count; i++)
            {
                Sprite s    = baseSprites[i];
                float  posx = s.PosX;
                float  posy = s.PosY;

                float rot = s.Rot;

                float width  = s.ScaleX * s.Width;
                float height = s.ScaleY * s.Height;

                JabActor.BodyType bodyState = JabActor.BodyType.DYNAMIC;
                JabActor          actor     = null;
                if (!dynamic)
                {
                    bodyState = JabActor.BodyType.STATIC;
                }

                if (type == "Circle")
                {
                    actor = world.CreateSphere(width, new Vector2(posx, posy), bodyState);
                }
                else
                {
                    actor = world.CreateBox(new Vector2(width, height), new Vector2(posx, posy), bodyState);
                }

                actor.Friction       = friction;
                actor.Mass           = mass;
                actor.Restitution    = restitution;
                actor.Mass           = mass;
                actor.Rot            = rot;
                actor.Friction       = friction;
                actor.PosZ           = layerDepth;
                actor.Restitution    = restitution;
                actor.Density        = density;
                actor.AngularDamping = angulardamping;

                bodies.Add(actor);
            }

            return(bodies);
        }
Пример #19
0
 public override void UnloadContent()
 {
     body.RaiseFlag(Flags.DELETE);
     body = null;
     base.UnloadContent();
 }