Upgrade to most recent version of Rust. Still doesn't work.

This commit is contained in:
2015-11-16 10:44:01 +01:00
parent b91ae6cb29
commit 5d5a693508
8 changed files with 239 additions and 225 deletions

View File

@@ -4,13 +4,13 @@ use sdl2::rect::Rect;
pub struct Camera {
x: i32,
y: i32,
w: i32,
h: i32,
w: u32,
h: u32,
bounding: Rect
}
impl Camera {
pub fn new(x: i32, y: i32, w: i32, h: i32, bounding: Rect) -> Camera {
pub fn new(x: i32, y: i32, w: u32, h: u32, bounding: Rect) -> Camera {
Camera {
x: x,
y: y,
@@ -21,19 +21,19 @@ impl Camera {
}
pub fn center(&mut self, object: &Rect) {
let mut x = (object.x + object.w / 2) - (self.w / 2);
let mut y = (object.y + object.h / 2) - (self.h / 2);
let mut x = (object.x() + object.width() as i32 / 2) - (self.w as i32 / 2);
let mut y = (object.y() + object.height() as i32 / 2) - (self.h as i32 / 2);
if x < self.bounding.x {
x = self.bounding.x;
} else if x + self.w > self.bounding.w {
x = self.bounding.w - self.w;
if x < self.bounding.x() {
x = self.bounding.x();
} else if x + self.w as i32 > self.bounding.width() as i32 {
x = (self.bounding.width() - self.w) as i32;
}
if y < self.bounding.y {
y = self.bounding.y;
} else if y + self.h > self.bounding.h {
y = self.bounding.h - self.h;
if y < self.bounding.y() {
y = self.bounding.y();
} else if y + self.h as i32 > self.bounding.height() as i32 {
y = (self.bounding.height() - self.h) as i32;
}
self.x = x;
@@ -41,6 +41,6 @@ impl Camera {
}
pub fn to_rect(&self) -> Rect {
Rect::new(self.x, self.y, self.w, self.h)
Rect::new_unwrap(self.x, self.y, self.w, self.h)
}
}