kroz-rs/src/input/mod.rs

62 lines
2.3 KiB
Rust

use bracket_lib::prelude::*;
use hecs::World;
use crate::resources::*;
mod player;
pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
if resources.flashing_message.is_some() {
if bterm.key.is_some() {
resources.flashing_message = None;
}
} else {
match bterm.key {
None => {}
Some(key) => match key {
VirtualKeyCode::Left | VirtualKeyCode::J => {
player::try_move(-1, 0, world, resources);
}
VirtualKeyCode::U | VirtualKeyCode::Home => {
player::try_move(-1, -1, world, resources)
}
VirtualKeyCode::Up | VirtualKeyCode::I => {
player::try_move(0, -1, world, resources);
}
VirtualKeyCode::O | VirtualKeyCode::PageUp => {
player::try_move(1, -1, world, resources)
}
VirtualKeyCode::Right | VirtualKeyCode::K => {
player::try_move(1, 0, world, resources);
}
VirtualKeyCode::Comma | VirtualKeyCode::PageDown => {
player::try_move(1, 1, world, resources)
}
VirtualKeyCode::Down | VirtualKeyCode::M => {
player::try_move(0, 1, world, resources);
}
VirtualKeyCode::N | VirtualKeyCode::End => {
player::try_move(-1, 1, world, resources)
}
VirtualKeyCode::W => {
player::whip(world, resources);
}
VirtualKeyCode::D => {
resources.show_debug_info = !resources.show_debug_info;
}
VirtualKeyCode::Escape | VirtualKeyCode::Q => {
bterm.quit();
}
VirtualKeyCode::P => {
resources.flashing_message =
Some(FlashingMessage::from("Press any key to resume game."));
}
_ => {
resources
.sound_output
.play_sound(resources.sound_effects.bad_key.clone());
}
},
}
}
}