Example #1
0
 public override void Update(RenderContext renderContext, Land land, PipeList pipes)
 {
     fly(renderContext);
     checkCollision(renderContext, land, pipes);
     animateSprite(renderContext);
     base.Update(renderContext);
 }
Example #2
0
 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;
     }
 }
Example #3
0
 //public override void Draw(RenderContext renderContext)
 //{
 //    // Draw Sprites's bounds
 //    renderContext.spriteBatch.Draw(pixel, topPipe, Color.White);
 //    renderContext.spriteBatch.Draw(pixel, bottomPipe, Color.White);
 //    base.Draw(renderContext);
 //}
 public override void Update(RenderContext renderContext)
 {
     base.Update(renderContext);
     topPipe.X = (int)_position.X;
     topPipe.Y = (int)_position.Y;
     bottomPipe.X = (int)(_position.X + 685);
     bottomPipe.Y = (int)_position.Y;
 }
Example #4
0
 public bool isOutofScreen(RenderContext renderContext)
 {
     if (_position.Y > renderContext.graphicsDevice.Viewport.Height)
     {
         return true;
     }
     return false;
 }
Example #5
0
        public override void loadContent(RenderContext renderContext)
        {
            base.loadContent(renderContext);

            // Draw Sprites's bounds
            bound = new Rectangle((int)_position.X, (int)_position.Y, this._width, this._height);
            //pixel = new Texture2D(renderContext.graphicsDevice, 1, 1);
            //pixel.SetData<Color>(new[] { Color.Blue });
        }
Example #6
0
 protected void scrollSprite(RenderContext renderContext)
 {
     _rentangle = new Rectangle(0, scroller, _frameWidth, _frameHeight);
     scroller += (int)_velocity.Y;
     if (scroller > _height / 2)
     {
         scroller = 0;
     }
 }
Example #7
0
        public override void loadContent(RenderContext renderContext)
        {
            base.loadContent(renderContext);
            this._position = new Vector2(renderContext.graphicsDevice.Viewport.Width - this._width, 0);

            // Draw Sprites's bounds
            bound = new Rectangle((int)_position.X, (int)_position.Y, _frameWidth, _frameHeight);
            //pixel = new Texture2D(renderContext.graphicsDevice, 1, 1);
            //pixel.SetData<Color>(new[] { Color.Black });
        }
Example #8
0
        public override void loadContent(RenderContext renderContext)
        {
            base.loadContent(renderContext);
            this._center = new Vector2(_frameWidth / 2, _frameHeight / 2);

            // Draw Sprites's bounds
            bound = new Rectangle((int)(_position.X - _center.X), (int)(_position.Y - _center.Y), _frameWidth, _frameHeight);
            //    pixel = new Texture2D(renderContext.graphicsDevice, 1, 1);
            //    pixel.SetData<Color>(new[] { Color.Red });
        }
Example #9
0
        public override void loadContent(RenderContext renderContext)
        {
            base.loadContent(renderContext);

            // Draw Sprites's bounds
            topPipe = new Rectangle((int)_position.X, (int)_position.Y, 515, _height);
            bottomPipe = new Rectangle((int)(_position.X + 685), (int)_position.Y, 515, _height);
            //pixel = new Texture2D(renderContext.graphicsDevice, 1, 1);
            //pixel.SetData<Color>(new[] { Color.Chocolate });
        }
Example #10
0
        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();
        }
Example #11
0
 protected void animateSprite(RenderContext renderContext)
 {
     _rentangle = new Rectangle(0, currentFrame * _frameHeight, _frameWidth, _frameHeight);
     timer += (int)renderContext.gameTime.ElapsedGameTime.TotalMilliseconds / 2;
     if (timer > INTERVAL)
     {
         currentFrame++;
         timer = 0;
         if (currentFrame > 2)
         {
             currentFrame = 0;
         }
     }
 }
Example #12
0
 //public override void Draw(RenderContext renderContext)
 //{
 //    base.Draw(renderContext);
 //    // Draw Sprites's bounds
 //    renderContext.spriteBatch.Draw(pixel, bound, Color.White);
 //}
 public override void Update(RenderContext renderContext)
 {
     scrollSprite(renderContext);
 }
Example #13
0
 public virtual void LoadContent(RenderContext renderContext)
 {
     this._font = renderContext.contentManager.Load<SpriteFont>(_linkFile);
 }
Example #14
0
 public virtual void Draw(RenderContext renderContext)
 {
     renderContext.spriteBatch.DrawString(_font, _text, _position, _color, _rotation,
         _center, _scale, _effects, _depth);
 }
Example #15
0
 public virtual void loadContent(RenderContext renderContext)
 {
     _texture = renderContext.contentManager.Load<Texture2D>(this._linkFile);
     _rentangle = new Rectangle(0, 0, this._width, this._height);
 }
Example #16
0
        //public override void Draw(RenderContext renderContext)
        //{
        //    // Draw Sprites's bounds
        //    renderContext.spriteBatch.Draw(pixel, bound, Color.White);
        //    base.Draw(renderContext);
        //}
        private void fly(RenderContext renderContext)
        {
            if (!isDie)
            {
                // Increase bird's speed
                _velocity.X += 0.2f;

                // Increase jump time
                jumpElapsed += renderContext.gameTime.ElapsedGameTime.TotalMilliseconds;

                // Check the jump time
                if (jumpElapsed > jumpTime)
                {
                    canJump = true;
                    jumpElapsed = 0;
                }

                // Check to rotate bird
                if (_velocity.X > 0)
                {
                    this._rotation = CORNER;
                }
                else
                {
                    this._rotation = -CORNER;
                }

                // Move bird
                _position += _velocity;

                // Touch event
                TouchCollection touches = TouchPanel.GetState();
                if (touches.Count > 0 && canJump)
                {
                    foreach (TouchLocation touch in touches)
                    {
                        if (touch.State == TouchLocationState.Pressed)
                        {
                            canJump = false;
                            _velocity.X = -4;
                        }
                    }
                }
            }
        }
Example #17
0
 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);
 }