/// Move the coordinates and prevents leaving the level,
/// or collide with other coordinates, except of the camera. Also checks, if
/// field on new coordinate is passable
Move the coordinates and prevents leaving the level,
or collide with other coordinates, except of the camera. Also checks, if
field on new coordinate is passable
Move the coordinates and prevents leaving the level or collide with other coordinates except of the camera . Also checks if field on new coordinate is passable
pub fn move_coord_without_cam(&mut self,
                                  dx: i64,
                                  dy: i64,
                                  mut buf_x: u64,
                                  mut buf_y: u64,
                                  level: &mut Level) {
        // if the camera is bigger as the world,
        buf_x = if (level.get_width() as u64) < buf_x {
            level.get_width() as u64
        } else {
            buf_x
        };
        buf_y = if (level.get_height() as u64) < buf_y {
            level.get_height() as u64
        } else {
            buf_y
        };
        // checks leaving level
        let new_x = if (self.x as i64 + dx) < 0 {
            0
        } else if (self.x as i64 + dx) as u64 >= level.get_width() as u64 {
            level.get_width() as u64
        } else {
            (self.x as i64 + dx) as u64
        };
        let new_y = if (self.y as i64 + dy) < 0 {
            0
        } else if (self.y as i64 + dy) as u64 >= level.get_height() as u64 {
            level.get_height() as u64
        } else {
            (self.y as i64 + dy) as u64
        };
        /* player not at border */
        /* Check collision with unpassable fields, not with camera! (dx = dy = 0) */
        if dx != 0 || dy != 0 {
            let next_field =
                level.get_field_at((self.x as i64 + dx) as usize, (self.y as i64 + dy) as usize);
            if !next_field.check_passable() {
                return;
            }
        }
        /* Check end */
        if dx != 0 || dy != 0 {
            /* Update old position in field */
            level.get_data()[self.x as usize][self.y as usize].free_fieldstatus();
        }
        // sets coordinates after last checks
        // prevent Level-leaving
        self.x = if new_x < buf_x {
            buf_x
        } else if new_x > (level.get_width() as u64) - buf_x - 1 {
            level.get_width() as u64 - buf_x - 1
        } else {
            new_x
        };
        self.y = if new_y < buf_y {
            buf_y
        } else if new_y > (level.get_height() as u64) - buf_y - 1 {
            level.get_height() as u64 - buf_y - 1
        } else {
            new_y
        };
    }
pub fn move_coord_without_cam ( & mut self , dx : i64 , dy : i64 , mut buf_x : u64 , mut buf_y : u64 , level : & mut Level ) { // if the camera is bigger as the world, buf_x = if ( level . get_width ( ) as u64 ) < buf_x { level . get_width ( ) as u64 } else { buf_x } ; buf_y = if ( level . get_height ( ) as u64 ) < buf_y { level . get_height ( ) as u64 } else { buf_y } ; // checks leaving level let new_x = if ( self . x as i64 + dx ) < 0 { 0 } else if ( self . x as i64 + dx ) as u64 >= level . get_width ( ) as u64 { level . get_width ( ) as u64 } else { ( self . x as i64 + dx ) as u64 } ; let new_y = if ( self . y as i64 + dy ) < 0 { 0 } else if ( self . y as i64 + dy ) as u64 >= level . get_height ( ) as u64 { level . get_height ( ) as u64 } else { ( self . y as i64 + dy ) as u64 } ; /* player not at border */ /* Check collision with unpassable fields, not with camera! (dx = dy = 0) */ if dx != 0 || dy != 0 { let next_field = level . get_field_at ( ( self . x as i64 + dx ) as usize , ( self . y as i64 + dy ) as usize ) ; if ! next_field . check_passable ( ) { return ; } } /* Check end */ if dx != 0 || dy != 0 { /* Update old position in field */ level . get_data ( ) [ self . x as usize ] [ self . y as usize ] . free_fieldstatus ( ) ; } // sets coordinates after last checks // prevent Level-leaving self . x = if new_x < buf_x { buf_x } else if new_x > ( level . get_width ( ) as u64 ) - buf_x - 1 { level . get_width ( ) as u64 - buf_x - 1 } else { new_x } ; self . y = if new_y < buf_y { buf_y } else if new_y > ( level . get_height ( ) as u64 ) - buf_y - 1 { level . get_height ( ) as u64 - buf_y - 1 } else { new_y } ; }
Move the coordinates and prevents leaving the level,
or collide with other coordinates, except of the camera.
Move the coordinates and prevents leaving the level or collide with other coordinates except of the camera .
&mut self
dx
i64
dy
i64
buf_x
u64
buf_y
u64
level
&mut Level