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