pub fn check_move(
        &self,
        direction: Direction,
        map: &Map,
        players: &[Player],
        npcs: &[Box<dyn Enemy>],
        // In case of a move on two axes, we have to provide the result of the first move too!
        x_add: i64,
        y_add: i64,
    ) -> (i64, i64) {
        let info = self
            .action
            .get_specific_dimension(&self.texture_handler, direction);
        let x = self.x() + x_add;
        let y = self.y() + y_add;
        let (x_add, y_add) = match direction {
            Direction::Down
                if info.height() as i64 + y + 1 < map.y + MAP_SIZE as i64 * MAP_CASE_SIZE =>
            {
                (0, 1)
            }
            Direction::Up if y - 1 >= map.y => (0, -1),
            Direction::Left if x - 1 >= map.x => (-1, 0),
            Direction::Right
                if info.width() as i64 + x + 1 < map.x + MAP_SIZE as i64 * MAP_CASE_SIZE =>
            {
                (1, 0)
            }
            _ => return (0, 0),
        };

        fn call(
            self_id: Id,
            c: &Character,
            move_hitbox: &(u32, u32),
            x: i64,
            y: i64,
            width: u32,
            height: u32,
            direction: Direction,
        ) -> bool {
            if self_id == c.id {
                return true;
            }
            let self_x = x + (width / 2 - move_hitbox.0 / 2) as i64;
            let self_y = y + (height - move_hitbox.1) as i64;
            let other_width = c.move_hitbox.0;
            let other_height = c.move_hitbox.1;
            let other_x = c.x() + (c.width() / 2 - other_width / 2) as i64;
            let other_y = c.y() + (c.height() - other_height) as i64;

            let width = move_hitbox.0 as i64;
            let height = move_hitbox.1 as i64;

            !match direction {
                Direction::Down => {
                    self_x + width >= other_x
                        && self_x <= other_x + other_width as i64
                        && self_y + height + 1 >= other_y
                        && self_y + height <= other_y + other_height as i64
                }
                Direction::Up => {
                    self_x + width >= other_x
                        && self_x <= other_x + other_width as i64
                        && self_y >= other_y
                        && self_y - 1 <= other_y + other_height as i64
                }
                Direction::Right => {
                    self_x + width + 1 >= other_x
                        && self_x + width <= other_x + other_width as i64
                        && self_y + height >= other_y
                        && self_y <= other_y + other_height as i64
                }
                Direction::Left => {
                    self_x >= other_x
                        && self_x - 1 <= other_x + other_width as i64
                        && self_y + height >= other_y
                        && self_y <= other_y + other_height as i64
                }
            }
        }

        let self_x = x + x_add;
        let self_y = y + y_add;
        // NPC moves are a bit more restricted than players'.
        if if self.kind.is_player() {
            let width = self.width();
            let height = self.height();
            self.check_hitbox(self_x - map.x, self_y - map.y, &map.data, direction)
                && npcs.iter().all(|n| {
                    call(
                        self.id,
                        n.character(),
                        &self.move_hitbox,
                        self_x,
                        self_y,
                        width,
                        height,
                        direction,
                    )
                })
                && players.iter().all(|p| {
                    call(
                        self.id,
                        &p,
                        &self.move_hitbox,
                        self_x,
                        self_y,
                        width,
                        height,
                        direction,
                    )
                })
        } else {
            self.check_hitbox(self_x - map.x, self_y - map.y, &map.data, direction)
                && npcs
                    .iter()
                    .all(|n| self.check_character_move(self_x, self_y, n.character()))
                && players
                    .iter()
                    .all(|n| self.check_character_move(self_x, self_y, &n))
        } {
            (x_add, y_add)
        } else {
            (0, 0)
        }
    }
/// `x_add` and `y_add` are used in case you want to move in two directions at once, so when
/// checking the second direction, you actually already "moved" and don't check a bad position.
`x_add` and `y_add` are used in case you want to move in two directions at once, so when
checking the second direction, you actually already "moved" and don't check a bad position.
` x_add ` and ` y_add ` are used in case you want to move in two directions at once so when checking the second direction you actually already " moved " and don ' t check a bad position .
pub fn check_move(
        &self,
        direction: Direction,
        map: &Map,
        players: &[Player],
        npcs: &[Box<dyn Enemy>],
        // In case of a move on two axes, we have to provide the result of the first move too!
        x_add: i64,
        y_add: i64,
    ) -> (i64, i64) {
        let info = self
            .action
            .get_specific_dimension(&self.texture_handler, direction);
        let x = self.x() + x_add;
        let y = self.y() + y_add;
        let (x_add, y_add) = match direction {
            Direction::Down
                if info.height() as i64 + y + 1 < map.y + MAP_SIZE as i64 * MAP_CASE_SIZE =>
            {
                (0, 1)
            }
            Direction::Up if y - 1 >= map.y => (0, -1),
            Direction::Left if x - 1 >= map.x => (-1, 0),
            Direction::Right
                if info.width() as i64 + x + 1 < map.x + MAP_SIZE as i64 * MAP_CASE_SIZE =>
            {
                (1, 0)
            }
            _ => return (0, 0),
        };
        fn call(
            self_id: Id,
            c: &Character,
            move_hitbox: &(u32, u32),
            x: i64,
            y: i64,
            width: u32,
            height: u32,
            direction: Direction,
        ) -> bool {
            if self_id == c.id {
                return true;
            }
            let self_x = x + (width / 2 - move_hitbox.0 / 2) as i64;
            let self_y = y + (height - move_hitbox.1) as i64;
            let other_width = c.move_hitbox.0;
            let other_height = c.move_hitbox.1;
            let other_x = c.x() + (c.width() / 2 - other_width / 2) as i64;
            let other_y = c.y() + (c.height() - other_height) as i64;
            let width = move_hitbox.0 as i64;
            let height = move_hitbox.1 as i64;
            !match direction {
                Direction::Down => {
                    self_x + width >= other_x
                        && self_x <= other_x + other_width as i64
                        && self_y + height + 1 >= other_y
                        && self_y + height <= other_y + other_height as i64
                }
                Direction::Up => {
                    self_x + width >= other_x
                        && self_x <= other_x + other_width as i64
                        && self_y >= other_y
                        && self_y - 1 <= other_y + other_height as i64
                }
                Direction::Right => {
                    self_x + width + 1 >= other_x
                        && self_x + width <= other_x + other_width as i64
                        && self_y + height >= other_y
                        && self_y <= other_y + other_height as i64
                }
                Direction::Left => {
                    self_x >= other_x
                        && self_x - 1 <= other_x + other_width as i64
                        && self_y + height >= other_y
                        && self_y <= other_y + other_height as i64
                }
            }
        }
        let self_x = x + x_add;
        let self_y = y + y_add;
        // NPC moves are a bit more restricted than players'.
        if if self.kind.is_player() {
            let width = self.width();
            let height = self.height();
            self.check_hitbox(self_x - map.x, self_y - map.y, &map.data, direction)
                && npcs.iter().all(|n| {
                    call(
                        self.id,
                        n.character(),
                        &self.move_hitbox,
                        self_x,
                        self_y,
                        width,
                        height,
                        direction,
                    )
                })
                && players.iter().all(|p| {
                    call(
                        self.id,
                        &p,
                        &self.move_hitbox,
                        self_x,
                        self_y,
                        width,
                        height,
                        direction,
                    )
                })
        } else {
            self.check_hitbox(self_x - map.x, self_y - map.y, &map.data, direction)
                && npcs
                    .iter()
                    .all(|n| self.check_character_move(self_x, self_y, n.character()))
                && players
                    .iter()
                    .all(|n| self.check_character_move(self_x, self_y, &n))
        } {
            (x_add, y_add)
        } else {
            (0, 0)
        }
    }
pub fn check_move ( & self , direction : Direction , map : & Map , players : & [ Player ] , npcs : & [ Box < dyn Enemy > ] , // In case of a move on two axes, we have to provide the result of the first move too! x_add : i64 , y_add : i64 , ) -> ( i64 , i64 ) { let info = self . action . get_specific_dimension ( & self . texture_handler , direction ) ; let x = self . x ( ) + x_add ; let y = self . y ( ) + y_add ; let ( x_add , y_add ) = match direction { Direction :: Down if info . height ( ) as i64 + y + 1 < map . y + MAP_SIZE as i64 * MAP_CASE_SIZE => { ( 0 , 1 ) } Direction :: Up if y - 1 >= map . y => ( 0 , - 1 ) , Direction :: Left if x - 1 >= map . x => ( - 1 , 0 ) , Direction :: Right if info . width ( ) as i64 + x + 1 < map . x + MAP_SIZE as i64 * MAP_CASE_SIZE => { ( 1 , 0 ) } _ => return ( 0 , 0 ) , } ; fn call ( self_id : Id , c : & Character , move_hitbox : & ( u32 , u32 ) , x : i64 , y : i64 , width : u32 , height : u32 , direction : Direction , ) -> bool { if self_id == c . id { return true ; } let self_x = x + ( width / 2 - move_hitbox . 0 / 2 ) as i64 ; let self_y = y + ( height - move_hitbox . 1 ) as i64 ; let other_width = c . move_hitbox . 0 ; let other_height = c . move_hitbox . 1 ; let other_x = c . x ( ) + ( c . width ( ) / 2 - other_width / 2 ) as i64 ; let other_y = c . y ( ) + ( c . height ( ) - other_height ) as i64 ; let width = move_hitbox . 0 as i64 ; let height = move_hitbox . 1 as i64 ; ! match direction { Direction :: Down => { self_x + width >= other_x && self_x <= other_x + other_width as i64 && self_y + height + 1 >= other_y && self_y + height <= other_y + other_height as i64 } Direction :: Up => { self_x + width >= other_x && self_x <= other_x + other_width as i64 && self_y >= other_y && self_y - 1 <= other_y + other_height as i64 } Direction :: Right => { self_x + width + 1 >= other_x && self_x + width <= other_x + other_width as i64 && self_y + height >= other_y && self_y <= other_y + other_height as i64 } Direction :: Left => { self_x >= other_x && self_x - 1 <= other_x + other_width as i64 && self_y + height >= other_y && self_y <= other_y + other_height as i64 } } } let self_x = x + x_add ; let self_y = y + y_add ; // NPC moves are a bit more restricted than players'. if if self . kind . is_player ( ) { let width = self . width ( ) ; let height = self . height ( ) ; self . check_hitbox ( self_x - map . x , self_y - map . y , & map . data , direction ) && npcs . iter ( ) . all ( | n | { call ( self . id , n . character ( ) , & self . move_hitbox , self_x , self_y , width , height , direction , ) } ) && players . iter ( ) . all ( | p | { call ( self . id , & p , & self . move_hitbox , self_x , self_y , width , height , direction , ) } ) } else { self . check_hitbox ( self_x - map . x , self_y - map . y , & map . data , direction ) && npcs . iter ( ) . all ( | n | self . check_character_move ( self_x , self_y , n . character ( ) ) ) && players . iter ( ) . all ( | n | self . check_character_move ( self_x , self_y , & n ) ) } { ( x_add , y_add ) } else { ( 0 , 0 ) } }
`x_add` and `y_add` are used in case you want to move in two directions at once, so when
checking the second direction, you actually already "moved" and don't check a bad position.
` x_add ` and ` y_add ` are used in case you want to move in two directions at once so when checking the second direction you actually already " moved " and don ' t check a bad position .
&self
direction
Direction
map
&Map
players
&[Player]
npcs
&[Box<dyn Enemy>]
x_add
i64
y_add
i64