2022-01-06 13:07:53 -06:00
|
|
|
use std::process::exit;
|
|
|
|
|
|
|
|
use components::{register_all, CharRender, MobAction, Mobile, Player, Position, TurnTaker};
|
2021-12-18 12:22:46 -06:00
|
|
|
use game::{BranchConfig, DungeonLevel};
|
2021-12-18 12:06:50 -06:00
|
|
|
|
2022-01-06 13:07:53 -06:00
|
|
|
use pancurses::{endwin, initscr, noecho, Window};
|
|
|
|
use player::player_turn;
|
2022-01-02 12:56:42 -06:00
|
|
|
use specs::prelude::*;
|
2022-01-06 13:07:53 -06:00
|
|
|
use systems::{MobSystem, TimeSystem};
|
2022-01-02 12:56:42 -06:00
|
|
|
|
|
|
|
mod components;
|
2021-12-18 12:22:46 -06:00
|
|
|
mod game;
|
2022-01-06 13:07:53 -06:00
|
|
|
mod player;
|
2021-12-18 21:03:00 -06:00
|
|
|
mod rooms;
|
2022-01-02 12:56:42 -06:00
|
|
|
mod systems;
|
2022-01-01 18:19:55 -06:00
|
|
|
mod util;
|
2021-12-18 12:22:46 -06:00
|
|
|
|
2021-12-18 11:58:33 -06:00
|
|
|
fn main() {
|
2022-01-02 12:56:42 -06:00
|
|
|
let mut world = World::new();
|
|
|
|
|
|
|
|
register_all(&mut world);
|
2021-12-18 12:22:46 -06:00
|
|
|
|
|
|
|
let cfg = BranchConfig;
|
|
|
|
let level = DungeonLevel::new(&cfg);
|
|
|
|
|
2022-01-02 12:56:42 -06:00
|
|
|
world.insert(level);
|
|
|
|
|
|
|
|
world
|
|
|
|
.create_entity()
|
|
|
|
.with(Position { x: 5, y: 6 })
|
|
|
|
.with(CharRender { glyph: '@' })
|
2022-01-02 14:30:37 -06:00
|
|
|
.with(Player)
|
2022-01-06 13:07:53 -06:00
|
|
|
.with(Mobile {
|
|
|
|
next_action: MobAction::Nop,
|
|
|
|
})
|
2022-01-02 14:30:37 -06:00
|
|
|
.with(TurnTaker {
|
|
|
|
next: 0,
|
|
|
|
maximum: 10,
|
|
|
|
})
|
2022-01-02 12:56:42 -06:00
|
|
|
.build();
|
|
|
|
|
|
|
|
let mut dispatcher = DispatcherBuilder::new()
|
2022-01-06 13:07:53 -06:00
|
|
|
.with(TimeSystem, "time", &[])
|
|
|
|
.with(MobSystem, "mobs", &[])
|
2022-01-02 12:56:42 -06:00
|
|
|
.build();
|
2021-12-18 12:22:46 -06:00
|
|
|
|
2022-01-06 13:07:53 -06:00
|
|
|
let mut window = init_window();
|
|
|
|
|
2022-01-02 12:56:42 -06:00
|
|
|
loop {
|
2022-01-02 13:17:17 -06:00
|
|
|
dispatcher.dispatch(&world);
|
2022-01-06 13:07:53 -06:00
|
|
|
|
|
|
|
let players = world.read_storage::<Player>();
|
|
|
|
let turns = world.read_storage::<TurnTaker>();
|
|
|
|
|
|
|
|
if (&players, &turns).join().any(|(_plr, turn)| turn.next == 0) {
|
|
|
|
drop(players);
|
|
|
|
drop(turns);
|
|
|
|
player_turn(&mut world, &mut window);
|
|
|
|
} else {
|
|
|
|
drop(players);
|
|
|
|
drop(turns);
|
|
|
|
}
|
2022-01-02 12:56:42 -06:00
|
|
|
}
|
2021-12-18 11:58:33 -06:00
|
|
|
}
|
2022-01-06 13:07:53 -06:00
|
|
|
|
|
|
|
/// Initializes the terminal to accept user input, and creates a new
|
|
|
|
/// Window.
|
|
|
|
fn init_window() -> Window {
|
|
|
|
// Create a new window over the terminal.
|
|
|
|
let window = initscr();
|
|
|
|
|
|
|
|
// Enable keypad mode (off by default for historical reasons), so
|
|
|
|
// we can read special keycodes other than just characters.
|
|
|
|
window.keypad(true);
|
|
|
|
|
|
|
|
// Disable echoing so the user doesn't see flickering in the
|
|
|
|
// upper-left corner of the screen when they type a character.
|
|
|
|
noecho();
|
|
|
|
|
|
|
|
window
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Cleans everything up and exits the game.
|
|
|
|
fn quit() -> ! {
|
|
|
|
endwin();
|
|
|
|
|
|
|
|
exit(0)
|
|
|
|
}
|