Ejemplo n.º 1
0
        public void Update(GameTime gameTime, List <NonAnimatedSprite> blocks)
        {
            base.Update(gameTime);

            if (OnGround)
            {
                bool fallen = true;
                for (int i = 0; i < blocks.Count; i++)
                {
                    if (Foot.Intersects(blocks[i].Roof))
                    {
                        fallen = false;
                    }
                }

                if (fallen)
                {
                    OnGround = false;
                    Floor    = 600;
                }
            }

            if (!OnGround)
            {
                Velocity.Y += Gravity;

                for (int i = 0; i < blocks.Count; i++)
                {
                    if (Foot.Intersects(blocks[i].Roof) && Velocity.Y > 0)
                    {
                        Floor = blocks[i].Position.Y;
                    }
                }

                if (Position.Y >= Floor)
                {
                    OnGround   = true;
                    Velocity   = new Vector2(0, 0);
                    Position.Y = Floor + 1;
                }
            }


            //if onGround = false
            //if you collide with a brick, set Floor = top of brick & onGround = true & Velocity = 0 & position.Y = top of brick

            //!onGround
            //if you do NOT collide with any brick: set floor = 600, onGround = false
        }