aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: ab93eb5adfe6e77812bd3c4a8dde7088884f05a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
extern crate rand;
extern crate pancurses;

#[macro_use]
extern crate text_io;

mod state;
mod entities;
mod world;
mod tiling;

use entities::Player;
use pancurses::{
    initscr,
    endwin,
    Input,
    noecho
};
use std::env;
use state::State;
use world::{Dungeon};

fn get_player_name() -> String {
    match env::var_os("USER") {
        Some(val) => val.into_string().unwrap(),
        None => String::from("Kshar")
    }
}

fn main() {
    let window = initscr();

    let mut state = State::new(
        Player::new(
            get_player_name(),
            "Warrior".to_string(),
            30,
            10,
            10,
            20,
            1,
            (0, 0)
        ),
        Dungeon::new(window.get_max_x() as usize, window.get_max_y() as usize, 5),
    );

    state.init();

    window.keypad(true);
    noecho();
    
    loop {
        // update actors
        
        state.render_level(&window);

        // update character
        state.show_character(&window);

        // 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 => (),
        }
        // actors actions (normally attack / interact if on same location as the character)
    }
    endwin();
}