pub fn new(body_tile: Tile, head_tile: Tile, bounds: Bounds) -> Self {
        // Initial length.
        let length = 3;
        // Random head distance from the y-borders.
        let distance = 10;

        // Initializes the random number generator (RNG).
        let mut rng = rand::thread_rng();
        // A random head for the snake.
        let head = Vec2 {
            x: rng.gen_range(bounds.min.x, bounds.max.x + 1),
            y: rng.gen_range(
                bounds.min.y + distance,
                bounds.max.y - (distance + length - 1),
            ),
        };

        // Initializes the segments, in vertical position.
        let mut segments = VecDeque::new();
        for i in 0 .. length {
            segments.push_back(Vec2 { y: head.y + i, ..head });
        }

        Self { direction: Direction::Up, segments, body_tile, head_tile }
    }
/// Initializes the snake, given the tiles for its head and body, as well
/// the bounds of the plane.
Initializes the snake, given the tiles for its head and body, as well
the bounds of the plane.
Initializes the snake given the tiles for its head and body as well the bounds of the plane .
pub fn new(body_tile: Tile, head_tile: Tile, bounds: Bounds) -> Self {
        // Initial length.
        let length = 3;
        // Random head distance from the y-borders.
        let distance = 10;
        // Initializes the random number generator (RNG).
        let mut rng = rand::thread_rng();
        // A random head for the snake.
        let head = Vec2 {
            x: rng.gen_range(bounds.min.x, bounds.max.x + 1),
            y: rng.gen_range(
                bounds.min.y + distance,
                bounds.max.y - (distance + length - 1),
            ),
        };
        // Initializes the segments, in vertical position.
        let mut segments = VecDeque::new();
        for i in 0 .. length {
            segments.push_back(Vec2 { y: head.y + i, ..head });
        }
        Self { direction: Direction::Up, segments, body_tile, head_tile }
    }
pub fn new ( body_tile : Tile , head_tile : Tile , bounds : Bounds ) -> Self { // Initial length. let length = 3 ; // Random head distance from the y-borders. let distance = 10 ; // Initializes the random number generator (RNG). let mut rng = rand :: thread_rng ( ) ; // A random head for the snake. let head = Vec2 { x : rng . gen_range ( bounds . min . x , bounds . max . x + 1 ) , y : rng . gen_range ( bounds . min . y + distance , bounds . max . y - ( distance + length - 1 ) , ) , } ; // Initializes the segments, in vertical position. let mut segments = VecDeque :: new ( ) ; for i in 0 .. length { segments . push_back ( Vec2 { y : head . y + i , .. head } ) ; } Self { direction : Direction :: Up , segments , body_tile , head_tile } }
Initializes the snake, given the tiles for its head and body, as well
the bounds of the plane.
Initializes the snake given the tiles for its head and body as well the bounds of the plane .
body_tile
Tile
head_tile
Tile
bounds
Bounds
body_tile
Tile
head_tile
Tile
bounds
Bounds