fn resize(&mut self, event: ResizeEvent) {
        if let Some(size) = event.size {
            // New bounds.
            self.bounds = Self::make_bounds(size);

            if self.snake.saturate_at_bounds(self.bounds) {
                // We will consider that the game is lost if snake gets outside
                // of the plane when resizing.
                self.state = State::Ended(EndKind::Loss);
            }
            if !self.food.in_bounds(self.bounds) {
                // If the food is outside of the plane, regenerates.
                self.food.regenerate(&self.snake, self.bounds);
            }
        } else {
            // Screen size is not valid? Save this as a bad screen state.
            self.state = State::BadScreen;
        }
    }
/// Resizes the game state about screen size.
Resizes the game state about screen size.
Resizes the game state about screen size .
fn resize(&mut self, event: ResizeEvent) {
        if let Some(size) = event.size {
            // New bounds.
            self.bounds = Self::make_bounds(size);
            if self.snake.saturate_at_bounds(self.bounds) {
                // We will consider that the game is lost if snake gets outside
                // of the plane when resizing.
                self.state = State::Ended(EndKind::Loss);
            }
            if !self.food.in_bounds(self.bounds) {
                // If the food is outside of the plane, regenerates.
                self.food.regenerate(&self.snake, self.bounds);
            }
        } else {
            // Screen size is not valid? Save this as a bad screen state.
            self.state = State::BadScreen;
        }
    }
fn resize ( & mut self , event : ResizeEvent ) { if let Some ( size ) = event . size { // New bounds. self . bounds = Self :: make_bounds ( size ) ; if self . snake . saturate_at_bounds ( self . bounds ) { // We will consider that the game is lost if snake gets outside // of the plane when resizing. self . state = State :: Ended ( EndKind :: Loss ) ; } if ! self . food . in_bounds ( self . bounds ) { // If the food is outside of the plane, regenerates. self . food . regenerate ( & self . snake , self . bounds ) ; } } else { // Screen size is not valid? Save this as a bad screen state. self . state = State :: BadScreen ; } }
Resizes the game state about screen size.
Resizes the game state about screen size .
&mut self
event
ResizeEvent
&mut self
event
ResizeEvent