better ranged targeting visuals

This commit is contained in:
Llywelwyn 2023-08-30 05:40:45 +01:00
parent e22261d012
commit 9427ebd7c1
4 changed files with 44 additions and 5 deletions

View file

@ -44,6 +44,6 @@ pub const WIZARD_STARTING_FOOD: &str = "1d2+1";
pub const WIZARD_STARTING_WEAPON: &str = "equip_dagger"; pub const WIZARD_STARTING_WEAPON: &str = "equip_dagger";
pub const WIZARD_STARTING_ARMOUR: &str = "equip_back_protection"; pub const WIZARD_STARTING_ARMOUR: &str = "equip_back_protection";
pub const WIZARD_MAX_SCROLL_LVL: i32 = 3; pub const WIZARD_MAX_SCROLL_LVL: i32 = 3;
pub const WIZARD_SCROLL_AMOUNT: &str = "1d3"; pub const WIZARD_SCROLL_AMOUNT: &str = "1d3+1";
pub const WIZARD_POTION_AMOUNT: &str = "1d3-1"; pub const WIZARD_POTION_AMOUNT: &str = "1d3";
pub const VILLAGER_STARTING_FOOD: &str = "1d3+2"; pub const VILLAGER_STARTING_FOOD: &str = "1d3+2";

View file

@ -15,6 +15,11 @@ pub const SHORT_PARTICLE_LIFETIME: f32 = 100.0; // in ms
pub const DEFAULT_PARTICLE_LIFETIME: f32 = 200.0; pub const DEFAULT_PARTICLE_LIFETIME: f32 = 200.0;
pub const LONG_PARTICLE_LIFETIME: f32 = 300.0; pub const LONG_PARTICLE_LIFETIME: f32 = 300.0;
pub const TARGETING_CURSOR_COL: (u8, u8, u8) = rltk::GOLDENROD;
pub const TARGETING_LINE_COL: (u8, u8, u8) = rltk::LIGHTGOLDENROD;
pub const TARGETING_AOE_COL: (u8, u8, u8) = (20, 20, 20);
pub const TARGETING_VALID_COL: (u8, u8, u8) = (10, 10, 10);
// THEMES // THEMES
pub const BLOODSTAIN_COLOUR: (u8, u8, u8) = (153, 0, 0); pub const BLOODSTAIN_COLOUR: (u8, u8, u8) = (153, 0, 0);
// DEFAULT THEME // DEFAULT THEME

View file

@ -35,6 +35,7 @@ use super::{
get_local_col, get_local_col,
}; };
use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH; use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH;
use crate::data::visuals::{ TARGETING_LINE_COL, TARGETING_CURSOR_COL, TARGETING_AOE_COL, TARGETING_VALID_COL };
use rltk::prelude::*; use rltk::prelude::*;
use specs::prelude::*; use specs::prelude::*;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -959,7 +960,7 @@ pub fn ranged_target(
let screen_x = idx.x - min_x; let screen_x = idx.x - min_x;
let screen_y = idx.y - min_y; let screen_y = idx.y - min_y;
if screen_x > 1 && screen_x < max_x - min_x - 1 && screen_y > 1 && screen_y < max_y - min_y - 1 { if screen_x > 1 && screen_x < max_x - min_x - 1 && screen_y > 1 && screen_y < max_y - min_y - 1 {
ctx.set_bg(screen_x + x_offset, screen_y + y_offset, RGB::named(rltk::BLUE)); ctx.set_bg(screen_x + x_offset, screen_y + y_offset, TARGETING_VALID_COL);
available_cells.push(idx); available_cells.push(idx);
} }
} }
@ -987,6 +988,23 @@ pub fn ranged_target(
} }
let mut result = (TargetResult::NoResponse { x, y }, None); let mut result = (TargetResult::NoResponse { x, y }, None);
if valid_target { if valid_target {
let path = rltk::line2d(
LineAlg::Bresenham,
Point::new(player_pos.x, player_pos.y),
Point::new(mouse_pos_adjusted.0, mouse_pos_adjusted.1)
);
for (i, point) in path.iter().enumerate() {
if i == 0 || i == path.len() - 1 {
continue;
}
ctx.set(
point.x + x_offset - min_x,
point.y + y_offset - min_y,
RGB::named(TARGETING_LINE_COL),
RGB::named(TARGETING_VALID_COL),
to_cp437('~')
);
}
if aoe > 0 { if aoe > 0 {
// We adjust for camera position when getting FOV, but then we need to adjust back // We adjust for camera position when getting FOV, but then we need to adjust back
// when iterating through the tiles themselves, by taking away min_x/min_y. // when iterating through the tiles themselves, by taking away min_x/min_y.
@ -997,10 +1015,20 @@ pub fn ranged_target(
); );
blast_tiles.retain(|p| p.x > 0 && p.x < map.width - 1 && p.y > 0 && p.y < map.height - 1); blast_tiles.retain(|p| p.x > 0 && p.x < map.width - 1 && p.y > 0 && p.y < map.height - 1);
for tile in blast_tiles.iter() { for tile in blast_tiles.iter() {
ctx.set_bg(tile.x - min_x + x_offset, tile.y - min_y + y_offset, RGB::named(rltk::DARKCYAN)); let bg = if available_cells.contains(&tile) {
let col1 = TARGETING_AOE_COL;
let col2 = TARGETING_VALID_COL;
((col1.0 + col2.0) / 2, (col1.1 + col2.1) / 2, (col1.2 + col2.2) / 2)
} else {
let col1 = TARGETING_AOE_COL;
let col2 = BLACK;
((col1.0 + col2.0) / 2, (col1.1 + col2.1) / 2, (col1.2 + col2.2) / 2)
};
ctx.set_bg(tile.x - min_x + x_offset, tile.y - min_y + y_offset, bg);
} }
} }
ctx.set_bg(mouse_pos.0, mouse_pos.1, RGB::named(rltk::CYAN));
ctx.set_bg(mouse_pos.0, mouse_pos.1, RGB::named(TARGETING_CURSOR_COL));
result = match ctx.key { result = match ctx.key {
None => result, None => result,
Some(key) => Some(key) =>

View file

@ -80,6 +80,12 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk, xy: Option<(i32, i32)>) {
tip.add(format!("You see {}.", name), get_local_col(n)); tip.add(format!("You see {}.", name), get_local_col(n));
tooltips.push(tip); tooltips.push(tip);
} }
TileType::ToOvermap(n) => {
let name = get_local_desc(n);
let mut tip = Tooltip::new();
tip.add(format!("You see an exit from {}.", name), get_local_col(n));
tooltips.push(tip);
}
_ => {} _ => {}
} }