aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs73
1 files changed, 25 insertions, 48 deletions
diff --git a/src/main.rs b/src/main.rs
index f7e7f0f..12e92c9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,67 +4,44 @@ extern crate pancurses;
#[macro_use]
extern crate text_io;
+mod state;
mod entities;
mod world;
mod tiling;
-use entities::{Character, Player, Entity};
-use pancurses::{Window, initscr, endwin, Input, noecho};
-use world::{Dungeon, Level, Generatable};
-use tiling::TileType;
+use entities::Player;
+use pancurses::{
+ initscr,
+ endwin,
+ Input,
+ noecho
+};
+use state::State;
+use world::Dungeon;
-fn tile_to_str(tile: &TileType) -> &str {
- match tile {
- TileType::Floor => ".",
- TileType::Wall => "#",
- TileType::Empty => " ",
- TileType::StairsDown => ">",
- TileType::StairsUp => "<",
- TileType::Character => "@",
- _ => "?"
- }
-}
-
-fn draw_block(window: &Window, block: &TileType) {
- window.printw(tile_to_str(block));
-}
-
-fn render_level(window: &Window, level: &Level) {
- let grid = level.to_tilegrid().unwrap();
-
- for (linenum, line) in grid.raw_data().iter().enumerate() {
- for block in line.iter() {
- draw_block(&window, block);
- }
- window.mv(linenum as i32, 0);
- }
-}
fn main() {
let window = initscr();
- let mut level = 0;
- let mut dungeon = Dungeon::new(
- window.get_max_x() as usize,
- window.get_max_y() as usize - 2,
- 5
+ let mut state = State::new(
+ Player::new(
+ "Kshar".to_string(),
+ "Warrior".to_string(),
+ 30,
+ 10,
+ 10,
+ 20,
+ (0, 0)
+ ),
+ Dungeon::new(window.get_max_x() as usize, window.get_max_y() as usize, 5),
);
- dungeon.generate();
- let start_location = dungeon.levels[0].get_start_point();
+ state.init();
- let mut character: Character = Character::new(
- "Kshar".to_string(),
- "Warror".to_string(),
- 30,
- 10,
- 10,
- 20,
- start_location
- );
- character.place(start_location);
+ // Dump the whole dungeon structure in terminal for debugging
+ state.debug();
- render_level(&window, &dungeon.levels[0]);
+ state.render_level(&window);
window.keypad(true);
noecho();