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