Skip to content

Tutorials - Building 2D Games -Chapter 22: Snake Game Mechanics #219

@xiaodongYao

Description

@xiaodongYao
/// <summary>
/// Informs the slime to grow by one segment.
/// </summary>
public void Grow()
{
    // Capture the value of the tail segment
    SlimeSegment tail = _segments[_segments.Count - 1];

    // Create a new tail segment that is positioned a grid cell in the
    // reverse direction from the tail moving to the tail.
    SlimeSegment newTail = new SlimeSegment();
    newTail.At = tail.To + tail.ReverseDirection * _stride;
    newTail.To = tail.At;
    newTail.Direction = Vector2.Normalize(tail.At - newTail.At);

    // Add the new tail segment
    _segments.Add(newTail);
}

I encountered a confusing point while learning the 2D game tutorial on the official website. In Chapter 22: Snake Game Mechanics, in the Growth method of slime, newTail.At = tail.To + tail.ReverseDirection * _stride; doesn't this make newTail.At equal to tail.At?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions