2022-01-06 13:07:53 -06:00
|
|
|
use components::{register_all, CharRender, MobAction, Mobile, Player, Position, TurnTaker};
|
2022-03-03 12:21:32 -06:00
|
|
|
use io::init_window;
|
2022-03-27 17:56:23 -05:00
|
|
|
use level::{DungeonLevel, LEVEL_SIZE};
|
2021-12-18 12:06:50 -06:00
|
|
|
|
2022-01-06 13:07:53 -06:00
|
|
|
use player::player_turn;
|
2022-01-15 14:57:24 -06:00
|
|
|
use rand::thread_rng;
|
2022-01-02 12:56:42 -06:00
|
|
|
use specs::prelude::*;
|
2022-03-27 18:05:23 -05:00
|
|
|
use systems::build_dispatcher;
|
2022-01-02 12:56:42 -06:00
|
|
|
|
|
|
|
mod components;
|
2022-03-03 12:21:32 -06:00
|
|
|
mod io;
|
2022-01-10 19:33:45 -06:00
|
|
|
mod level;
|
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;
|
2022-01-15 20:15:17 -06:00
|
|
|
mod visibility;
|
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
|
|
|
|
2022-01-15 14:57:24 -06:00
|
|
|
let level = DungeonLevel::generate_level(&mut world, &mut thread_rng());
|
2022-01-15 14:49:15 -06:00
|
|
|
let spawn_pos = level.upstairs[0];
|
2021-12-18 12:22:46 -06:00
|
|
|
|
2022-01-02 12:56:42 -06:00
|
|
|
world.insert(level);
|
|
|
|
|
|
|
|
world
|
|
|
|
.create_entity()
|
2022-03-27 17:56:23 -05:00
|
|
|
.with(Position::from(spawn_pos))
|
2022-01-02 12:56:42 -06:00
|
|
|
.with(CharRender { glyph: '@' })
|
2022-03-27 17:56:23 -05:00
|
|
|
.with(Player {
|
|
|
|
known_cells: (0..LEVEL_SIZE.1)
|
|
|
|
.map(|_| (0..LEVEL_SIZE.0).map(|_| false).collect())
|
|
|
|
.collect(),
|
|
|
|
})
|
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();
|
|
|
|
|
2022-03-27 18:05:23 -05:00
|
|
|
let mut dispatcher = build_dispatcher();
|
2021-12-18 12:22:46 -06:00
|
|
|
|
2022-03-03 13:08:08 -06:00
|
|
|
let mut window = match init_window() {
|
|
|
|
Ok(window) => window,
|
|
|
|
Err(err) => {
|
|
|
|
println!("Error initializing window: {}", err);
|
|
|
|
return;
|
2022-03-27 17:56:23 -05:00
|
|
|
}
|
2022-03-03 13:08:08 -06:00
|
|
|
};
|
2022-01-06 13:07:53 -06:00
|
|
|
|
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
|
|
|
|
2022-01-06 16:57:20 -06:00
|
|
|
if (
|
|
|
|
&world.read_storage::<Player>(),
|
|
|
|
&world.read_storage::<TurnTaker>(),
|
|
|
|
)
|
|
|
|
.join()
|
|
|
|
.any(|(_plr, turn)| turn.next == 0)
|
|
|
|
{
|
2022-01-06 13:07:53 -06:00
|
|
|
player_turn(&mut world, &mut window);
|
|
|
|
}
|
2022-01-02 12:56:42 -06:00
|
|
|
}
|
2021-12-18 11:58:33 -06:00
|
|
|
}
|