157 lines
4.4 KiB
Rust
157 lines
4.4 KiB
Rust
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
pub mod components;
|
|
pub mod constants;
|
|
pub mod resources;
|
|
mod sidebar;
|
|
mod state;
|
|
pub mod systems;
|
|
pub mod vga_color;
|
|
|
|
use bracket_lib::prelude::*;
|
|
use components::{
|
|
monster::{color_for_kind, glyphs_for_kind, ticks_for_kind, MonsterKind},
|
|
Monster, Player, Position, Renderable,
|
|
};
|
|
use resources::map::TileType;
|
|
use resources::{Clock, LevelNumber, Map, ShowDebugInfo, SoundEffects, SoundOutput, Stats};
|
|
use specs::prelude::*;
|
|
use state::State;
|
|
use std::time::Instant;
|
|
|
|
use vga_color as vga;
|
|
|
|
fn main() -> BError {
|
|
let context = BTermBuilder::simple(80, 25)?
|
|
.with_fps_cap(60.0)
|
|
.with_title("Kroz")
|
|
.with_tile_dimensions(8, 16)
|
|
.build()?;
|
|
|
|
let mut ss = SoundOutput::new();
|
|
let sound_effects = SoundEffects::new(&ss);
|
|
ss.play_sound(sound_effects.startup.clone());
|
|
|
|
let mut ecs = World::new();
|
|
|
|
ecs.insert(ss);
|
|
ecs.insert(LevelNumber(0));
|
|
ecs.insert(ShowDebugInfo(false));
|
|
ecs.insert(Clock {
|
|
last_ticked: Instant::now(),
|
|
has_ticked: false,
|
|
ticks: 0,
|
|
});
|
|
ecs.insert(sound_effects);
|
|
ecs.insert(Stats {
|
|
score: 1290,
|
|
gems: 14,
|
|
whips: 7,
|
|
teleports: 0,
|
|
keys: 0,
|
|
});
|
|
|
|
ecs.register::<Position>();
|
|
ecs.register::<Renderable>();
|
|
ecs.register::<Monster>();
|
|
ecs.register::<Player>();
|
|
|
|
let mut map = Map::new();
|
|
let mut rng = RandomNumberGenerator::new();
|
|
for (i, tile) in &mut map.get_tiles().iter().enumerate() {
|
|
if rng.roll_dice(1, 16) < 2 && *tile == TileType::Floor {
|
|
let position = map.index_to_point2d(i);
|
|
let kind = MonsterKind::Slow;
|
|
ecs.create_entity()
|
|
.with(Position {
|
|
x: position.x,
|
|
y: position.y,
|
|
})
|
|
.with(Renderable {
|
|
glyph: *rng.random_slice_entry(&glyphs_for_kind(kind)).unwrap(),
|
|
fg: color_for_kind(kind),
|
|
bg: RGB::named(vga::BLACK),
|
|
})
|
|
.with(Monster {
|
|
kind,
|
|
ticks_until_move: ticks_for_kind(kind),
|
|
})
|
|
.build();
|
|
}
|
|
}
|
|
|
|
{
|
|
let entities = ecs.entities();
|
|
let positions = ecs.read_storage::<Position>();
|
|
let monsters = ecs.read_storage::<Monster>();
|
|
|
|
for (entity, _monster, pos) in (&entities, &monsters, &positions).join() {
|
|
map.set_tile_at(Point { x: pos.x, y: pos.y }, TileType::Monster(entity));
|
|
}
|
|
}
|
|
|
|
let player_start_pos = Point { x: 40, y: 22 };
|
|
|
|
ecs.create_entity()
|
|
.with(Position {
|
|
x: player_start_pos.x,
|
|
y: player_start_pos.y,
|
|
})
|
|
.with(Renderable {
|
|
glyph: to_cp437('☻'),
|
|
fg: RGB::named(vga::YELLOW_BRIGHT),
|
|
bg: RGB::named(vga::BLACK),
|
|
})
|
|
.with(Player {
|
|
last_moved: Instant::now(),
|
|
})
|
|
.build();
|
|
|
|
map.set_tile_at(player_start_pos, TileType::Player);
|
|
|
|
ecs.insert(map);
|
|
|
|
ecs.insert(Point::new(player_start_pos.x, player_start_pos.y));
|
|
|
|
// for i in 0..10 {
|
|
// gs.ecs
|
|
// .create_entity()
|
|
// .with(Position { x: i * 7, y: 20 })
|
|
// .with(Renderable {
|
|
// glyph: to_cp437('Ä'),
|
|
// fg: RGB::named(vga::RED_BRIGHT),
|
|
// bg: RGB::named(vga::BLACK),
|
|
// })
|
|
// .with(LeftMover {})
|
|
// .build();
|
|
// }
|
|
|
|
// let descent_sounds: Vec<Sound> = (20..100)
|
|
// .rev()
|
|
// .flat_map(|x| {
|
|
// (1..10).rev().flat_map(move |y| {
|
|
// vec![Sound {
|
|
// sound_type: SoundType::Tone(x * y * y),
|
|
// duration: Duration::from_millis((y as f64 / 1.5) as u64),
|
|
// }]
|
|
// })
|
|
// })
|
|
// .collect();
|
|
|
|
// let descent_effect = gs.sound_system.render_sound_effect(SoundEffect {
|
|
// sounds: descent_sounds,
|
|
// });
|
|
|
|
// let _ = gs.sound_system.play_sound(descent_effect);
|
|
|
|
// let effect = gs.sound_system.render_sound_effect(SoundEffect {
|
|
// sounds: vec![Sound {
|
|
// sound_type: SoundType::Tone(3500),
|
|
// duration: Duration::from_millis(4000),
|
|
// }],
|
|
// });
|
|
|
|
// let _ = gs.sound_system.play_sound(effect);
|
|
|
|
main_loop(context, State::new(ecs))
|
|
}
|