aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume <g@bitimplosion.com>2019-11-12 11:18:31 +0100
committerGitHub <noreply@github.com>2019-11-12 11:18:31 +0100
commite58d24c9a945b29ca9a4fd18647749941ba5e48b (patch)
tree47054a2ff776d9be280ecc693fbbd5db6324d79e
parent54b3362a04cbe607232c2a00edd61b5c948bb31e (diff)
parent4fef96e48eb0c2421fb86da9ee90c29b57ff05ef (diff)
Merge pull request #2 from lferro9000/add_main_loop
Add main loop for input and state changes
-rw-r--r--src/main.rs23
-rw-r--r--src/world.rs3
2 files changed, 22 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index e5fe385..06fcd0f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,7 +12,7 @@ use std::env;
use character::Player;
use character::Character;
use computer::Enemy;
-use pancurses::{Window, initscr, endwin};
+use pancurses::{Window, initscr, endwin, Input, noecho};
use world::{Dungeon, Level, Generable, TileType};
fn tile_to_str(tile: &TileType) -> &str {
@@ -22,6 +22,7 @@ fn tile_to_str(tile: &TileType) -> &str {
TileType::Empty => " ",
TileType::StairsDown => ">",
TileType::StairsUp => "<",
+ TileType::Character => "@",
_ => "?"
}
}
@@ -85,8 +86,24 @@ fn main() {
let window = initscr();
render_level(&window, &dungeon.levels[0]);
- window.refresh();
- window.getch();
+ loop {
+ // update actors
+ // update character
+ window.refresh();
+
+ // get input and execute it
+ match window.getch() {
+
+ Some(Input::Character('h')) => { window.addstr("q: quit\n"); },
+ // Some(Input::KeyDown) => { window.addstr("down\n"); },
+ // Some(Input::KeyUp) => { window.addch('b'); },
+ // Some(Input::KeyLeft) => { window.addch('c'); },
+ // Some(Input::KeyRight) => { window.addch('d'); },
+ Some(Input::Character('q')) => break,
+ Some(_) => (),
+ None => (),
+ }
+ }
endwin();
}
diff --git a/src/world.rs b/src/world.rs
index 23bed8a..24a4c31 100644
--- a/src/world.rs
+++ b/src/world.rs
@@ -8,7 +8,8 @@ pub enum TileType {
Wall,
Floor,
StairsUp,
- StairsDown
+ StairsDown,
+ Character,
}
enum CorridorType {