pub fn process(&mut self, button_value: ButtonValue, button_state: ButtonState) {
        match button_state {
            ButtonState::Pressed => match button_value {
                ButtonValue::Up | ButtonValue::Down => self.vertical.push(button_value),
                ButtonValue::Left | ButtonValue::Right => self.horizontal.push(button_value),
                _ => (),
            },
            ButtonState::Released => match button_value {
                ButtonValue::Up | ButtonValue::Down => self.vertical.retain(|&x| x != button_value),
                ButtonValue::Left | ButtonValue::Right => {
                    self.horizontal.retain(|&x| x != button_value)
                }
                _ => (),
            },
        }
        // Set horizontal movement based on the stack
        if let Some(last_horiz) = self.horizontal.last() {
            match last_horiz {
                ButtonValue::Left => self.direction.x = -1.0,
                ButtonValue::Right => self.direction.x = 1.0,
                _ => {}
            }
        } else {
            self.direction.x = 0.0;
        }
        // Set vertical movement based on the stack
        if let Some(last_vert) = self.vertical.last() {
            match last_vert {
                ButtonValue::Up => self.direction.y = 1.0,
                ButtonValue::Down => self.direction.y = -1.0,
                _ => {}
            }
        } else {
            self.direction.y = 0.0;
        }
        // Normalize
        if self.direction.magnitude() > 0.01 {
            self.direction = self.direction.normalize();
        }
    }
/// Process one button, and update the direction vector.
Process one button, and update the direction vector.
Process one button and update the direction vector .
pub fn process(&mut self, button_value: ButtonValue, button_state: ButtonState) {
        match button_state {
            ButtonState::Pressed => match button_value {
                ButtonValue::Up | ButtonValue::Down => self.vertical.push(button_value),
                ButtonValue::Left | ButtonValue::Right => self.horizontal.push(button_value),
                _ => (),
            },
            ButtonState::Released => match button_value {
                ButtonValue::Up | ButtonValue::Down => self.vertical.retain(|&x| x != button_value),
                ButtonValue::Left | ButtonValue::Right => {
                    self.horizontal.retain(|&x| x != button_value)
                }
                _ => (),
            },
        }
        // Set horizontal movement based on the stack
        if let Some(last_horiz) = self.horizontal.last() {
            match last_horiz {
                ButtonValue::Left => self.direction.x = -1.0,
                ButtonValue::Right => self.direction.x = 1.0,
                _ => {}
            }
        } else {
            self.direction.x = 0.0;
        }
        // Set vertical movement based on the stack
        if let Some(last_vert) = self.vertical.last() {
            match last_vert {
                ButtonValue::Up => self.direction.y = 1.0,
                ButtonValue::Down => self.direction.y = -1.0,
                _ => {}
            }
        } else {
            self.direction.y = 0.0;
        }
        // Normalize
        if self.direction.magnitude() > 0.01 {
            self.direction = self.direction.normalize();
        }
    }
pub fn process ( & mut self , button_value : ButtonValue , button_state : ButtonState ) { match button_state { ButtonState :: Pressed => match button_value { ButtonValue :: Up | ButtonValue :: Down => self . vertical . push ( button_value ) , ButtonValue :: Left | ButtonValue :: Right => self . horizontal . push ( button_value ) , _ => ( ) , } , ButtonState :: Released => match button_value { ButtonValue :: Up | ButtonValue :: Down => self . vertical . retain ( | & x | x != button_value ) , ButtonValue :: Left | ButtonValue :: Right => { self . horizontal . retain ( | & x | x != button_value ) } _ => ( ) , } , } // Set horizontal movement based on the stack if let Some ( last_horiz ) = self . horizontal . last ( ) { match last_horiz { ButtonValue :: Left => self . direction . x = - 1.0 , ButtonValue :: Right => self . direction . x = 1.0 , _ => { } } } else { self . direction . x = 0.0 ; } // Set vertical movement based on the stack if let Some ( last_vert ) = self . vertical . last ( ) { match last_vert { ButtonValue :: Up => self . direction . y = 1.0 , ButtonValue :: Down => self . direction . y = - 1.0 , _ => { } } } else { self . direction . y = 0.0 ; } // Normalize if self . direction . magnitude ( ) > 0.01 { self . direction = self . direction . normalize ( ) ; } }
Process one button, and update the direction vector.
Process one button and update the direction vector .
&mut self
button_value
ButtonValue
button_state
ButtonState
&mut self
button_value
ButtonValue
button_state
ButtonState