protected void UpdateInput() { // Get the game pad state. GamePadState currentState = GamePad.GetState(PlayerIndex.One); KeyboardState currentKeyState = Keyboard.GetState(); ship.Update(currentKeyState); if (currentKeyState.IsKeyDown(Keys.W)) { if (soundEngineInstance.State == SoundState.Stopped) { soundEngineInstance.Volume = 0.75f; soundEngineInstance.IsLooped = true; soundEngineInstance.Play(); } else { soundEngineInstance.Resume(); } } else if (currentKeyState.IsKeyUp(Keys.W)) { if (soundEngineInstance.State == SoundState.Playing) { soundEngineInstance.Pause(); } } // In case you get lost, press A to warp back to the center. if (currentState.Buttons.A == ButtonState.Pressed || currentKeyState.IsKeyDown(Keys.Enter)) { ship.Position = Vector3.Zero; ship.Velocity = Vector3.Zero; ship.Rotation = 0.0f; soundHyperspaceActivation.Play(); } }
void updatePlaying() { if (GamePad.GetState(0).Buttons.Back == ButtonState.Pressed) { reset(); } if (inputManager.InputPause()) { currentState = States.Paused; } if (score <= 0) { score = 0; if (reduced && !eaten) { currentState = States.GameOver; } else if (eaten) { if (currentScore == 0) { currentState = States.GameOver; } } } if (score > saveData.GetHighScore()) { saveData.SetHighScore(score); } if (score > sessionScore) { sessionScore = score; } if (currentScore < score) { currentScore += 10; } else if (currentScore > score) { currentScore -= 10; } monsterTimer--; if (monsterTimer <= 0) { monsterTimer = 150; Random rand = new Random(); int y = rand.Next(0, 650); float speed = 1; if (score >= 10000) { speed = 10; monsterTimer = 50; } else if (score >= 7500) { speed = 7; monsterTimer = 60; } else if (score >= 5000) { speed = 6; monsterTimer = 70; } else if (score >= 2000) { speed = 5; monsterTimer = 80; } else if (score >= 1000) { speed = 4; monsterTimer = 90; } else if (score >= 500) { speed = 3; monsterTimer = 100; } else if (score >= 100) { speed = 2; } monsters.Add(new Monster(contentManager, new Vector2(1280, y), speed)); } ship.Update(); if (ship.HasFired()) { if (ship.GetFrame() != 2) { bolts.Add(new Bolt(contentManager, new Vector2(ship.GetPosition().X + 32, ship.GetPosition().Y + 48), saveData.GetBoltColour(), 5, 400)); } else { bolts.Add(new Bolt(contentManager, new Vector2(ship.GetPosition().X + 32, ship.GetPosition().Y + 20), saveData.GetBoltColour(), 5, 400)); } } if (bolts.Count > 0) { for (int i = bolts.Count - 1; i >= 0; i--) { bolts[i].Update(); if (bolts[i].IsDead()) { bolts.RemoveAt(i); } } } if (monsters.Count > 0) { for (int i = monsters.Count - 1; i >= 0; i--) { monsters[i].Update(); if (ship.GetCollisionBox().Intersects(monsters[i].GetCollisionBox())) { if (!ship.ControlsLocked()) { ship.LockControls(true); monsters[i].SetEating(); monsters[i].SetPosition(new Vector2(ship.GetPosition().X + 20, ship.GetPosition().Y)); score = 0; eaten = true; } } if (bolts.Count > 0) { for (int j = bolts.Count - 1; j >= 0; j--) { if (bolts[j].GetCollisionBox().Intersects(monsters[i].GetCollisionBox())) { monsters[i].DoDamage(1); score += 100; bolts.RemoveAt(j); } } } if (monsters[i].IsDead()) { monsters.RemoveAt(i); } else { if (monsters[i].GetPosition().X < -64) { reduced = true; score -= 200; monsters.RemoveAt(i); } } } } starfield.Update(); }