protected override void Update(GameTime gameTime) { MouseState mouse = Mouse.GetState(); switch (CurrentGameState) { case GameState.MainMenu: //Menu Actions if (buttonPlay.isClicked == true) { CurrentGameState = GameState.Playing; } if (buttonQuit.isClicked == true) { Exit(); } buttonQuit.Update(mouse); buttonPlay.Update(mouse); break; case GameState.Playing: //Game actions if (musicPlaying == true) { } else if (musicPlaying == false) { MediaPlayer.Play(song); musicPlaying = true; } KeyboardState keyboardState = Keyboard.GetState(); //generate stars for (int i = 0; i < 4; ++i) { StarSprite star = new StarSprite(this.star[generateRandom(0, 6)], this, TimeSpan.FromSeconds(2)); star.Position = new Vector2(generateRandom(0, ScreenWidth), 0); this.Components.Add(star); } //start & continue game if (keyboardState.IsKeyDown(Keys.Enter) && !ship.Enabled) { if (lives == 0) { for (int i = 0; i < enemyConductor.enemyList.Count; ++i) { this.Components.Remove(enemyConductor.enemyList[i]); } //enemyConductor.enemyList.Clear(); this.enemyConductor.StartTime = gameTime; this.enemyConductor.EnemiesGoingLeft = false; this.enemyConductor.Initialize(1); score = 0; lives = 3; level = 1; goals = 10000; ship.Enabled = true; ship.Visible = true; CurrentGameState = GameState.Ending; } else { goals = score + goals; ship.Enabled = true; ship.Visible = true; } } if (score >= goals) { //Load companion this.shipC = new ShipCompanion(this.companionTexture, this); this.shipC.Position = this.ship.Position + new Vector2(side * 50, 0); this.Components.Add(this.shipC); this.shipC.Counter = 1000; goals *= 1.5f; side *= -1; } //respawn mobs if player wipes them all out if (EnemyConductor.enemyList.Count == 0 && level % 2 != 0) { level++; enemyConductor.enemyList.Clear(); this.enemyConductor.EnemiesGoingLeft = false; this.enemyConductor.StartTime = gameTime; this.enemyConductor.Initialize(1); } else if (EnemyConductor.enemyList.Count == 0 && level % 2 == 0) { level++; enemyConductor.enemyList.Clear(); this.enemyConductor.EnemiesGoingLeft = false; this.enemyConductor.StartTime = gameTime; this.enemyConductor.Initialize(2); } //Change background color every level... /* * if(level > prevLevel) * { * if (c4 < 100) * { * c1 += 25; c2 += 25; c3 += 25; c4 += 25; * color = new Color(c1, c2, c3); * } * else * { * c1 -= 25; c2 -= 25; c3 -= 25; c4 += 25; * color = new Color(c1, c2, c3); * if (c4 == 200) c4 = 0; * } * * prevLevel = level; * } */ break; case GameState.Ending: KeyboardState kb = Keyboard.GetState(); if (kb.IsKeyDown(Keys.Space)) { enemyConductor.enemyList.Clear(); CurrentGameState = GameState.MainMenu; } break; } base.Update(gameTime); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); //load player ship textures this.shipTexture = Content.Load <Texture2D>("ship"); this.shipExplodingTexture = Content.Load <Texture2D>("Explode"); this.ship = new ShipSprite(this.shipTexture, this); this.ship.Position = new Vector2(500, 700); this.Components.Add(this.ship); //Load companion this.companionTexture = Content.Load <Texture2D>("shipC"); this.shipC = new ShipCompanion(this.companionTexture, this); this.shipC.Position = this.ship.Position + new Vector2(100, 0); //load the sound here to prevent a stutter when use fires first bullet sound = Content.Load <SoundEffect>("fire"); //load song (background music) song = Content.Load <Song>("music"); // Create friend bullet this.friendBullet = new Texture2D(this.GraphicsDevice, 1, 1); Color[] data = new Color[1 * 1]; for (int i = 0; i < data.Length; ++i) { data[i] = Color.Yellow; } this.friendBullet.SetData(data); // Create enemy bullet this.enemyBullet = new Texture2D(this.GraphicsDevice, 1, 1); data = new Color[1 * 1]; for (int i = 0; i < data.Length; ++i) { data[i] = Color.White; } this.enemyBullet.SetData(data); //create 6 coloured stars for (int i = 0; i < 6; ++i) { Texture2D newStar; newStar = new Texture2D(this.GraphicsDevice, 1, 1); data = new Color[1 * 1]; for (int a = 0; a < data.Length; ++a) { data[a] = starColor(i); } newStar.SetData(data); star.Add(newStar); } //load enemies this.enemyConductor = new EnemyConductor(this); this.enemyConductor.Initialize(1); this.Components.Add(this.enemyConductor); //load buttons buttonPlay = new cButton(Content.Load <Texture2D>("playButton"), graphics.GraphicsDevice); buttonQuit = new cButton(Content.Load <Texture2D>("quitButton"), graphics.GraphicsDevice); //load background startScreen = Content.Load <Texture2D>("MainMenu"); color = new Color(c1, c2, c3, c4); }