From 6148c0608770fd65d29838420b512bf46b310f2e Mon Sep 17 00:00:00 2001 From: logaritmisk Date: Fri, 4 Dec 2015 16:45:38 +0100 Subject: [PATCH] Did things I don't remember :'( --- src/camera.rs | 24 ++++++++++++------------ src/main.rs | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 2aeffd1..a8a2a05 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -4,36 +4,36 @@ use sdl2::rect::Rect; pub struct Camera { x: i32, y: i32, - w: u32, - h: u32, + width: u32, + height: u32, bounding: Rect } impl Camera { - pub fn new(x: i32, y: i32, w: u32, h: u32, bounding: Rect) -> Camera { + pub fn new(x: i32, y: i32, width: u32, height: u32, bounding: Rect) -> Camera { Camera { x: x, y: y, - w: w, - h: h, + width: width, + height: height, bounding: bounding } } pub fn center(&mut self, object: &Rect) { - 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); + let mut x = (object.x() + object.width() as i32 / 2) - (self.width as i32 / 2); + let mut y = (object.y() + object.height() as i32 / 2) - (self.height as i32 / 2); 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; + } else if x + self.width as i32 > self.bounding.width() as i32 { + x = (self.bounding.width() - self.width) as i32; } 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; + } else if y + self.height as i32 > self.bounding.height() as i32 { + y = (self.bounding.height() - self.height) as i32; } self.x = x; @@ -41,6 +41,6 @@ impl Camera { } pub fn to_rect(&self) -> Rect { - Rect::new_unwrap(self.x, self.y, self.w, self.h) + Rect::new_unwrap(self.x, self.y, self.width, self.height) } } diff --git a/src/main.rs b/src/main.rs index a0ff4ea..57eb06e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ extern crate sdl2_image; use std::path::Path; -use std::thread::sleep_ms; +use std::thread::sleep; use std::cell::RefCell; use sdl2_image::LoadTexture; @@ -16,7 +16,7 @@ use sdl2::render::{Renderer, Texture}; use tile::Layer; use camera::Camera; -use player::Player; +// use player::Player; use keyboard::KeyboardHandler; use sprite::{Sprite, StaticSprite, AnimatedSprite}; @@ -549,7 +549,7 @@ fn main() { renderer.present(); - sleep_ms(5); + sleep(std::time::Duration::from_millis(5)); } sdl2_image::quit();