/// <summary> /// Collision handling for each sprite on the screen. /// </summary> /// <param name="sprite">Sprite to check collision with.</param> private void HandleCollision(Sprite sprite) { Rectangle itemBounds = new Rectangle(sprite.GetX(), sprite.GetY(), sprite.GetWidth(), sprite.GetHeight()); String name = sprite.GetName(); if (IntersectPixels(playerBounds, playerData, itemBounds, sprite.GetColorData())) { if (!sprite.GetTransparent()) { if (name.Equals("level1") || name.Equals("level2") || name.Equals("level3")) { if (IsAbove(playerBounds, itemBounds) && ((player.CheckJump() && sprite.GetY() == 399) || (jumping && sprite.GetY() == 499))) { sprite.KillVirus(); } else { if (Constants.isSwappingHand && player.HasSword() && sprite.GetY() == 399) { swordUsed = true; sprite.SlashVirus(); } else { if (!Constants.isPunching) { sprite.HitVirus(); } } } } ApplyEffect(name, sprite); PlaySoundEffects(name, sprite); if (!name.Equals("gym") && !name.Contains("boss")) { sprite.Collide(name); } else { if (Constants.isSteppingRight) { screenPaused = true; ScreenManager.AddScreen(new ExcercisesScreen(this)); this.FreezeScreen(); } } if (name.Contains("boss")) { if (playerBounds.Right >= sprite.GetX() + 150) { //Add Boss Screen screenPaused = true; spriteCounter = 0; currentSprite.Clear(); globalCounter = 600; this.FreezeScreen(); currentSprite.Remove(sprite); ScreenManager.AddScreen(new BossFightScreen(this, Int32.Parse((name.Substring(4))))); } } } } }
void menu_Clicked(object sender, System.EventArgs a) { this.Remove(); ScreenManager.AddScreen(new MainScreen()); }
/// <remarks> ///<para>AUTHOR: Khaled Salah, Ahmed Shirin </para> ///</remarks> public override void Update(GameTime gameTime) { Content = ScreenManager.Game.Content; #region Omar Abdulaal bgLayer1.Update(); bgLayer2.Update(); bgLayer3.Update(); player.Update(gameTime); if (jumping) { GetActualBounds(player.GetBoundingRectangle(), player.GetColorData(), out playerBounds, out playerData); } else { playerBounds = player.GetBoundingRectangle(); playerData = player.GetColorData(); } if (player.CheckDeath()) { if (colorDataList.Count == 0) { this.Remove(); ScreenManager.AddScreen(new LosingScreen(player.Score)); } else { this.Remove(); ScreenManager.AddScreen(new PhotographsScreen(colorDataList, player.Score)); } } if (Constants.isJumping && colorDataList.Count == 0) { byte[] colorData = ScreenManager.Kinect.GetColorPixels(30); if (colorData != null) { colorDataList.Add(colorData); } } if (Constants.isRunning && colorDataList.Count == 1) { byte[] colorData = ScreenManager.Kinect.GetColorPixels(30); if (colorData != null) { colorDataList.Add(colorData); } } if (player.Immunity < 30) { alertTimer += gameTime.ElapsedGameTime.Milliseconds; if (alertTimer >= 750) { displayAlert = !displayAlert; alertTimer = 0; } } else { displayAlert = false; } #endregion #region khaled's pausescreen and music if (MediaPlayer.State.Equals(MediaState.Stopped)) { switch (playQueue) { case 1: { MediaPlayer.Play(songs[0]); playQueue = 2; break; } case 2: { MediaPlayer.Play(songs[1]); playQueue = 3; break; } case 3: { playQueue = 1; break; } default: break; } } #endregion updateImmunityCounter++; if (player.Immunity < 30 && updateImmunityCounter > 0) { immunityAudio.Play(); updateImmunityCounter = -300; } KeyboardState state = Keyboard.GetState(); if (state.IsKeyDown(Keys.Space)) { Constants.isJumping = true; } if (state.IsKeyDown(Keys.LeftControl)) { Constants.isBending = true; } if (state.IsKeyDown(Keys.Enter)) { Constants.isPunching = true; } if (state.IsKeyDown(Keys.D)) { Constants.isSwappingHand = true; } if (Constants.isJumping) { jumpTimer++; } if (jumpTimer == 1) { soundEffects[9].Play(); } if (!player.CheckJump()) { jumpTimer = 0; } if (player.CheckJump()) { jumping = true; } if (jumping) { time += gameTime.ElapsedGameTime.Milliseconds; if (time <= player.GetJumpTime()) { jumping = true; } else { jumping = false; time = 0; } } if (player.CheckSword()) { swordTimer += gameTime.ElapsedGameTime.Milliseconds; } if (globalCounter % 600 == 0) { NewItems(); } globalCounter++; if (globalCounter % 60 == 0 && globalCounter > 600) { spriteCounter++; } for (int i = 0; i <= spriteCounter - 1; i++) { try { currentSprite[i].Update(spriteSpeed); HandleCollision(currentSprite[i]); } catch (Exception e) { spriteCounter--; } } for (int i = 0; i <= spriteCounter - 1; i++) { try { Sprite sprite = currentSprite[i]; if (sprite.GetName().Contains("boss") && sprite.GetX() == 800) { spriteSpeed = 0; bgLayer1.PauseBackground(); bgLayer2.PauseBackground(); bgLayer3.PauseBackground(); player.MovePlayer(); } } catch (Exception e) { spriteCounter--; } } if (!player.CheckSword()) { swordTimer = 0; } if (swordUsed) { player.AcquireSword(false); if (swordTimer >= player.GetSwordTime()) { swordUsed = false; player.ReInitializeRunAnimation(); swordTimer = 0; } } RemoveSprites(); bar.SetCurrentValue(player.Immunity); score.score = player.Score; //FreezeScreen(); //ScreenManager.AddScreen(new BossFightScreen(this, 1)); base.Update(gameTime); }