el_diablo/src/position.rs

33 lines
660 B
Rust
Raw Normal View History

2023-11-27 19:21:10 +01:00
#[derive(PartialEq, Debug)]
2023-11-08 06:52:20 +01:00
pub struct Position {
2023-11-27 19:21:10 +01:00
level: usize,
x: usize,
y: usize,
2023-11-08 06:52:20 +01:00
}
impl Position {
2023-11-27 19:21:10 +01:00
pub fn new(level: usize, x: usize, y: usize) -> Self {
2023-11-08 06:52:20 +01:00
Self {
level,
x,
y,
}
}
2023-11-27 19:21:10 +01:00
pub fn change(&mut self, dx: i16, dy: i16) {
self.x = ((self.x as i16) + dx) as usize;
self.y = ((self.y as i16) + dy) as usize;
}
pub fn set(&mut self, level: usize, x: usize, y: usize) {
self.level = level;
self.x = x;
self.y = y;
}
pub fn get_x(&self) -> usize {
self.x
}
pub fn get_y(&self) -> usize {
self.y
}
2023-11-08 06:52:20 +01:00
}