el_diablo/src/position.rs

35 lines
713 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;
}
2023-12-03 09:25:03 +01:00
pub fn get_level(&self) -> usize {
self.level
}
2023-11-27 19:21:10 +01:00
pub fn get_x(&self) -> usize {
self.x
}
2023-12-03 09:25:03 +01:00
pub fn get_y(&self) -> usize { self.y }
2023-11-08 06:52:20 +01:00
}