diff options
-rw-r--r-- | Cargo.lock | 6 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/main.rs | 21 | ||||
-rw-r--r-- | src/view.rs | 26 |
4 files changed, 31 insertions, 25 deletions
@@ -2,7 +2,7 @@ name = "roma" version = "0.1.0" dependencies = [ - "pancurses 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pancurses 0.11.0 (git+https://github.com/ihalila/pancurses)", "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -55,7 +55,7 @@ dependencies = [ [[package]] name = "pancurses" version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/ihalila/pancurses#8f81661687a32a5b0a1cb65b1bb7b46c9206b593" dependencies = [ "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -94,7 +94,7 @@ dependencies = [ "checksum libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "56cce3130fd040c28df6f495c8492e5ec5808fb4c9093c310df02b0c8f030148" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum ncurses 5.86.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e404cc633e25a50d3427c4202313a33375c0a559902cecce1dd2893dd226feb0" -"checksum pancurses 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "775e85872854c4921272744ec1135d09b5168be5a109e9cc020ee169db37aa2f" +"checksum pancurses 0.11.0 (git+https://github.com/ihalila/pancurses)" = "<none>" "checksum pdcurses-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "923a29f049a83da029e6e96d2c1de8a9e3ca7c41ab1d2a9e3ab2c85a27725cf2" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "61efcbcd9fa8d8fbb07c84e34a8af18a1ff177b449689ad38a6e9457ecc7b2ae" @@ -4,5 +4,6 @@ version = "0.1.0" authors = ["Tom Barrett <tombarrett@siu.edu>"] [dependencies] -pancurses = "0.11" +pancurses = { git = "https://github.com/ihalila/pancurses" } rand = "0.3" + diff --git a/src/main.rs b/src/main.rs index 81583b8..2e8ca3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,30 +31,37 @@ fn init() -> pancurses::Window { fn main() { let main = init(); - let mut map = Map::new(); let mut view = View::new(main.get_max_yx(), &map.window); - let cursor = Character::new('X', 3, Location{x:150,y:150}); - map.fill(); + let mut cursor = Character::new('X', 3, Location{x:150,y:150}); + let list = List::new(map.impassable.to_vec()); - list.draw(&map.window); - cursor.draw(&map.window); let paused = false; loop{ match main.getch() { - Some(Input::Character(c)) => break, + Some(Input::Character(c)) => { + match c { + 'h' => cursor.location.y -= 1, + 'l' => cursor.location.y += 1, + 'k' => cursor.location.x -= 1, + 'j' => cursor.location.x += 1, + 'q' => break, + _ => (), + } + }, _ => () } if !paused { list.action(); } + map.fill(); list.draw(&map.window); cursor.draw(&map.window); - view.center(cursor, map.window.get_max_yx()); + view.center(cursor, &map.window); } endwin(); diff --git a/src/view.rs b/src/view.rs index 51a052b..acd4807 100644 --- a/src/view.rs +++ b/src/view.rs @@ -12,7 +12,7 @@ pub struct View{ impl View{ pub fn new((x,y) : (i32, i32), map_window : &pancurses::Window) -> View { - let window = map_window.derwin(x,y,0,0).expect("help"); + let window = map_window.derwin(x,y,0,0).expect("Cannot create derwin."); View{ width : x, height : y, @@ -22,40 +22,38 @@ impl View{ } } - pub fn center(&mut self, character : Character, (hh, ww) : (i32,i32)) { - let mut rr = self.row; - let mut cc = self.col; + pub fn center(&mut self, character : Character, map_window : &pancurses::Window) { let r = character.location.x - self.height/2; let c = character.location.y - self.width/2; + + let (hh, ww) = map_window.get_max_yx(); if c + self.width >= ww { let delta = ww - (c + self.width); - cc = c + delta; + self.col = c + delta; } else { - cc = c; + self.col = c; } if r + self.height >= hh { let delta = hh - (r + self.height); - rr = r + delta; + self.row = r + delta; } else { - rr = r; + self.row = r; } if r < 0 { - rr = 0; + self.row = 0; } if c < 0 { - cc = 0; + self.col = 0; } - self.window.refresh(); - self.window.mv(rr, cc); - self.row = rr; - self.col = cc; + self.window.mvderwin(self.row, self.col); + map_window.touch(); self.window.refresh(); } } |