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; } } }
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)); } } }
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; } }
public void EndContact(Collision col) { if (col.HasActor(Body) != null) { JabActor other = col.HasActor(Body); if (IsSliding) { IsSliding = false; AudioQueue.PlaySlide(false); } } }
public override void UnloadContent() { base.UnloadContent(); launchInst.RaiseFlag(Flags.DELETE); World.BeginContact -= OnContact; World.EndContact -= EndContact; if (IsSliding) { IsSliding = false; AudioQueue.PlaySlide(false); } }
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) { } } } } }
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"); }
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; } } }
void OnFrameChange(int prevFrame, int curFrame) { if (curFrame == 0 && Animation == "Fire") { EventManager.Get.SendEvent(new CannonFireEvent(Position, FireDir)); Animation = "Barrel"; smoke.Animation = "Smoke"; smoke.LowerFlag(Jabber.Flags.PASSRENDER); Vector2 dir = FireDir; dir.Normalize(); smoke.Position = Position + dir * Width / 2.0f; smoke.Rot = Rot; AudioQueue.PlayOnce("Sounds/Cannon_Fire_1");// + Jabber.BaseGame.Random.Next(1, 3)); } }
public static void PlaySFXBreakForMaterial(BodyMaterial material) { switch (material) { case BodyMaterial.WOOD: AudioQueue.PlayOnce("Sounds/Break_Wood_01"); // + BaseGame.Random.Next(1, 3)); break; case BodyMaterial.GLASS: AudioQueue.PlayOnce("Sounds/Break_Glass_01"); break; case BodyMaterial.CONCRETE: AudioQueue.PlayOnce("Sounds/Break_Concrete_01"); break; } }
public override void OnPress(Vector2 pos) { base.OnPress(pos); if (active) { active = false; Egg e = new Egg(Position, scene); e.Initialize(Jabber.BaseGame.Get.Content); scene.AddNode(e); Body.AddLinearImpulse(new Vector2(0, 13)); AudioQueue.PlayOnce("Sounds/EggLay"); Deactivate(); } }
public static void PlayHitSFXForMaterial(BodyMaterial material) { switch (material) { case BodyMaterial.WOOD: AudioQueue.PlayOnce("Sounds/Hit_Wood_0" + BaseGame.Random.Next(1, 3)); break; case BodyMaterial.GLASS: AudioQueue.PlayOnce("Sounds/Hit_Glass_0" + BaseGame.Random.Next(1, 3)); break; case BodyMaterial.CONCRETE: AudioQueue.PlayOnce("Sounds/Hit_Concrete_0" + BaseGame.Random.Next(1, 5)); break; } }
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"); } } }
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; } } }
public override void OnPress(Vector2 pos) { base.OnPress(pos); if (active) { active = false; Vector2 tarpos = Camera.Get.ScreenToWorld(pos); Vector2 dir = tarpos - Body.Position; dir.Normalize(); float velocity = Body.LinearVelocity.Length(); dir *= velocity * 1.5f; if (dir.Length() < 20) { dir.Normalize(); dir *= 20.0f; } Body.LinearVelocity = dir; /* * if (dir.Length() < 25) * { * dir.Normalize(); * Body.LinearVelocity = dir * 25; * }*/ AccelerateAnimation = "Accelerate_Flap"; AudioQueue.PlayOnce("Sounds/FeatherFall"); accelerate = true; } }
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 (CheckFlag(Flags.FADE_OUT)) { float a = Colour.A / 255.0f; float d = JabMath.MoveTowards(a, 0.0f, gttf(gameTime) * 2.0f, 0.001f); Colour = Color.White * d; if (d == 0) { RaiseFlag(Flags.DELETE); } return; } if (PosX > world.GetRightMaxPos() + 1000 || PosX < world.startPos.X - 1000) { Rot = 0.5f * JabMath.PI; } if (Math.Abs(Rot) > 0.45f * JabMath.PI) { deathTimer += gttf(gameTime) * 5.0f; while (deathTimer > 1.0f && numDonutsMade < 5) { deathTimer -= 1.0f; Donut d = new Donut(world); AudioQueue.PlayOnce("Sounds/pop"); d.Initialize(BaseGame.Get.Content); d.Position = Position + new Vector2(RandomFloatInRange(-0.5f, 0.5f) * Width, RandomFloatInRange(-0.5f, 0.5f) * Height); d.Chosen = true; world.AddNode(d); deathTimer -= 1.0f; ++numDonutsMade; float oldWidth = Body.Width; float oldHeight = Body.Height; Vector2 oldPos = Body.Position; float oldRot = Body.Rot; oldWidth *= 0.9f; oldHeight *= 0.9f; Vector2 linearVelocity = Body.LinearVelocity; float angularVelocity = Body.AngularVelocity; Body.RaiseFlag(Flags.DELETE); Body.CollisionGroup = Donut.DonutCollisionGroup; Body = world.World.CreateBox(new Vector2(oldWidth, oldHeight), oldPos, JabActor.BodyType.DYNAMIC); Body.Rot = oldRot; Body.LinearVelocity = linearVelocity; Body.AngularVelocity = angularVelocity; //Sprite.Width = oldWidth; //Sprite.Height = oldHeight; } if (numDonutsMade > 4) { RaiseFlag(Flags.DELETE); } //Colour = Color.White * ((5.0f - numDonutsMade) / 5.0f); } Sprite.Width = JabMath.MoveTowards(Sprite.Width, Body.Width, gttf(gameTime) * 1.0f); Sprite.Height = JabMath.MoveTowards(Sprite.Height, Body.Height, gttf(gameTime) * 1.0f); // Body.LinearDamping = 0.15f; // Body.AngularDamping = 0.3f; }
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; } } } }
public override void Update(GameTime gameTime) { if (!hasCollidedOnce) { featherTrail.Add(CreateFeather()); } if (Body.LinearVelocity.Length() < 0.5f && IsSliding) { IsSliding = false; AudioQueue.PlaySlide(false); } if (Body.LinearVelocity.Length() < 0.5f) { AsType.CurrentAnim.Speed = 0; } else { AsType.CurrentAnim.Speed = 20; } hitTimer -= gttf(gameTime); if (launchInst.Volume != 1.0f) { launchInst.Volume = JabMath.MoveTowards(launchInst.Volume, 0.0f, gttf(gameTime) * 5.0f); } if (hasHitContact) { targetDamping = 1.5f; hasHitContact = true; if (Body.PosX > scene.GetRightMaxPos() + 5000 || Body.PosY < -10 || Body.PosX < scene.startPos.X - 5000) { RaiseFlag(Jabber.Flags.DELETE); } //if (Body.LinearVelocity.Length() > 4.0f) { //Vector2 vel = Body.LinearVelocity; //vel.Normalize(); //vel *= 4.0f; //Body.LinearVelocity = vel; } } //Body.LinearDamping = JabMath.MoveTowards(Body.LinearDamping, targetDamping, gttf(gameTime) * 50, 0.03f); base.Update(gameTime); //Body.Restitution = oldRestitution; if (Body.LinearVelocity.Length() > 0.5f) { AsType.Animation = AccelerateAnimation; Vector2 dir = Body.LinearVelocity; dir.Normalize(); AsType.Rot = (float)Math.Atan2((float)dir.X, (float)dir.Y); /* * if (firstUpdate) * AsType.Rot = (float)Math.Atan2((float)dir.X, (float)dir.Y); * else * AsType.Rot = JabMath.MoveTowards(Rot, (float)Math.Atan2((float)dir.X, (float)dir.Y), gttf(gameTime) * 3.0f);*/ } else { AsType.Rot = Body.Rot;// JabMath.MoveTowards(Rot, 0, gttf(gameTime) * 3.0f); } // Check to see if chicken should be made to be in-active (if it is currently active).. if (active) { if (Body.LinearVelocity.Length() <= 0.00001f) { zeroTimer += gttf(gameTime); if (zeroTimer > 1) { active = false; } } else { zeroTimer = 0; } } firstUpdate = false; }
public override void Update(GameTime gameTime) { if (invincibilityTime < maxTime) { invincibilityTime += gttf(gameTime); Body.Awake = true; return; } else { invincibilityTime += gttf(gameTime); } if (screen == null) { for (int i = 0; i < ScreenManager.Get.Screens.Count; i++) { if (ScreenManager.Get.Screens[i] is GameplayScreen) { screen = ScreenManager.Get.Screens[i] as GameplayScreen; } } } if (health > 0) { if (ThingStandingOnIsMoving && IsBox) { // SwitchActiveBody(); } if ((Body.LinearVelocity.Length() + Math.Abs(Body.AngularVelocity) >= 0.5f && IsBox) || (!StandingOnSomething && IsBox)) { SwitchActiveBody(); if (AsType.Animation != "Roll") { AsType.Animation = "Roll"; } } else if ((!IsBox && Body.LinearVelocity.Length() + Math.Abs(Body.AngularVelocity) < 0.5f) && StandingOnSomething && !ThingStandingOnIsMoving) { SwitchActiveBody(); if (AsType.Animation != "Idle" && chicksScene.ActiveChicken == null) { AsType.Animation = "Idle"; } else { Chicken active = chicksScene.ActiveChicken; AsType.Animation = ""; AsType.CurrentFrame = "fox-watch-00010"; } } if (AsType.Animation == "Idle" && CarryingSomething) { AsType.Animation = "Carrying"; } else if (AsType.Animation == "Carrying" && !CarryingSomething) { AsType.Animation = "Idle"; } if ((AsType.Animation == "Idle" || AsType.Animation == "") && chicksScene.ActiveMotion != null) { Chicken active = chicksScene.ActiveMotion; AsType.Animation = ""; Vector2 dirToChicken = active.Position - AsType.Position; dirToChicken.Normalize(); float rotToChicken = (float)Math.Atan2((float)-dirToChicken.X, (float)-dirToChicken.Y); rotToChicken -= 0.5f * (float)Math.PI + AsType.Rot; while (rotToChicken < 0) { rotToChicken += 2 * (float)Math.PI; } while (rotToChicken > 2 * (float)Math.PI) { rotToChicken -= 2 * (float)Math.PI; } rotToChicken /= 2 * (float)Math.PI; int num = (int)(rotToChicken * 11); if (num.ToString().Length == 2) { AsType.CurrentFrame = "fox-watch-000" + num.ToString(); } else { AsType.CurrentFrame = "fox-watch-0000" + num.ToString(); } } else if (AsType.Animation == "") { AsType.Animation = "Idle"; } if (health > 0) { if (PosX > screen.scene.GetRightMaxPos() + 1000 || PosX < screen.scene.startPos.X - 1000 || PosY < -10 || PosY > 10000) { health = -1; } if (!(ScreenManager.Get.TopScreen is PauseScreen) && ScreenManager.Get.TopScreen != screen) { if (AsType.Animation != "Celebrate" && AsType.Animation != "Roll" && AsType.Animation != "Carrying") { AsType.Animation = "Celebrate"; } } else if (AsType.Animation == "Celebrate") { AsType.Animation = "Idle"; } } SetPos(); } else { if (AsType.Animation == "Roll") { SetPos(); if (Body.LinearVelocity.Length() < 0.3f && StandingOnSomething) { if (AsType.Animation != "Die") { AudioQueue.PlayOnce("Sounds/Fox_Death_2" + Jabber.BaseGame.Random.Next(0, 3)); } AsType.Animation = "Die"; } else if (Body.LinearVelocity.Length() < 0.3f || InFan) { deadWhileInRollButStillTimer += gttf(gameTime); if (deadWhileInRollButStillTimer > 1.0f) { if (AsType.Animation != "Die") { AudioQueue.PlayOnce("Sounds/Fox_Death_2" + Jabber.BaseGame.Random.Next(0, 3)); } AsType.Animation = "Die"; } } else { deadWhileInRollButStillTimer = 0.0f; } } else if (AsType.Animation != "Die" && AsType.Animation != "Corpse") { if (AsType.Animation != "Die") { AudioQueue.PlayOnce("Sounds/Fox_Death_2" + Jabber.BaseGame.Random.Next(0, 3)); } AsType.Animation = "Die"; Body.CollisionGroup = FOX_NONE_COLLISION_GROUP; Body.IgnoreRayCast = true; PhysicsPosition = false; PhysicsRotate = false; } else if (AsType.Animation == "Die" || AsType.Animation == "Corpse") { Body.CollisionGroup = FOX_NONE_COLLISION_GROUP; Body.IgnoreRayCast = true; PhysicsPosition = false; PhysicsRotate = false; RayCastHit hit = World.RayCast(AsType.Position, AsType.Position + new Vector2(0, -(AsType.Height / 1.4f))); if (hit.actor != null) { if (true)//AsType.PosY - (hit.worldImpact.Y + AsType.Height / 2.0f) > 0) todo: fix { AsType.PosY = hit.worldImpact.Y + AsType.Height / 2.0f; AsType.Rot = (float)Math.Atan2((float)hit.worldNormal.X, (float)hit.worldNormal.Y); deathFallTimer = 0; } if (AsType.Animation == "Corpse") { alphaOutTimer += gttf(gameTime); } if (alphaOutTimer > 1.0f) { alphaingOut += gttf(gameTime); float val = 1.0f - alphaingOut; if (alphaingOut > 1) { RaiseFlag(Jabber.Flags.DELETE); } else { Colour = new Color(val, val, val, val); } } } else { alphaOutTimer = 0.0f; deathFallTimer += gttf(gameTime); AsType.PosY -= deathFallTimer * 9.8f; } Body.IgnoreRayCast = true; } } base.Update(gameTime); if (InFan) { Body.LinearDamping = 0.0f; } else if (InFanLastFrame) { Body.Friction = 0.5f; Body.AngularDamping = 0.5f; Body.LinearDamping = 0.5f; AsType.Animation = "Roll"; } InFanLastFrame = InFan; InFan = false; if (AsType.Animation == "Roll" || AsType.Animation == "Die" || AsType.Animation == "Corpse") { if (WearHat && invincibilityTime > maxTime * 2.0f) { ThrownHat hat = new ThrownHat(LocationToHat); hat.Initialize(Jabber.BaseGame.Get.Content); hat.Position = Body.Position + ActorStandingOn.worldNormal * 64; hat.Rot = Rot; chicksScene.AddNode(hat); WearHat = false; } } }
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; } }