private void checkCollision(RenderContext renderContext, Sprite land, PipeList pipes) { // Check collision with background if (!isDie) { // Check collision with pipe foreach (Pipe pipe in pipes.pipeList) { if (pipe.topPipe.Intersects(this.bound) || pipe.bottomPipe.Intersects(this.bound)) { // Bird die isDie = true; direction = 1; _velocity = new Vector2(12, 0); _rotation = CORNER; } } } // Check collision with land if (land.bound.Intersects(this.bound)) { // Bird die isDie = true; _velocity = Vector2.Zero; } }
public override void Update(RenderContext renderContext, Land land, PipeList pipes) { fly(renderContext); checkCollision(renderContext, land, pipes); animateSprite(renderContext); base.Update(renderContext); }
protected override void Initialize() { // Create all Sprites objects renderContext = new RenderContext(); scope = 0; _background = new Background("Background"); _bird = new Bird("Bird", new Vector2(50, 350), 50, 79); _land = new Land("Land", 142, this.GraphicsDevice.Viewport.Height); _pipes = new PipeList("Pipe"); _font = new Font("Font", scope.ToString(), new Vector2(50, 125)); base.Initialize(); }
public bool isPassPipe(PipeList pipes) { if (pipes.pipeList.Count > 0) { Pipe pipeFirst = pipes.pipeList[0]; for (int i = 1; i < pipes.pipeList.Count; i++) { if (pipes.pipeList[i].topPipe.Y > pipeFirst.topPipe.Y) pipeFirst = pipes.pipeList[i]; } if (pipeFirst != null && bound.Y == pipeFirst.topPipe.Y) { return true; } } return false; }
public virtual void Update(RenderContext renderContext, Land land, PipeList pipes) { _position += _velocity * direction; bound.X = (int)(_position.X - _center.X); bound.Y = (int)(_position.Y - _center.Y); }