aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 599c65ce537f69ae949c3328bf54545f6068078e (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
extern crate rand;
extern crate pancurses;

extern crate text_io;

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

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


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

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

    state.init();

    window.keypad(true);
    noecho();

    state.render_level(&window);

    loop {
        // update
        state.render_entities(&window);

        state.render_player(&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();
}