/// <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 (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); gsm.GameStateChanger(currentGameState); if (currentGameState == 1) { if (Keyboard.GetState().IsKeyDown(Keys.E)) { currentGameState = 3; } else { intro.IntroText(); } } if (currentGameState == 3) { p.Update(gameTime, ch); p.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); hud.Update(gameTime); foreach (Asteroid a in asteroid) { a.Update(gameTime); a.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); if (p.GetPlayerHitbox().Intersects(a.GetAsteroidHitbox())) { switch (a.GetSize()) { case 1: numOfAsteroids -= 1; Vector2 temp = new Vector2((float)a.GetXPos(), (float)a.GetYPos()); asteroidKillList.Add(a); p.SetLives((p.GetLife() - 1)); break; case 2: numOfAsteroids -= 1; for (int i = 0; i < 2; i++) { double angle = r.NextDouble() * 2 * Math.PI; newAsteroidList.Add(new Asteroid(new Vector2(a.GetXPos(), a.GetYPos()), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)))); numOfAsteroids += 1; } asteroidKillList.Add(a); p.SetLives((p.GetLife() - 1)); break; case 3: numOfAsteroids -= 1; for (int i = 0; i < 2; i++) { double angle = r.NextDouble() * 2 * Math.PI; newAsteroidList.Add(new Asteroid(new Vector2(a.GetXPos(), a.GetYPos()), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)))); numOfAsteroids += 1; } asteroidKillList.Add(a); p.SetLives((p.GetLife() - 1)); break; default: System.Windows.Forms.MessageBox.Show("Oeps"); break; } } } if (asteroid.Count == 0) { LevelsIncrease(); } foreach (Asteroid a in newAsteroidList) { asteroid.Add(a); } foreach (Asteroid a in asteroidKillList) { asteroid.Remove(a); } asteroidKillList.Clear(); newAsteroidList.Clear(); foreach (Weapon wep in p.weapList) { wep.Update(gameTime, wep.GetDirection()); wep.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); if (wep.GetFadeTime() == 0) { wep.SetIsVisable(false); killListWep.Add(wep); } foreach (Asteroid a in asteroid) { if (wep.GetHitbox().Intersects(a.GetAsteroidHitbox())) { switch (a.GetSize()) { case 1: asteroidKillList.Add(a); killListWep.Add(wep); hud.SetScore(10); numOfAsteroids -= 1; break; case 2: for (int i = 0; i < 2; i++) { double angle = r.NextDouble() * 2 * Math.PI; newAsteroidList.Add(new Asteroid(new Vector2(a.GetXPos(), a.GetYPos()), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)))); numOfAsteroids += 1; } asteroidKillList.Add(a); killListWep.Add(wep); hud.SetScore(25); break; case 3: for (int i = 0; i < 2; i++) { double angle = r.NextDouble() * 2 * Math.PI; newAsteroidList.Add(new Asteroid(new Vector2(a.GetXPos(), a.GetYPos()), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)))); numOfAsteroids += 1; } asteroidKillList.Add(a); killListWep.Add(wep); hud.SetScore(50); break; default: break; } } } } foreach (Weapon weap in killListWep) { p.weapList.Remove(weap); } playerLife = p.GetLife(); if (playerLife <= 0) { currentGameState = 4; } } if (currentGameState == 4) { if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { numOfAsteroids = 5; r = new Random(); p = new Player(); hud = new HUD(); Initialize(); currentGameState = 3; } } if (currentGameState == 5) { if (Keyboard.GetState().IsKeyDown(Keys.F)) { currentGameState = 2; } else { oMenu.Update(ch); } } if (currentGameState == 8) { if (loadingScreen != null) { IsFixedTimeStep = false; loader = loadingScreen.Update(); if (loader != null) { loadingScreen = null; IsFixedTimeStep = true; } } } base.Update(gameTime); }
/// <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); structOptionsMain = new StructOptionsMain(); structOptionsMain.Graphics = graphics; structOptionsMain.Content = Content; structOptionsMain.SpriteBatch = spriteBatch; structOptionsMain.SpriteFont = Content.Load<SpriteFont>("MenuFont"); structOptionsMain.Ch = ch; oMenu = new OptionsMenu(structOptionsMain); p.Load(Content); p.SetPlayerPos(spriteBatch); hud.Load(Content); intro.Load(Content, graphics); credit.Load(Content, graphics); oMenu.Init(); gameOverMenu.Load(); shield.Load(); pickUp.Load(Content); if (spawnPickup >= 70) { pickUp.Load(Content); } machineGun.Load(); extraLife.Load(); speedUp.Load(); mainMenu.Load(graphics.GraphicsDevice, scores); background = new Background(GraphicsDevice, Content); loadingScreen = new LoadingScreen(Content, graphics.GraphicsDevice); kbm.Load(); foreach (Weapon wep in p.weapList) { wep.Load(Content, p.GetDirection()); } }
/// <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); p.Load(Content); hud.Load(Content); intro.Load(Content, graphics); oMenu.Load(); background = new Background(GraphicsDevice, Content); loadingScreen = new LoadingScreen(Content, graphics.GraphicsDevice); foreach (Weapon wep in p.weapList) { wep.Load(Content, p.GetDirection()); } }
/// <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); p.Load(Content); p.SetPlayerPos(spriteBatch); hud.Load(Content); mainMenu = new MainMenu(Content, graphics, ch); intro.Load(Content, graphics); oMenu.Load(); mainMenu.Load(Content, graphicsDevice); background = new Background(GraphicsDevice, Content); loadingScreen = new LoadingScreen(Content, graphics.GraphicsDevice); alien = new Alien(Content.Load<Texture2D>("AlienShip"), new Vector2(50, 100), Vector2.Zero, 0f, 2f, Content.Load<Texture2D>("AlienBullet")); foreach (Weapon wep in p.weapList) { wep.Load(Content, p.GetDirection()); } }