returning the fade2black with distance
This commit is contained in:
parent
cfbe4098b7
commit
046837d9a1
4 changed files with 40 additions and 13 deletions
|
|
@ -13,12 +13,14 @@ pub const HP_BAR_LAYER: usize = 4;
|
|||
pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16;
|
||||
pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5;
|
||||
pub const GLOBAL_OFFSET_MAX_CLAMP: f32 = 1.0;
|
||||
pub const SPRITE_OFFSET_MIN_CLAMP: f32 = 0.85;
|
||||
pub const SPRITE_OFFSET_MAX_CLAMP: f32 = 1.0;
|
||||
pub const WITH_SCANLINES_BRIGHTEN_AMOUNT: f32 = 0.1; // 0.0 = no brightening, 1.0 = full brightening.
|
||||
pub const NON_VISIBLE_MULTIPLIER: f32 = 0.3; // 0.0 = black, 1.0 = full colour.
|
||||
pub const NON_VISIBLE_MULTIPLIER_IF_SCANLINES: f32 = 0.8; // as above, but when using scanlines. should be higher.
|
||||
pub const MAX_DARKENING: f32 = 0.45; // 0.0 = black, 1.0 = full colour - only used if WITH_DARKEN_BY_DISTANCE is true.
|
||||
pub const MAX_DARKENING: f32 = 0.35; // 0.0 = black, 1.0 = full colour - only used if WITH_DARKEN_BY_DISTANCE is true.
|
||||
pub const MAX_DARKENING_IF_SCANLINES: f32 = 0.9; // as above, but when using scanlines. should be higher.
|
||||
pub const START_DARKEN_AT_N_TILES: f32 = 8.0; // start darkening at this distance (should always be less than entity::DEFAULT_VIEWSHED_STANDARD).
|
||||
pub const START_DARKEN_AT_N_TILES: f32 = 7.0; // start darkening at this distance (should always be less than entity::DEFAULT_VIEWSHED_STANDARD).
|
||||
|
||||
pub const SHORT_PARTICLE_LIFETIME: f32 = 100.0; // in ms
|
||||
pub const DEFAULT_PARTICLE_LIFETIME: f32 = 200.0;
|
||||
|
|
|
|||
14
src/main.rs
14
src/main.rs
|
|
@ -181,8 +181,6 @@ fn draw_camera(
|
|||
let positions = ecs.read_storage::<Position>();
|
||||
let renderables = ecs.read_storage::<Renderable>();
|
||||
let hidden = ecs.read_storage::<Hidden>();
|
||||
let props = ecs.read_storage::<Prop>();
|
||||
let items = ecs.read_storage::<Item>();
|
||||
let minds = ecs.read_storage::<Mind>();
|
||||
let pools = ecs.read_storage::<Pools>();
|
||||
let entities = ecs.entities();
|
||||
|
|
@ -257,7 +255,14 @@ fn draw_camera(
|
|||
renderable.fg.b
|
||||
)
|
||||
} else {
|
||||
Color::WHITE
|
||||
let mul = themes::darken_by_distance(
|
||||
Point::new(
|
||||
entry.0.x + bounds.min_x - bounds.x_offset,
|
||||
entry.0.y + bounds.min_y - bounds.y_offset
|
||||
),
|
||||
*ecs.fetch::<Point>()
|
||||
);
|
||||
Color::from_rgb(mul, mul, mul)
|
||||
}
|
||||
);
|
||||
if let Some(pool) = pools.get(entry.1.e) {
|
||||
|
|
@ -376,7 +381,8 @@ fn render_map_in_view(
|
|||
if memory.recolour {
|
||||
Color::from_rgb(memory.fg.r, memory.fg.g, memory.fg.b)
|
||||
} else {
|
||||
Color::from_rgb(0.75, 0.75, 0.75)
|
||||
let mult = 0.3;
|
||||
Color::from_rgb(mult, mult, mult)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ use super::consts::visuals::{
|
|||
BRIGHTEN_FG_COLOUR_BY,
|
||||
GLOBAL_OFFSET_MIN_CLAMP,
|
||||
GLOBAL_OFFSET_MAX_CLAMP,
|
||||
SPRITE_OFFSET_MIN_CLAMP,
|
||||
SPRITE_OFFSET_MAX_CLAMP,
|
||||
};
|
||||
|
||||
// FIXME: If the map size gets too small, entities stop being rendered starting from the right.
|
||||
|
|
@ -110,9 +112,9 @@ impl Map {
|
|||
rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP),
|
||||
);
|
||||
map.colour_offset[idx].1 = (
|
||||
rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP),
|
||||
rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP),
|
||||
rng.range(GLOBAL_OFFSET_MIN_CLAMP, GLOBAL_OFFSET_MAX_CLAMP),
|
||||
rng.range(SPRITE_OFFSET_MIN_CLAMP, SPRITE_OFFSET_MAX_CLAMP),
|
||||
rng.range(SPRITE_OFFSET_MIN_CLAMP, SPRITE_OFFSET_MAX_CLAMP),
|
||||
rng.range(SPRITE_OFFSET_MIN_CLAMP, SPRITE_OFFSET_MAX_CLAMP),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,30 @@ pub fn get_sprite_for_id(idx: usize, map: &Map, other_pos: Option<Point>) -> (&s
|
|||
TileType::Wall => map.tiles[idx].sprite(check_if_base(TileType::Wall, idx, map), f),
|
||||
_ => map.tiles[idx].sprite(false, f),
|
||||
};
|
||||
let tint = if !map.visible_tiles[idx] {
|
||||
Color::from_rgb(0.75, 0.75, 0.75)
|
||||
let base = if !map.visible_tiles[idx] {
|
||||
NON_VISIBLE_MULTIPLIER
|
||||
} else {
|
||||
Color::WHITE
|
||||
if other_pos.is_some() {
|
||||
darken_by_distance(
|
||||
Point::new((idx as i32) % map.width, (idx as i32) / map.width),
|
||||
other_pos.unwrap()
|
||||
)
|
||||
} else {
|
||||
1.0
|
||||
}
|
||||
};
|
||||
let offsets = get_normalised_offsets(idx, map);
|
||||
let tint = Color::from_rgb(base * offsets.0, base * offsets.1, base * offsets.2);
|
||||
return (sprite, tint);
|
||||
}
|
||||
|
||||
fn get_normalised_offsets(idx: usize, map: &Map) -> (f32, f32, f32) {
|
||||
let offsets = map.colour_offset[idx].1;
|
||||
let max = f32::max(f32::max(offsets.0, offsets.1), offsets.2);
|
||||
let normalised = (offsets.0 / max, offsets.1 / max, offsets.2 / max);
|
||||
normalised
|
||||
}
|
||||
|
||||
/// Gets the renderables for a tile, with darkening/offset/post-processing/etc. Passing a val for "debug" will ignore viewshed.
|
||||
pub fn get_tile_renderables_for_id(
|
||||
idx: usize,
|
||||
|
|
@ -354,7 +371,7 @@ pub fn multiply_by_float(rgb: RGB, offsets: (f32, f32, f32)) -> RGB {
|
|||
return RGB::from_f32(r, g, b);
|
||||
}
|
||||
|
||||
fn darken_by_distance(pos: Point, other_pos: Point) -> f32 {
|
||||
pub fn darken_by_distance(pos: Point, other_pos: Point) -> f32 {
|
||||
let distance = DistanceAlg::Pythagoras.distance2d(pos, other_pos) as f32; // Get distance in tiles.
|
||||
let interp_factor =
|
||||
(distance - START_DARKEN_AT_N_TILES) /
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue