public void Init() { //move arm into view timer = 90; x = 410; inhole = false; y1 = 900; y2 = 900; state = LevelState.INIT; dx = 0; foreach (Light l in lights) { l.Off(); } lights[activeHole - 1].On(); SoundCache.PlaySound("Pilot Are You Ready"); mainLoop.Play(); }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); //update all lights foreach (Light l in lights) { l.Update(gameTime); } //update all sounds mainLoop.Update(gameTime); //game state switch (state) { case LevelState.INIT: //move bar up until in start position y1 -= (float)gameTime.ElapsedGameTime.TotalMilliseconds / 30; y2 -= (float)gameTime.ElapsedGameTime.TotalMilliseconds / 30; if (y1 < 830) { y1 = 830; y2 = 830; StartGame(); } break; case LevelState.RESETTING: //move bar down to get new ball if (gameTime.TotalGameTime.TotalMilliseconds > lastRandomLight + 100) { if (randomLight != 0) { lights[randomLight - 1].Off(); } randomLight++; if (randomLight == 11) { randomLight = 1; } lights[randomLight - 1].On(); lastRandomLight = gameTime.TotalGameTime.TotalMilliseconds; } if (y1 < 900) { y1 += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 15; } if (y2 < 900) { y2 += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 15; } if (y1 >= 900 && y2 >= 900) { if (lives != 0) { Init(); } else { EndGame(); } } break; case LevelState.ENDING: endSequence -= gameTime.ElapsedGameTime.TotalMilliseconds; if (endSequence < 0) { StartAttractMode(); } break; case LevelState.ATTRACT: //update attract mode message if (gameTime.TotalGameTime.TotalMilliseconds > lastMsgUpdate + 200) { msgpos++; if (msgpos == msg.Length - 5) { msgpos = 0; } lastMsgUpdate = gameTime.TotalGameTime.TotalMilliseconds; } //update attract mode lights if (gameTime.TotalGameTime.TotalMilliseconds > lastRandomLight + 5) { //if (MediaPlayer.State == MediaState.Playing) /*{ * MediaPlayer.GetVisualizationData(data); * float total = 0; * for (int i = 0; i < 256; i++) * { * total += data.Samples[i]; * } * total = Math.Abs(total / 256)*40; * * if (total > 1.0f) total = 1.0f; * for(int i=0;i<10;i++) lights[i].Off(); * randomLight = (int)(total * 9) + 1; * for(int i=0;i<randomLight;i++) lights[i].On(); * }*/ lastRandomLight = gameTime.TotalGameTime.TotalMilliseconds; } break; case LevelState.PLAYING: //update timer if (gameTime.TotalGameTime.TotalMilliseconds > lastTimerUpdate + 1000) { timer--; if (timer == 0) { PlayerDie(); Reset(); } if (timer == 2) { SoundCache.PlaySound("Oxygen Depleted"); } if (timer == 30) { SoundCache.PlaySound("Oxygen Reserves Are Low"); } if (timer == 45) { SoundCache.PlaySound("Hurry Up Pilot"); } lastTimerUpdate = gameTime.TotalGameTime.TotalMilliseconds; } break; } //physics angle = (float)Math.Atan((y2 - y1) / 820); if (!inhole) { //max angle if (angle > 0.15f) { angle = 0.15f; } if (angle < -0.15f) { angle = -0.15f; } //max left and right maxx = (float)Math.Sqrt(Math.Pow(820.0f, 2) - Math.Pow(y1 - y2, 2)); maxx /= 2; maxx -= 140; //acceleration dx += (float)Math.Sin(angle) / 200.0f; //drag if (dx > 0) { dx -= 0.00001f; if (dx < 0) { dx = 0; } } if (dx < 0) { dx += 0.00001f; if (dx > 0) { dx = 0; } } x += dx * (float)gameTime.ElapsedGameTime.TotalMilliseconds; //bounce if (x > 410 + maxx) { x = 410 + maxx; dx = -dx / 5.0f; if (Math.Abs(dx) < 0.01f) { dx = 0; } } if (x < 410 - maxx) { x = 410 - maxx; dx = -dx / 5.0f; if (Math.Abs(dx) < 0.01f) { dx = 0; } } float by = 2 + (y1) + ((y2 - y1) * (x / 820.0f)); Rectangle ballrect = new Rectangle((int)x - 5, (int)by - 3, 10, 6); foreach (Hole h in holes) { Rectangle holerect = new Rectangle(h.x - 5, h.y - 8, 10, 10); if (!h.small) { holerect = new Rectangle(h.x - 8, h.y - 10, 16, 16); } if (ballrect.Intersects(holerect)) { if (x > h.x) { dx -= 0.0002f; } if (x < h.x) { dx += 0.0002f; } } } ballrect = new Rectangle((int)x - 1, (int)by - 3, 2, 6); foreach (Hole h in holes) { Rectangle holerect = new Rectangle(h.x - 1, h.y - 8, 2, 10); if (!h.small) { holerect = new Rectangle(h.x - 4, h.y - 10, 8, 16); } if (ballrect.Intersects(holerect) && !inhole) { inhole = true; dx = 0; fallx = x; fally = 2 + (y1) + ((y2 - y1) * (x / 820.0f)); if (h.isBlack || h.nr != activeHole) { SoundCache.PlaySound("Come Back To Me"); PlayerDie(); Reset(); } else { SoundCache.PlaySound("Entering Wormhole"); PlayerNextHole(); Reset(); } } } } else { anim += 0.2f; } }
private void EndGame() { state = LevelState.ENDING; mainLoop.FadeOut(); SoundCache.PlaySound("Goodbye Pilot"); }