initial commit
using rltk
This commit is contained in:
parent
40a2ac07be
commit
d3a09df7a8
29 changed files with 3323 additions and 0 deletions
21
src/rect.rs
Normal file
21
src/rect.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
pub struct Rect {
|
||||
pub x1: i32,
|
||||
pub x2: i32,
|
||||
pub y1: i32,
|
||||
pub y2: i32,
|
||||
}
|
||||
|
||||
impl Rect {
|
||||
pub fn new(x: i32, y: i32, w: i32, h: i32) -> Rect {
|
||||
Rect { x1: x, y1: y, x2: x + w, y2: y + h }
|
||||
}
|
||||
|
||||
//Returns true if this overlaps with other
|
||||
pub fn intersect(&self, other: &Rect) -> bool {
|
||||
self.x1 <= other.x2 && self.x2 >= other.x1 && self.y1 <= other.y2 && self.y2 >= other.y1
|
||||
}
|
||||
|
||||
pub fn centre(&self) -> (i32, i32) {
|
||||
((self.x1 + self.x2) / 2, (self.y1 + self.y2) / 2)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue