/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); /* Draw the active screen */ SCREEN_MANAGER.Draw(gameTime); base.Draw(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); /* Have the active screen initilize itself. */ SCREEN_MANAGER.LoadContent(); }
public override void Update(GameTime gameTime) { // Check if m is pressed and go to screen2 if (Keyboard.GetState().IsKeyDown(Keys.S)) { SCREEN_MANAGER.goto_screen("gameMenu"); } base.Update(gameTime); }
public override void Update(GameTime gameTime) { // Check if Enter is pressed to start game if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { SCREEN_MANAGER.goto_screen("gameScreen"); } base.Update(gameTime); }
/// <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) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.P)) { SCREEN_MANAGER.goto_screen("gameMenu"); } SCREEN_MANAGER.Update(gameTime); base.Update(gameTime); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { /* Init our screen manager and add a screens to it. */ SCREEN_MANAGER.add_screen(new GameMenu(GraphicsDevice, Content)); SCREEN_MANAGER.add_screen(new GameScreen(GraphicsDevice, Content)); SCREEN_MANAGER.add_screen(new GameOver(GraphicsDevice, Content)); /* Set the active screen to the game menu */ SCREEN_MANAGER.goto_screen("gameMenu"); /* Init the current screen */ SCREEN_MANAGER.Init(); base.Initialize(); }
public override void Update(GameTime gameTime) { // User inputs. // Save the previous state of the keyboard and game pad so we can determine single key/button presses _prevGamePadState = _currentGamePadState; _prevKeyboardState = _currentKeyboardState; _prevMouseState = _currentMouseState; // Read the current state of the keyboard and gamepad and store it. _currentKeyboardState = Keyboard.GetState(); _currentGamePadState = GamePad.GetState(PlayerIndex.One); _currentMouseState = Mouse.GetState(); UpdatePlayer(gameTime); _bgLayer1.Update(gameTime); _bgLayer2.Update(gameTime); // update lasers UpdateLasers(gameTime); // update the enemies UpdateEnemies(gameTime); if (score >= 3 && !_boss.Active) { AddBoss(); } if (_boss.Active) { UpdateBoss(gameTime); // TODO: if boss.inactive exit -> highscore } // update collisons UpdateCollision(); UpdateExplosions(gameTime); // Check if ESC is pressed or Player is inactive and go to GameOver screen if (!_player.Active || Keyboard.GetState().IsKeyDown(Keys.Escape)) { SCREEN_MANAGER.goto_screen("gameOver"); } base.Update(gameTime); }
protected void UpdateCollision() { // we are going to use the rectangle's built in intersection // methods. Rectangle playerRectangle; Rectangle enemyRectangle; Rectangle laserRectangle; Rectangle bossRectangle; // create the rectangle for the player playerRectangle = new Rectangle( (int)_player.Position.X, (int)_player.Position.Y, _player.Width, _player.Height); if (_boss.Active) { bossRectangle = new Rectangle( (int)_boss.Position.X, (int)_boss.Position.Y, _boss.Width, _boss.Health); if (playerRectangle.Intersects(bossRectangle)) { AddExplosion(_player.Position); _player.Health = 0; } for (var j = 0; j < laserBeams.Count; j++) { laserRectangle = new Rectangle( (int)laserBeams[j].Position.X, (int)laserBeams[j].Position.Y, laserBeams[j].Width, laserBeams[j].Height); if (laserRectangle.Intersects(bossRectangle)) { AddExplosion(_boss.Position); _boss.Health -= 5; } if (_boss.Health <= 0) { _boss.Active = false; score += _boss.Value; SCREEN_MANAGER.goto_screen("gameOver"); } } } if (!_boss.Active) { // detect collisions between the player and all enemies. for (var i = 0; i < enemies.Count; i++) { enemyRectangle = new Rectangle( (int)enemies[i].Position.X, (int)enemies[i].Position.Y, enemies[i].Width, enemies[i].Height); // determine if the player and the enemy intersect. if (playerRectangle.Intersects(enemyRectangle)) { // kill off the enemy enemies[i].Health = 0; // Show the explosion where the enemy was... AddExplosion(enemies[i].Position); // deal damge to the player _player.Health -= enemies[i].Damage; // if the player has no health destroy it. if (_player.Health <= 0) { //AddExplosion(_player.Position); _player.Active = false; // _player.Position = Vector2.Zero; } } for (var l = 0; l < laserBeams.Count; l++) { // create a rectangle for this laserbeam laserRectangle = new Rectangle( (int)laserBeams[l].Position.X, (int)laserBeams[l].Position.Y, laserBeams[l].Width, laserBeams[l].Height); // test the bounds of the laser and enemy if (laserRectangle.Intersects(enemyRectangle)) { // Show the explosion where the enemy was... AddExplosion(enemies[i].Position); // kill off the enemy enemies[i].Health = 0; // kill off the laserbeam laserBeams[l].Active = false; score++; } } } } }