/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Vector2 stage = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); Texture2D texBack1 = Content.Load <Texture2D>("Images/stars2"); ScrollingBackground sb1 = new ScrollingBackground(this, spriteBatch, stage, texBack1, new Vector2(0, 1), 1); Texture2D texBack2 = Content.Load <Texture2D>("Images/stars"); ScrollingBackground sb2 = new ScrollingBackground(this, spriteBatch, stage, texBack2, new Vector2(0, 2), 0.5f); song = Content.Load <Song>("Sounds/music"); MediaPlayer.Play(song); MediaPlayer.IsRepeating = true; this.Components.Add(sb1); this.Components.Add(sb2); actionScreen = new ActionScreen(this, spriteBatch); Components.Add(actionScreen); splashScreen = new SplashScreen(this, spriteBatch); Components.Add(splashScreen); helpScreen = new HelpScreen(this, spriteBatch); Components.Add(helpScreen); aboutScreen = new AboutScreen(this, spriteBatch); Components.Add(aboutScreen); highScoreScreen = new HighScoreScreen(this, spriteBatch); Components.Add(highScoreScreen); howToPlayScreen = new HowToPlayScreen(this, spriteBatch); Components.Add(howToPlayScreen); splashScreen.show(); }
public void CreateActionScreen() { Components.Remove(actionScreen); actionScreen = new ActionScreen(this, spriteBatch); Components.Add(actionScreen); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // TODO: Add your update logic here int selectedIndex = 0; KeyboardState ks = Keyboard.GetState(); if (splashScreen.Enabled) { selectedIndex = splashScreen.Menu.SelectedIndex; if (selectedIndex == 0 && ks.IsKeyDown(Keys.Enter)) { Components.Remove(actionScreen); actionScreen = new ActionScreen(this, spriteBatch); level = 1; Components.Add(actionScreen); hideAllScenes(); actionScreen.show(); } if (selectedIndex == 1 && ks.IsKeyDown(Keys.Enter)) { hideAllScenes(); helpScreen.show(); } if (selectedIndex == 2 && ks.IsKeyDown(Keys.Enter)) { Components.Remove(highScoreScreen); highScoreScreen = new HighScoreScreen(this, spriteBatch); Components.Add(highScoreScreen); hideAllScenes(); highScoreScreen.show(); } if (selectedIndex == 3 && ks.IsKeyDown(Keys.Enter)) { hideAllScenes(); aboutScreen.show(); } if (selectedIndex == 4 && ks.IsKeyDown(Keys.Enter)) { hideAllScenes(); howToPlayScreen.show(); } if (selectedIndex == 5 && ks.IsKeyDown(Keys.Enter)) { Exit(); } } if (helpScreen.Enabled || aboutScreen.Enabled || highScoreScreen.Enabled || howToPlayScreen.Enabled || actionScreen.Enabled) { if (ks.IsKeyDown(Keys.Escape)) { Components.Remove(actionScreen.Ship.Bullet); hideAllScenes(); splashScreen.show(); } } if (actionScreen.Score == level * 10) { Components.Remove(actionScreen); actionScreen = new ActionScreen(this, spriteBatch); level += 1; Components.Add(actionScreen); actionScreen.Level = level; actionScreen.show(); actionScreen.DisplayLevel(); } base.Update(gameTime); }