public override void Initialize(Microsoft.Xna.Framework.Content.ContentManager Content) { EventManager.Get.SendEvent(new ExplosionEvent()); base.Initialize(Content); CreateFramesFromXML("Chickens_Frames"); CurrentFrame = "bird-boom-00005"; ResetDimensions(); Width = Height = initialRadius;// JabMath.LinearInterpolate(initialRadius, maxRadius, Timer); UniformScale = 1.0f; Colour = new Color(1.0f, 1.0f, 1.0f, 0.0f); int angleIterations = 16; 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 * maxRadius); if (hit.actor != null && hit.Distance <= maxRadius && hit.actor.BodyState != JabActor.BodyType.STATIC) { float totalDistProportion = (maxRadius - hit.Distance) / maxRadius; if (hit.actor.UserData is Fox) { Fox f = hit.actor.UserData as Fox; if (f.IsBox) { f.SwitchActiveBody(); f.AnimSprite.Animation = "Roll"; } } hit.actor.AddLinearImpulse(dir * 15 * totalDistProportion, hit.worldImpact); if (hit.actor.UserData is BreakableBody) { (hit.actor.UserData as BreakableBody).TakeHit(totalDistProportion * 2.0f); } } } }
void LoadFoxie(XElement elements) { List <BaseSprite> l = CreateBaseSprites(elements); for (int i = 0; i < l.Count; i++) { try { Fox f = new Fox(screen, chicksScene, l[i].Position, l[i].Rot); f.Initialize(Content); f.WearHat = true; Nodes.Add(f); } catch (Exception e) { System.Windows.MessageBox.Show(e.ToString()); } } }
void LoadFoxie(XElement elements) { List<BaseSprite> l = CreateBaseSprites(elements); for (int i = 0; i < l.Count; i++) { try { Fox f = new Fox(screen, chicksScene, l[i].Position, l[i].Rot); f.Initialize(Content); f.WearHat = true; Nodes.Add(f); } catch(Exception e) { System.Windows.MessageBox.Show(e.ToString()); } } }
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; } }