BaseSprite LoadDonutCase(BaseSprite sprite, string texturedir, XElement part) { DonutCase c = new DonutCase(this); c.Scale = sprite.Scale; c.Initialize(Content); c.Position = sprite.Position; if(sprite.Rot != 0) c.Rot = sprite.Rot; return c; }
void CheckEndGame(GameTime dt) { if (endGameTimeOut != 0) { int k = 0; } bool anyFox = false; for (int i = 0; i < scene.Nodes.Count; i++) { if (scene.Nodes[i] is Fox && (scene.Nodes[i] as Fox).IsAlive) { anyFox = true; break; } } if (!anyFox) { forceEndGame.Colour = Color.LightGreen; forceEndGame.RegularScale = ScaleFactor * 0.35f; forceEndGame.ScaleOnHover = ScaleFactor * 1.1f * 0.35f; } else if (scene.ToFire.Count == 0) { forceEndGame.Colour = Color.Red; forceEndGame.RegularScale = ScaleFactor * 0.35f; forceEndGame.ScaleOnHover = ScaleFactor * 1.1f * 0.35f; } bool anyMoving = false; bool onlyFoxMoving = false; bool foxAllMovingVertically = true; bool movingFoxesAreAllDead = true; bool onlyChickenMoving = true; List <Chicken> chicks = withChicks.GetChicks(); for (int i = 0; i < scene.Nodes.Count; i++) { if (scene.Nodes[i] is Fox) { Fox f = scene.Nodes[i] as Fox; if (f.Body.LinearVelocity.Length() > 0.0005f) { onlyFoxMoving = true; if (f.Body.LinearVelocity.X > 0.001f) { foxAllMovingVertically = false; } if (f.IsAlive) { movingFoxesAreAllDead = false; } } } } for (int i = 0; i < chicks.Count; i++) { if (chicks[i].Body.LinearVelocity.Length() > 0.1f && chicks[i].PosX > cannon.Position.X && chicks[i].PosX < rightMostPos + 100) { anyMoving = true; onlyFoxMoving = false; } } if (!anyMoving) { onlyChickenMoving = false; } if (!anyMoving) { for (int i = 0; i < scene.Nodes.Count; i++) { if (scene.Nodes[i] is PhysicSprite) { if ((scene.Nodes[i] as PhysicSprite).Body.LinearVelocity.Length() > 0.1f && scene.Nodes[i].PosX <rightMostPos + 100 && scene.Nodes[i].PosX> cannon.PosX && scene.Nodes[i].PosY > -100) { anyMoving = true; if (!(scene.Nodes[i] is Fox)) { onlyFoxMoving = false; } if (!(scene.Nodes[i] is Chicken)) { onlyChickenMoving = false; } } } } } if ((!anyMoving || (onlyFoxMoving && foxAllMovingVertically)) && scene.ToFire.Count == 0 && withChicks.ActiveChicken == null) { chickenStopMovingTimer += gttf(dt); if (chickenStopMovingTimer > 10.0f) { endGameTimeOut += gttf(dt); if (endGameTimeOut > 10) { ScreenFadeOut(); } HasWon = false; } } else if ((!anyMoving || onlyChickenMoving) && scene.ToFire.Count == 0 && withChicks.ActiveChicken == null) { chickenStopMovingTimer += gttf(dt); if (chickenStopMovingTimer > 10.0f) { endGameTimeOut += gttf(dt); if (endGameTimeOut > 10) { ScreenFadeOut(); } HasWon = true; } } else { chickenStopMovingTimer = 0; } bool AnyCheckedDonuts = false; for (int i = 0; i < scene.Nodes.Count; i++) { if (scene.Nodes[i] is Donut) { if ((scene.Nodes[i] as Donut).Chosen) { AnyCheckedDonuts = true; } AnyCheckedDonuts = true; } else if (scene.Nodes[i] is DonutCase) { DonutCase c = scene.Nodes[i] as DonutCase; if (Math.Abs(c.Rot) < 0.45f * JabMath.PI) { AnyCheckedDonuts = true; } AnyCheckedDonuts = true; } } if (onlyFoxMoving && foxAllMovingVertically && anyFox && scene.ToFire.Count == 0 && !movingFoxesAreAllDead) { if (AnyMovingAndNoFoxAndNoChicken == float.MinValue) { AnyMovingAndNoFoxAndNoChicken = 1.0f; } AnyMovingAndNoFoxAndNoChicken -= gttf(dt); if (AnyMovingAndNoFoxAndNoChicken < 0) { endGameTimeOut += gttf(dt); if (endGameTimeOut > 1) { ScreenFadeOut(); } if (!anyFox) { HasWon = true; } } } else if (!AnyCheckedDonuts && movingFoxesAreAllDead) { if (((scene.ToFire.Count == 0 && !anyMoving) || (!anyMoving && !anyFox)) && withChicks.ActiveChicken == null ) { endGameTimeOut += gttf(dt); if (endGameTimeOut > 3) { ScreenFadeOut(); } if (!anyFox) { HasWon = true; } } } else if (AnyCheckedDonuts && scene.ToFire.Count == 0 && !anyMoving) { endGameTimeOut += gttf(dt); if (endGameTimeOut > 1) { ScreenFadeOut(); } HasWon = false; } else if (!onlyFoxMoving && theFinalCountDown == 10 && theFinalCountDownWin == 10) { endGameTimeOut = 0.0f; } if (!anyFox && scene.ToFire.Count == 0 && withChicks.ActiveChicken == null) { theFinalCountDownWin -= gttf(dt); if (theFinalCountDownWin < 0) { endGameTimeOut += gttf(dt); if (endGameTimeOut > 10) { ScreenFadeOut(); } HasWon = true; } } if (anyMoving && !anyFox && !AnyCheckedDonuts && withChicks.ActiveChicken == null) { theFinalCountDown -= gttf(dt); if (theFinalCountDown < 0) { endGameTimeOut += gttf(dt); if (endGameTimeOut > 3) { ScreenFadeOut(); } HasWon = false; } } }