diff --git a/src/camera.rs b/src/camera.rs index 090476b..412479b 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -7,7 +7,7 @@ use super::data::prelude::*; const SHOW_BOUNDARIES: bool = false; -pub fn get_screen_bounds(ecs: &World, _ctx: &mut BTerm) -> (i32, i32, i32, i32, i32, i32) { +pub fn get_screen_bounds(ecs: &World) -> (i32, i32, i32, i32, i32, i32) { let player_pos = ecs.fetch::(); let map = ecs.fetch::(); let (x_chars, y_chars, mut x_offset, mut y_offset) = (VIEWPORT_W, VIEWPORT_H, 1, 10); @@ -35,7 +35,7 @@ pub fn get_screen_bounds(ecs: &World, _ctx: &mut BTerm) -> (i32, i32, i32, i32, pub fn render_camera(ecs: &World, ctx: &mut BTerm) { let map = ecs.fetch::(); - let (min_x, max_x, min_y, max_y, x_offset, y_offset) = get_screen_bounds(ecs, ctx); + let (min_x, max_x, min_y, max_y, x_offset, y_offset) = get_screen_bounds(ecs); // Render map let mut y = 0; diff --git a/src/gui/farlook.rs b/src/gui/farlook.rs index 045b172..1e29daa 100644 --- a/src/gui/farlook.rs +++ b/src/gui/farlook.rs @@ -19,7 +19,7 @@ pub enum FarlookResult { pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult { let runstate = gs.ecs.fetch::(); - let (_min_x, _max_x, _min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs, ctx); + let (_min_x, _max_x, _min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs); ctx.print_color( 1 + x_offset, diff --git a/src/gui/identify_menu.rs b/src/gui/identify_menu.rs index 14e0686..af7f9d3 100644 --- a/src/gui/identify_menu.rs +++ b/src/gui/identify_menu.rs @@ -122,7 +122,7 @@ pub fn identify(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option RunState ) -> RunState { - let (_, _, _, _, x_offset, y_offset) = camera::get_screen_bounds(ecs, ctx); + let (_, _, _, _, x_offset, y_offset) = camera::get_screen_bounds(ecs); ctx.print_color( 1 + x_offset, @@ -1191,7 +1191,7 @@ pub fn ranged_target( range: i32, aoe: i32 ) -> (TargetResult, Option) { - let (min_x, max_x, min_y, max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs, ctx); + let (min_x, max_x, min_y, max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs); let player_entity = gs.ecs.fetch::(); let player_pos = gs.ecs.fetch::(); let viewsheds = gs.ecs.read_storage::(); @@ -1231,10 +1231,7 @@ pub fn ranged_target( // Draw mouse cursor let mouse_pos = (x, y); - let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = camera::get_screen_bounds( - &gs.ecs, - ctx - ); + let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs); let x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W); let y = y.clamp(y_offset, y_offset - 1 + VIEWPORT_H); diff --git a/src/gui/remove_curse_menu.rs b/src/gui/remove_curse_menu.rs index f8d1f14..73003ca 100644 --- a/src/gui/remove_curse_menu.rs +++ b/src/gui/remove_curse_menu.rs @@ -117,7 +117,7 @@ pub fn remove_curse(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option< } // Get display args let width = get_max_inventory_width(&player_inventory); - let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs, ctx); + let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs); let (x, y) = (x_offset + 1, y_offset + 3); // Draw menu ctx.print_color( diff --git a/src/gui/tooltip.rs b/src/gui/tooltip.rs index 1aebed0..f05d790 100644 --- a/src/gui/tooltip.rs +++ b/src/gui/tooltip.rs @@ -64,7 +64,7 @@ impl Tooltip { #[rustfmt::skip] pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) { - let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(ecs, ctx); + let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(ecs); let map = ecs.fetch::(); let names = ecs.read_storage::(); let positions = ecs.read_storage::(); diff --git a/src/main.rs b/src/main.rs index 5ac6701..fc13f8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,5 +168,5 @@ fn idx_to_px(idx: usize, map: &Map) -> (f32, f32) { } fn update(app: &mut App, state: &mut State) { - // game loop + //state.tick(app); } diff --git a/src/player.rs b/src/player.rs index d91ba3b..35767a5 100644 --- a/src/player.rs +++ b/src/player.rs @@ -645,8 +645,21 @@ fn get_item(ecs: &mut World) -> RunState { } } -pub fn player_input(gs: &mut State, ctx: &mut BTerm, on_overmap: bool) -> RunState { - match ctx.key { +use notan::prelude::*; +pub fn player_input(gs: &mut State, ctx: &mut App, on_overmap: bool) -> RunState { + let key = &ctx.keyboard; + if key.was_pressed(KeyCode::Numpad4) { + return try_move_player(-1, 0, &mut gs.ecs); + } else if key.was_pressed(KeyCode::Numpad6) { + return try_move_player(1, 0, &mut gs.ecs); + } else if key.was_pressed(KeyCode::Numpad8) { + return try_move_player(0, -1, &mut gs.ecs); + } else if key.was_pressed(KeyCode::Numpad2) { + return try_move_player(0, 1, &mut gs.ecs); + } + return RunState::AwaitingInput; + + /*match ctx.key { None => { return RunState::AwaitingInput; } @@ -776,7 +789,7 @@ pub fn player_input(gs: &mut State, ctx: &mut BTerm, on_overmap: bool) -> RunSta } } } - return RunState::AwaitingInput; + return RunState::AwaitingInput;*/ } fn try_change_level(ecs: &mut World, backtracking: bool) -> Destination { diff --git a/src/states/state.rs b/src/states/state.rs index 530efd3..0a23297 100644 --- a/src/states/state.rs +++ b/src/states/state.rs @@ -162,33 +162,22 @@ impl State { } } -impl GameState for State { - fn tick(&mut self, ctx: &mut BTerm) { +impl State { + pub fn tick(&mut self, app: &mut App) { let mut new_runstate; { let runstate = self.ecs.fetch::(); new_runstate = *runstate; } // Clear screen - ctx.set_active_console(0); - ctx.cls(); - ctx.set_active_console(HP_BAR_LAYER); - ctx.cls(); - ctx.set_active_console(TEXT_LAYER); - ctx.cls(); - ctx.set_active_console(ENTITY_LAYER); - ctx.cls(); - ctx.set_active_console(TILE_LAYER); - ctx.cls(); - particle_system::particle_ticker(&mut self.ecs, ctx); + //particle_system::particle_ticker(&mut self.ecs, ctx); match new_runstate { - RunState::MainMenu { .. } => {} - RunState::CharacterCreation { .. } => {} + RunState::MainMenu { .. } | RunState::PreRun | RunState::CharacterCreation { .. } => {} _ => { // Draw map and ui - camera::render_camera(&self.ecs, ctx); - gui::draw_ui(&self.ecs, ctx); + //camera::render_camera(&self.ecs, ctx); + //gui::draw_ui(&self.ecs, ctx); } } @@ -217,7 +206,7 @@ impl GameState for State { } if can_act { let on_overmap = self.ecs.fetch::().overmap; - new_runstate = player_input(self, ctx, on_overmap); + new_runstate = player_input(self, app, on_overmap); } else { new_runstate = RunState::Ticking; } @@ -248,7 +237,7 @@ impl GameState for State { } } RunState::Farlook { .. } => { - let result = gui::show_farlook(self, ctx); + let result = gui::FarlookResult::Cancel; //gui::show_farlook(self, ctx); match result { gui::FarlookResult::NoResponse { x, y } => { new_runstate = RunState::Farlook { x, y }; @@ -259,7 +248,7 @@ impl GameState for State { } } RunState::ShowCheatMenu => { - let result = gui::show_cheat_menu(self, ctx); + let result = gui::CheatMenuResult::Cancel; //gui::show_cheat_menu(self, ctx); match result { gui::CheatMenuResult::Cancel => { new_runstate = RunState::AwaitingInput; @@ -302,7 +291,7 @@ impl GameState for State { } } RunState::ShowInventory => { - let result = gui::show_inventory(self, ctx); + let result = gui::ItemMenuResult::Cancel; //gui::show_inventory(self, ctx); match result.0 { gui::ItemMenuResult::Cancel => { new_runstate = RunState::AwaitingInput; @@ -316,7 +305,7 @@ impl GameState for State { let is_aoe = self.ecs.read_storage::(); let aoe_item = is_aoe.get(item_entity); let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = - camera::get_screen_bounds(&self.ecs, ctx); + camera::get_screen_bounds(&self.ecs); let ppos = self.ecs.fetch::(); if let Some(aoe_item) = aoe_item { new_runstate = RunState::ShowTargeting { @@ -477,7 +466,10 @@ impl GameState for State { } } RunState::CharacterCreation { .. } => { - let result = gui::character_creation(self, ctx); + let result = gui::CharCreateResult::Selected { + ancestry: gui::Ancestry::Human, + class: gui::Class::Fighter, + }; //gui::character_creation(self, ctx); match result { gui::CharCreateResult::NoSelection { ancestry, class } => { new_runstate = RunState::CharacterCreation { ancestry, class }; @@ -502,7 +494,7 @@ impl GameState for State { }; } RunState::GameOver => { - let result = gui::game_over(ctx); + let result = gui::YesNoResult::No; //gui::game_over(ctx); let write_to_morgue: Option = match result { gui::YesNoResult::NoSelection => None, gui::YesNoResult::No => Some(false), @@ -525,7 +517,7 @@ impl GameState for State { new_runstate = RunState::MapGeneration; } RunState::HelpScreen => { - let result = gui::show_help(ctx); + let result = gui::YesNoResult::Yes; //gui::show_help(ctx); match result { gui::YesNoResult::Yes => { gamelog::record_event(EVENT::LookedForHelp(1)); @@ -574,19 +566,9 @@ impl GameState for State { new_runstate = self.mapgen_next_state.unwrap(); } if self.mapgen_history.len() != 0 { - ctx.set_active_console(0); - ctx.cls(); - ctx.set_active_console(HP_BAR_LAYER); - ctx.cls(); - ctx.set_active_console(TEXT_LAYER); - ctx.cls(); - ctx.set_active_console(ENTITY_LAYER); - ctx.cls(); - ctx.set_active_console(TILE_LAYER); - ctx.cls(); - camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx); + //camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx); - self.mapgen_timer += ctx.frame_time_ms; + //self.mapgen_timer += ctx.frame_time_ms; if self.mapgen_timer > 300.0 { self.mapgen_timer = 0.0; self.mapgen_index += 1; @@ -605,6 +587,6 @@ impl GameState for State { damage_system::delete_the_dead(&mut self.ecs); - let _ = render_draw_buffer(ctx); + //let _ = render_draw_buffer(ctx); } }