infinite font variations for testing - huge wip

This commit is contained in:
Llywelwyn 2023-09-03 05:10:17 +01:00
parent 2a3c59ad33
commit 4e0ed95a22
13 changed files with 72 additions and 24 deletions

BIN
resources/curses11x20.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Before After
Before After

BIN
resources/curses16x16.pdn Normal file

Binary file not shown.

BIN
resources/healthbar11x2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

BIN
resources/healthbar22x2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Before After
Before After

View file

@ -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<NavigationPath> = 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;
}
}
}
}

View file

@ -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::<Position>();
let renderables = ecs.read_storage::<Renderable>();
let pools = ecs.read_storage::<Pools>();
let minds = ecs.read_storage::<Mind>();
let hidden = ecs.read_storage::<Hidden>();
let props = ecs.write_storage::<Prop>();
@ -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);
}
}
}
}
}

View file

@ -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(' '));
}
}
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),

View file

@ -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);

View file

@ -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);