/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { if (game.GetGameState() == Game1.GameState.Playing) { checkInput(gameTime); } base.Update(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Draw(GameTime gameTime) { if (game.GetGameState() == Game1.GameState.Playing) { foreach (var item in bullets) { item.Draw(gameTime); } } base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { //Draws the same background twice, one above the other outside the screen pane if (game.GetGameState() == Game1.GameState.Playing) { spriteBatch.Begin(); spriteBatch.Draw(sf, background1, Color.White); spriteBatch.Draw(sf, background2, Color.White); spriteBatch.End(); } base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { if (game.GetGameState() == Game1.GameState.HighScores) { spriteBatch.Begin(); FlashTimerControl(); //Calls method to produce the text flashing effect color = selectedColor; spriteBatch.DrawString(font, menuItems[0], new Vector2((screenWidth / 2) - (font.MeasureString(menuItems[0]).X / 2), (screenHeight / 4 * 3)), color); spriteBatch.End(); } base.Draw(gameTime); }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { if (game.GetGameState() == Game1.GameState.Playing) { if (spawnMother) { if (mothership.GetAlienState() != AlienState.INACTIVE) { Move(); if (mothershipSoundInstance.State != SoundState.Playing) { mothershipSoundInstance.Play(); } } else if (mothership.GetAlienState() == AlienState.INACTIVE) { mothershipSoundInstance.Stop(); } } } base.Update(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Draw(GameTime gameTime) { if (game.GetGameState() == Game1.GameState.Playing) { if (motionCtr == 30) { //Iterate through list currentListPos++; if (currentListPos > 1) { currentListPos = 0; } //Set image for all aliens of each type alienTexture1 = alienMotion1[currentListPos]; alienTexture2 = alienMotion2[currentListPos]; alienTexture3 = alienMotion3[currentListPos]; hitAlienTexture1 = hitAlienMotion1[currentListPos]; hitAlienTexture2 = hitAlienMotion2[currentListPos]; hitAlienTexture3 = hitAlienMotion3[currentListPos]; for (int ctr = 0; ctr < alienSquad.GetLength(1); ctr++) { if (alienSquad[0, ctr].GetHitPoints() == 1) { alienSquad[0, ctr].SetTexture(hitAlienTexture1); } else { alienSquad[0, ctr].SetTexture(alienTexture1); } if (alienSquad[1, ctr].GetHitPoints() == 1) { alienSquad[1, ctr].SetTexture(hitAlienTexture2); } else { alienSquad[1, ctr].SetTexture(alienTexture2); } if (alienSquad[2, ctr].GetHitPoints() == 1) { alienSquad[2, ctr].SetTexture(hitAlienTexture3); } else { alienSquad[2, ctr].SetTexture(alienTexture3); } } //Reset motion counter delay motionCtr = 0; } for (int ctr1 = 0; ctr1 < alienSquad.GetLength(0); ctr1++) { for (int ctr2 = 0; ctr2 < alienSquad.GetLength(1); ctr2++) { if (alienSquad[ctr1, ctr2].GetAlienState() == AlienState.ACTIVE) { alienSquad[ctr1, ctr2].Draw(gameTime); } } } motionCtr++; } base.Draw(gameTime); }
public override void Update(GameTime gameTime) { if (game.GetGameState() == Game1.GameState.MainMenu) { if (!songPlaying) { titleSongInstance.Play(); songPlaying = true; } keyboard = Keyboard.GetState(); //Checks for input from user that represent going up if (CheckKeyboard(Keys.Up) || CheckKeyboard(Keys.W)) { //Will not go up further than top list item, wraps to bottom item if (selected > 0) { selected--; } else if (selected == 0) { selected = menuItems.Count - 1; } } //Checks for input from user that represent going down if (CheckKeyboard(Keys.Down) || CheckKeyboard(Keys.S)) { //Will not go lower than bottom list item, wraps to top item if (selected < menuItems.Count - 1) { selected++; } else if (selected == (menuItems.Count - 1)) { selected = 0; } } //Checks for input from user that represents 'enter' if (CheckKeyboard(Keys.Enter)) { switch (selected) { case 0: { titleSongInstance.Stop(); timer.Start(); break; } case 1: { game.SetGameState(Game1.GameState.HighScores); break; } case 2: { game.SetGameState(Game1.GameState.Exit); break; } } } prevKeyboard = keyboard; } base.Update(gameTime); }
public override void Update(GameTime gameTime) { if (game.GetGameState() == Game1.GameState.GameOverMenu) { keyboard = Keyboard.GetState(); //Makes sure user does not need to enter initial for highscore, if so controls are overriden if (!lockControls) { //Checks for input from user that represent going up if (CheckKeyboard(Keys.Up) || CheckKeyboard(Keys.W)) { //Will not go up further than top list item, wraps to bottom item if (selected > 0) { selected--; } else if (selected == 0) { selected = menuItems.Count - 1; } } //Checks for input from user that represent going down if (CheckKeyboard(Keys.Down) || CheckKeyboard(Keys.S)) { //Will not go lower than bottom list item, wraps to top item if (selected < menuItems.Count - 1) { selected++; } else if (selected == (menuItems.Count - 1)) { selected = 0; } } //Checks for input from user that represents 'enter' if (CheckKeyboard(Keys.Enter)) { switch (selected) { //Game restart case case 0: { timer.Start(); initialCtr = 0; lockControls = false; releaseControls = false; game.restartGame(); break; } //Main menu case case 1: { //game.restartGame(); //game.SetGameState(Game1.GameState.MainMenu); break; } //Exit case case 2: { game.SetGameState(Game1.GameState.Exit); break; } } } } score = game.GetGameScore(); highScore = game.GetGameHighScore(); //Will not accept key input if game controls are active if (lockControls) { acceptHighScoreInitials(); } prevKeyboard = keyboard; } base.Update(gameTime); }