aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: bed0c8ddbe270a8b2ffc9868487c4ec9a5886aac (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
mod entities;
mod events;
mod state;
mod tiling;
mod viewport;
mod world;

use ignore_result::Ignore;
use simplelog::*;
use std::env;
use std::fs::File;

use entities::Player;
use events::ViewportEvent;
use state::State;
use viewport::{CrossTermViewPort, ViewPort};
use world::Dungeon;

const DUNGEON_SIZE_X: usize = 80;
const DUNGEON_SIZE_Y: usize = 24;
const DUNGEON_DEPTH: usize = 5;

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

fn main() {
    // Set up the debug logger only if required.
    if let Ok(_val) = env::var("DEBUG") {
        WriteLogger::init(
            LevelFilter::Debug,
            Config::default(),
            File::create("roguerust.log").unwrap(),
        )
        .unwrap();
    }

    let mut state = State::new(
        Player::new(player_name(), String::from("Warrior"), 30, 10, 10, 20),
        Dungeon::new(DUNGEON_SIZE_X, DUNGEON_SIZE_Y, DUNGEON_DEPTH),
    );
    let mut window = CrossTermViewPort::new();
    state.init();

    // Main loop, dispatches events and calls rendering routines. Don't
    // add any game logic here.
    loop {
        window.render_state(&state);

        if let Some(event) = window.wait_input() {
            match event {
                ViewportEvent::Quit => break,
                ViewportEvent::MovePlayer(direction) => state.move_player(direction).ignore(),
                ViewportEvent::DownStairs => match state.down_stairs() {
                    Ok(()) => (),
                    Err(info) => window.notify(info),
                },
                ViewportEvent::UpStairs => match state.up_stairs() {
                    Ok(()) => (),
                    Err(info) => window.notify(info),
                },
                _ => (),
            }
        }

        // actors actions (normally attack / interact if on same location as the character)
    }
}