diff --git a/resources/curses11x20.png b/resources/curses11x20.png new file mode 100644 index 0000000..5f5e1e5 Binary files /dev/null and b/resources/curses11x20.png differ diff --git a/resources/curses12x24.png b/resources/curses12x24.png index af280d7..4504d0a 100644 Binary files a/resources/curses12x24.png and b/resources/curses12x24.png differ diff --git a/resources/curses16x16.pdn b/resources/curses16x16.pdn new file mode 100644 index 0000000..34d5704 Binary files /dev/null and b/resources/curses16x16.pdn differ diff --git a/resources/healthbar11x2.png b/resources/healthbar11x2.png new file mode 100644 index 0000000..96fb67c Binary files /dev/null and b/resources/healthbar11x2.png differ diff --git a/resources/healthbar22x2.png b/resources/healthbar22x2.png new file mode 100644 index 0000000..daa15d1 Binary files /dev/null and b/resources/healthbar22x2.png differ diff --git a/resources/nagidal22x20_centred.png b/resources/nagidal22x20_centred.png new file mode 100644 index 0000000..1383fb9 Binary files /dev/null and b/resources/nagidal22x20_centred.png differ diff --git a/resources/nagidal22x22_centred.png b/resources/nagidal22x22_centred.png new file mode 100644 index 0000000..f941b27 Binary files /dev/null and b/resources/nagidal22x22_centred.png differ diff --git a/resources/nagidal24x24.png b/resources/nagidal24x24.png index 8c7c82b..2d4aba9 100644 Binary files a/resources/nagidal24x24.png and b/resources/nagidal24x24.png differ diff --git a/src/ai/approach_ai_system.rs b/src/ai/approach_ai_system.rs index 18bc43d..5796463 100644 --- a/src/ai/approach_ai_system.rs +++ b/src/ai/approach_ai_system.rs @@ -39,18 +39,35 @@ impl<'a> System<'a> for ApproachAI { &turns, ).join() { turn_done.push(entity); - let target_idxs = if let Some(paths) = get_adjacent_unblocked(&map, approach.idx as usize) { + let target_idxs = if + let Some(paths) = get_adjacent_unblocked(&map, approach.idx as usize) + { paths } else { continue; }; let mut path: Option = None; + let mut curr_abs_diff = 100; let idx = map.xy_idx(pos.x, pos.y); for tar_idx in target_idxs { let potential_path = rltk::a_star_search(idx, tar_idx, &mut *map); if potential_path.success && potential_path.steps.len() > 1 { - if path.is_none() || potential_path.steps.len() < path.as_ref().unwrap().steps.len() { + if + path.is_none() || + potential_path.steps.len() < path.as_ref().unwrap().steps.len() + { path = Some(potential_path); + let (x1, y1) = (pos.x, pos.y); + let (x2, y2) = ((tar_idx as i32) % map.width, (tar_idx as i32) / map.width); + curr_abs_diff = i32::abs(x2 - x1) + i32::abs(y2 - y1); + } else if potential_path.steps.len() == path.as_ref().unwrap().steps.len() { + let (x1, y1) = (pos.x, pos.y); + let (x2, y2) = ((tar_idx as i32) % map.width, (tar_idx as i32) / map.width); + let abs_diff = i32::abs(x2 - x1) + i32::abs(y2 - y1); + if abs_diff < curr_abs_diff { + path = Some(potential_path); + curr_abs_diff = abs_diff; + } } } } diff --git a/src/camera.rs b/src/camera.rs index 82fb98b..0d24e8a 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,4 +1,4 @@ -use super::{ Hidden, Map, Mind, Position, Prop, Renderable }; +use super::{ Hidden, Map, Mind, Position, Prop, Renderable, Pools }; use rltk::prelude::*; use specs::prelude::*; use std::ops::Mul; @@ -70,6 +70,7 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) { { let positions = ecs.read_storage::(); let renderables = ecs.read_storage::(); + let pools = ecs.read_storage::(); let minds = ecs.read_storage::(); let hidden = ecs.read_storage::(); let props = ecs.write_storage::(); @@ -126,6 +127,23 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) { bg, render.glyph ); + if let Some(pool) = pools.get(*ent) { + if pool.hit_points.current < pool.hit_points.max { + ctx.set_active_console(2); + crate::gui::draw_lerping_bar( + ctx, + (entity_offset_x + x_offset) * 22 + 2, + (entity_offset_y + y_offset) * 20 - 2, + 18, + pool.hit_points.current, + pool.hit_points.max, + RGB::named(GREEN), + RGB::named(RED), + false + ); + ctx.set_active_console(0); + } + } } } } diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 0041d04..19d6849 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -84,7 +84,8 @@ pub fn draw_lerping_bar( n: i32, max: i32, full_colour: RGB, - empty_colour: RGB + empty_colour: RGB, + with_text: bool ) { let percent = (n as f32) / (max as f32); let fill_width = (percent * (width as f32)) as i32; @@ -92,15 +93,15 @@ pub fn draw_lerping_bar( let fg = RGB::named(rltk::BLACK); for x in 0..width { if x <= fill_width { - ctx.print_color(sx + x, sy, fg, bg, " "); - } else { - ctx.print_color(sx + x, sy, RGB::named(rltk::BLACK), RGB::named(rltk::BLACK), " "); + ctx.set(sx + x, sy, fg, bg, to_cp437(' ')); } } - ctx.print(sx - 1, sy, "["); - let health = format!("{}/{}", n, max); - ctx.print_color(sx + 1, sy, fg, bg, health); - ctx.print(sx + width, sy, "]"); + if with_text { + ctx.print(sx - 1, sy, "["); + let health = format!("{}/{}", n, max); + ctx.print_color(sx + 1, sy, fg, bg, health); + ctx.print(sx + width, sy, "]"); + } } pub const TEXT_FONT_MOD: i32 = 2; @@ -130,7 +131,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { stats.hit_points.current, stats.hit_points.max, RGB::from_u8(0, 255, 0), - RGB::from_u8(255, 0, 0) + RGB::from_u8(255, 0, 0), + true ); draw_lerping_bar( ctx, @@ -140,7 +142,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { stats.mana.current, stats.mana.max, RGB::named(rltk::BLUE), - RGB::named(rltk::BLACK) + RGB::named(rltk::BLACK), + true ); // Draw AC let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills); @@ -422,7 +425,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { &format!("{}", index) ); ctx.print_color( - (VIEWPORT_W + 3) * TEXT_FONT_MOD + 1, + (VIEWPORT_W + 3) * TEXT_FONT_MOD + 2, y, RGB::named(CYAN), RGB::named(BLACK), @@ -496,7 +499,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { entity.3 ); ctx.print_color( - (VIEWPORT_W + 3) * TEXT_FONT_MOD + 1, + (VIEWPORT_W + 3) * TEXT_FONT_MOD + 2, y, entity.1, RGB::named(rltk::BLACK), diff --git a/src/main.rs b/src/main.rs index a6e4092..8fb8221 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,23 +8,29 @@ const DISPLAYHEIGHT: i32 = 56; fn main() -> rltk::BError { // Embedded resources for use in wasm build - const CURSES_16_16_BYTES: &[u8] = include_bytes!("../resources/nagidal24x24.png"); - const ISHMERIA_8_16_BYTES: &[u8] = include_bytes!("../resources/curses12x24.png"); + const MAIN_22_20_BYTES: &[u8] = include_bytes!("../resources/nagidal22x20_centred.png"); + const TEXT_11_20_BYTES: &[u8] = include_bytes!("../resources/curses11x20.png"); + const SINGLE_1_1_BYTES: &[u8] = include_bytes!("../resources/healthbar22x2.png"); rltk::embedding::EMBED .lock() - .add_resource("resources/nagidal24x24.png".to_string(), CURSES_16_16_BYTES); + .add_resource("resources/nagidal22x20_centred.png".to_string(), MAIN_22_20_BYTES); rltk::embedding::EMBED .lock() - .add_resource("resources/curses12x24.png".to_string(), ISHMERIA_8_16_BYTES); + .add_resource("resources/curses11x20.png".to_string(), TEXT_11_20_BYTES); + rltk::embedding::EMBED + .lock() + .add_resource("resources/healthbar22x2.png".to_string(), SINGLE_1_1_BYTES); let mut context = RltkBuilder::new() .with_title("rust-rl") .with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT) - .with_font("nagidal24x24.png", 24, 24) - .with_font("curses12x24.png", 12, 24) - .with_tile_dimensions(24, 24) - .with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "nagidal24x24.png") - .with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses12x24.png") + .with_font("nagidal22x20_centred.png", 22, 20) + .with_font("curses11x20.png", 11, 20) + .with_font("healthbar22x2.png", 1, 1) + .with_tile_dimensions(22, 20) + .with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "nagidal22x20_centred.png") + .with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses11x20.png") + .with_sparse_console(DISPLAYWIDTH * 22, DISPLAYHEIGHT * 20, "healthbar22x2.png") .build()?; if config::CONFIG.visuals.with_scanlines { context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn); diff --git a/src/states/state.rs b/src/states/state.rs index 00152d5..0bc9533 100644 --- a/src/states/state.rs +++ b/src/states/state.rs @@ -164,6 +164,8 @@ impl GameState for State { new_runstate = *runstate; } // Clear screen + ctx.set_active_console(2); + ctx.cls(); ctx.set_active_console(1); ctx.cls(); ctx.set_active_console(0); @@ -562,6 +564,8 @@ impl GameState for State { new_runstate = self.mapgen_next_state.unwrap(); } if self.mapgen_history.len() != 0 { + ctx.set_active_console(2); + ctx.cls(); ctx.set_active_console(1); ctx.cls(); ctx.set_active_console(0);