/// <summary> /// Judge whether any pipe is collided with the cute magi(the bird). /// </summary> /// <param name="magi"></param> /// <returns></returns> public bool Collide(Magi magi) { Rectangle boundMagi = magi.Bound; foreach (Pipe p in _pipes) { Rectangle boundPipe = p.Bound; if (boundMagi.Intersects(boundPipe)) return true; } return false; }
/// <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); // TODO: use this.Content to load your game content here _resourceManager.LoadAll(); _font = _resourceManager.GetFont("DefaultFont"); _magi = new Magi(this, _magiStartPos, Vector2.Zero); _back = new Background(this); _pipeWave = new PipeWave(this); _state = GameState.InGame; }
/// <summary> /// Update the score, one point will be added the player for when /// the magi passed every two pipes, top and bottom. /// You need to access the Score property to get the current score. /// </summary> /// <param name="magi"></param> public void JudgeScore(Magi magi) { Rectangle boundMagi = magi.Bound; int count = 0; foreach (Pipe p in _pipes) { if (p.IsScored) continue; Rectangle bound = p.Bound; if (boundMagi.X > bound.X + bound.Width + 5) { p.IsScored = true; count++; } } _score += count / 2; // Every two pipes (top and bottom) for 1 score. }