Ejemplo n.º 1
0
        public void Move()
        {
            // Move the head part
            Head.Position_X += Head.MovementDirection[0];
            Head.Position_Y += Head.MovementDirection[1];

            // Adapt head to the borders
            Head.AdaptOutOfBorder(Game.Game_Matrix);
            // Check if head colided with something
            CheckNewPositionForCollisions(Head);

            // go through parts, starting from the part after Head
            SnakePart current_part = Head.PrevPart;

            while (current_part != null)
            {
                // set last direction to movement direction
                current_part.LastDirection = current_part.MovementDirection;
                // If there is next part, get it's last movement direction and set it on this part
                current_part.FollowNext();
                // Move part
                current_part.Position_X += current_part.MovementDirection[0];
                current_part.Position_Y += current_part.MovementDirection[1];
                // Adapt the part if it crosses the border
                current_part.AdaptOutOfBorder(Game.Game_Matrix);
                // Update matrix for moved part
                UpdateMatrix(current_part);

                // get next part to move
                current_part = current_part.PrevPart;
            }

            Head.LastDirection = Head.MovementDirection;
        }