/// <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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } player.Update(gameTime); // Check for platform collisions var platformQuery = Alist.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width); player.CheckForPlatformCollision(platformQuery); //ghosts buggy, explained below ghost1.Update(gameTime); ghost2.Update(gameTime); ghost3.Update(gameTime); ghost4.Update(gameTime); ghost5.Update(gameTime); ghost6.Update(gameTime); ghost7.Update(gameTime); ghost8.Update(gameTime); ghost9.Update(gameTime); 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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } foreach (GameObject gm in gameObjects) { gm.Update(gameTime); } var platformQuery = gameWorld.QueryRange(player.bounds.X, player.bounds.X + player.bounds.Width); player.CheckForPlatformCollision(platformQuery); 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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here // TODO: Add your update logic here player.Update(gameTime); // Check for platform collisions var platformQuery = world.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width); player.CheckForPlatformCollision(platformQuery); 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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here player.Update(gameTime); olive1.Update(gameTime); olive2.Update(gameTime); olive3.Update(gameTime); olive4.Update(gameTime); olive5.Update(gameTime); var barrierQuery = world.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width); player.CheckForBarrierCollision(barrierQuery); 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) { keyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (keyboardState.IsKeyDown(Keys.Escape)) { Exit(); } if (keyboardState.IsKeyDown(Keys.Tab)) { this.Reset(); } // TODO: Add your update logic here particleSystem.Update(gameTime); sparkleSystem.Update(gameTime); fireSystem.Update(gameTime); player.Update(gameTime); cake.Update(gameTime); cookie.Update(gameTime); donut.Update(gameTime); carrot.Update(gameTime); broccoli.Update(gameTime); if (player.collidesWithCake(cake)) { cake.eating.Play(); score += cake.pointVal; cake.Bounds.Y = 0; cake.Bounds.X = RandomizeItem(); } if (player.collidesWithCookie(cookie)) { cookie.eating.Play(); score += cookie.pointVal; cookie.Bounds.Y = 0; cookie.Bounds.X = RandomizeItem(); } if (player.collidesWithCarrot(carrot)) { carrot.cough.Play(); score += carrot.pointVal; carrot.Bounds.Y = 0; carrot.Bounds.X = RandomizeItem(); } if (player.collidesWithBroccoli(broccoli)) { broccoli.cough.Play(); score += broccoli.pointVal; broccoli.Bounds.Y = 0; broccoli.Bounds.X = RandomizeItem(); } if (player.collidesWithDonut(donut)) { donut.eating.Play(); score += donut.pointVal; donut.Bounds.Y = 0; donut.Bounds.X = RandomizeItem(); } if (PlayerCollidesWithButton()) { buttonRect.Y += 20; score += 10; } var blockQuery = world.QueryRange(player.position.X, player.position.X + player.FRAME_WIDTH); player.CheckForBlockCollision(blockQuery); 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) { offset = new Vector2(0, 0) + new Vector2(0, (float)gameTime.TotalGameTime.TotalMilliseconds / 50); newKeyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (newKeyboardState.IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here if (!lose) { //remove collised bullet and enemies for (int i = 0; i < bullets.Count; i++) { var enemyQuery = env.QueryRange(0, 1042); if (!bullets[i].IsExist(enemyQuery)) { score++; bullets.RemoveAt(i); return; } } //remove the bullet out of bounds for (int i = 0; i < bullets.Count; i++) { if (!bullets[i].IsVisible(-offset.Y)) { bullets.RemoveAt(i); i--; } } for (int i = 0; i < EBullets.Count; i++) { if (!EBullets[i].IsVisible(-offset.Y)) { EBullets.RemoveAt(i); i--; } } //remove stones out of bounds for (int i = 0; i < stones.Count; i++) { if (!stones[i].IsVisible(-offset.Y)) { stones.RemoveAt(i); i--; } } //add enemies float elapsed = (float)gameTime.ElapsedGameTime.TotalMilliseconds; timer -= elapsed; if (timer < 0 && enemies.Count < 10) { Enemy newEnemy = new Enemy(this, new BoundingRectangle(new Vector2(Random.Next(10) * 100, -30 - offset.Y), 60, 39), enemies_sheet[Random.Next(0, 15)]); newEnemy.LoadContent(Content); enemies.Add(newEnemy); env.AddGameObject(newEnemy); timer = TIMER; } //check for lose foreach (Enemy e in enemies) { e.Update(gameTime); if (e.IsLose(-offset.Y)) { lose = true; } if (player.Bounds.CollidesWith(e.Bounds)) { lose = true; } } foreach (EnemyBullet ebs in EBullets) { if (player.Bounds.CollidesWith(ebs.Bounds)) { lose = true; } } foreach (Stone s in stones) { s.Update(gameTime); if (s.IsCrash(player.Bounds)) { lose = true; } } //update foreach (EnemyBullet ebs in EBullets) { ebs.Update(gameTime); } foreach (Bullet b in bullets) { b.Update(gameTime); } player.Update(gameTime, -offset.Y); base.Update(gameTime); // Remove killed enemies foreach (Enemy enemy in killedEnemies) { enemies.Remove(enemy); env.RemoveGameObject(enemy); } } oldKeyboardState = newKeyboardState; }