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; } } } } }
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; } } } }