fixing the sea of red - entity rendering for things in view

This commit is contained in:
Llywelwyn 2023-09-24 16:55:47 +01:00
parent 643ecfcf3e
commit e8aa7494a4
9 changed files with 120 additions and 89 deletions

View file

@ -7,8 +7,13 @@ use super::data::prelude::*;
const SHOW_BOUNDARIES: bool = false; const SHOW_BOUNDARIES: bool = false;
pub fn get_offset() -> (i32, i32) { pub struct Offsets {
return (1, 10); pub x: i32,
pub y: i32,
}
pub fn get_offset() -> Offsets {
return Offsets { x: 1, y: 10 };
} }
pub struct ScreenBounds { pub struct ScreenBounds {
@ -52,13 +57,13 @@ pub fn in_bounds(x: i32, y: i32, min_x: i32, min_y: i32, upper_x: i32, upper_y:
pub fn render_camera(ecs: &World, ctx: &mut BTerm) { pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let (min_x, max_x, min_y, max_y, x_offset, y_offset) = get_screen_bounds(ecs); let bounds = get_screen_bounds(ecs);
// Render map // Render map
let mut y = 0; let mut y = 0;
for t_y in min_y..max_y { for t_y in bounds.min_y..bounds.max_y {
let mut x = 0; let mut x = 0;
for t_x in min_x..max_x { for t_x in bounds.min_x..bounds.max_x {
if t_x >= 0 && t_x < map.width && t_y >= 0 && t_y < map.height { if t_x >= 0 && t_x < map.width && t_y >= 0 && t_y < map.height {
let idx = map.xy_idx(t_x, t_y); let idx = map.xy_idx(t_x, t_y);
if map.revealed_tiles[idx] { if map.revealed_tiles[idx] {
@ -69,7 +74,7 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
Some(*ecs.fetch::<Point>()), Some(*ecs.fetch::<Point>()),
None None
); );
ctx.set(x + x_offset, y + y_offset, fg, bg, glyph); ctx.set(x + bounds.x_offset, y + bounds.y_offset, fg, bg, glyph);
} else { } else {
ctx.set_active_console(0); ctx.set_active_console(0);
let (id, tint) = crate::map::themes::get_sprite_for_id( let (id, tint) = crate::map::themes::get_sprite_for_id(
@ -78,7 +83,12 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
Some(*ecs.fetch::<Point>()) Some(*ecs.fetch::<Point>())
); );
ctx.add_sprite( ctx.add_sprite(
Rect::with_size(x * 16 + x_offset * 16, y * 16 + y_offset * 16, 16, 16), Rect::with_size(
x * 16 + bounds.x_offset * 16,
y * 16 + bounds.y_offset * 16,
16,
16
),
0, 0,
tint, tint,
0 // Ya 0 // Ya
@ -88,8 +98,8 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
} }
} else if SHOW_BOUNDARIES { } else if SHOW_BOUNDARIES {
ctx.set( ctx.set(
x + x_offset, x + bounds.x_offset,
y + y_offset, y + bounds.y_offset,
RGB::named(DARKSLATEGRAY), RGB::named(DARKSLATEGRAY),
RGB::named(BLACK), RGB::named(BLACK),
to_cp437('#') to_cp437('#')
@ -117,9 +127,14 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
data.sort_by(|&a, &b| b.1.render_order.cmp(&a.1.render_order)); data.sort_by(|&a, &b| b.1.render_order.cmp(&a.1.render_order));
for (pos, render, ent, _hidden) in data.iter() { for (pos, render, ent, _hidden) in data.iter() {
let idx = map.xy_idx(pos.x, pos.y); let idx = map.xy_idx(pos.x, pos.y);
let entity_offset_x = pos.x - min_x; let entity_offset_x = pos.x - bounds.min_x;
let entity_offset_y = pos.y - min_y; let entity_offset_y = pos.y - bounds.min_y;
if pos.x < max_x && pos.y < max_y && pos.x >= min_x && pos.y >= min_y { if
pos.x < bounds.max_x &&
pos.y < bounds.max_y &&
pos.x >= bounds.min_x &&
pos.y >= bounds.min_y
{
let mut draw = false; let mut draw = false;
let mut fg = render.fg; let mut fg = render.fg;
let bg = BLACK; let bg = BLACK;
@ -152,8 +167,8 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
ctx.set_active_console(0); ctx.set_active_console(0);
ctx.add_sprite( ctx.add_sprite(
Rect::with_size( Rect::with_size(
entity_offset_x * 16 + x_offset * 16, entity_offset_x * 16 + bounds.x_offset * 16,
entity_offset_y * 16 + y_offset * 16, entity_offset_y * 16 + bounds.y_offset * 16,
16, 16,
16 16
), ),
@ -164,8 +179,8 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
ctx.set_active_console(ENTITY_LAYER); ctx.set_active_console(ENTITY_LAYER);
} else { } else {
ctx.set( ctx.set(
entity_offset_x + x_offset, entity_offset_x + bounds.x_offset,
entity_offset_y + y_offset, entity_offset_y + bounds.y_offset,
fg, fg,
bg, bg,
render.glyph render.glyph
@ -176,8 +191,8 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
ctx.set_active_console(HP_BAR_LAYER); ctx.set_active_console(HP_BAR_LAYER);
crate::gui::draw_lerping_bar( crate::gui::draw_lerping_bar(
ctx, ctx,
(entity_offset_x + x_offset) * 16 + 2, (entity_offset_x + bounds.x_offset) * 16 + 2,
(entity_offset_y + y_offset) * 16 - 1, (entity_offset_y + bounds.y_offset) * 16 - 1,
14, 14,
pool.hit_points.current, pool.hit_points.current,
pool.hit_points.max, pool.hit_points.max,

View file

@ -1,11 +1,4 @@
use super::{ use super::{ State, RunState, tooltip::draw_tooltips, camera::get_offset, VIEWPORT_H, VIEWPORT_W };
State,
RunState,
tooltip::draw_tooltips,
camera::get_screen_bounds,
VIEWPORT_H,
VIEWPORT_W,
};
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
@ -19,19 +12,19 @@ pub enum FarlookResult {
pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult { pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult {
let runstate = gs.ecs.fetch::<RunState>(); let runstate = gs.ecs.fetch::<RunState>();
let (_min_x, _max_x, _min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs); let offsets = get_offset();
ctx.print_color( ctx.print_color(
1 + x_offset, 1 + offsets.x,
1 + y_offset, 1 + offsets.y,
RGB::named(WHITE), RGB::named(WHITE),
RGB::named(BLACK), RGB::named(BLACK),
"Look at what? [move keys][Esc.]" "Look at what? [move keys][Esc.]"
); );
if let RunState::Farlook { x, y } = *runstate { if let RunState::Farlook { x, y } = *runstate {
let x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W); let x = x.clamp(offsets.x, offsets.x - 1 + VIEWPORT_W);
let y = y.clamp(y_offset, y_offset - 1 + VIEWPORT_H); let y = y.clamp(offsets.y, offsets.y - 1 + VIEWPORT_H);
ctx.set(x, y, RGB::named(WHITE), RGB::named(BLACK), to_cp437('X')); ctx.set(x, y, RGB::named(WHITE), RGB::named(BLACK), to_cp437('X'));
draw_tooltips(&gs.ecs, ctx, Some((x, y))); draw_tooltips(&gs.ecs, ctx, Some((x, y)));
@ -55,6 +48,6 @@ pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult {
} else { } else {
let ppos = gs.ecs.fetch::<Point>(); let ppos = gs.ecs.fetch::<Point>();
// TODO: PPOS + offsets (should get these from screen_bounds()) // TODO: PPOS + offsets (should get these from screen_bounds())
return FarlookResult::NoResponse { x: ppos.x + x_offset, y: ppos.x + y_offset }; return FarlookResult::NoResponse { x: ppos.x + offsets.x, y: ppos.x + offsets.y };
} }
} }

View file

@ -122,12 +122,12 @@ pub fn identify(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Enti
} }
// Get display args // Get display args
let width = get_max_inventory_width(&player_inventory); let width = get_max_inventory_width(&player_inventory);
let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs); let offsets = crate::camera::get_offset();
let (x, y) = (x_offset + 1, y_offset + 3); let (x, y) = (offsets.x + 1, offsets.y + 3);
// Draw menu // Draw menu
ctx.print_color( ctx.print_color(
1 + x_offset, 1 + offsets.x,
1 + y_offset, 1 + offsets.y,
RGB::named(WHITE), RGB::named(WHITE),
RGB::named(BLACK), RGB::named(BLACK),
"Identify which item? [aA-zZ][Esc.]" "Identify which item? [aA-zZ][Esc.]"

View file

@ -549,11 +549,11 @@ pub fn get_input_direction(
ctx: &mut BTerm, ctx: &mut BTerm,
function: fn(i: i32, j: i32, ecs: &mut World) -> RunState function: fn(i: i32, j: i32, ecs: &mut World) -> RunState
) -> RunState { ) -> RunState {
let (_, _, _, _, x_offset, y_offset) = camera::get_screen_bounds(ecs); let offsets = camera::get_offset();
ctx.print_color( ctx.print_color(
1 + x_offset, 1 + offsets.x,
1 + y_offset, 1 + offsets.y,
RGB::named(WHITE), RGB::named(WHITE),
RGB::named(BLACK), RGB::named(BLACK),
"In what direction? [0-9]/[YUHJKLBN]" "In what direction? [0-9]/[YUHJKLBN]"
@ -1191,14 +1191,14 @@ pub fn ranged_target(
range: i32, range: i32,
aoe: i32 aoe: i32
) -> (TargetResult, Option<Point>) { ) -> (TargetResult, Option<Point>) {
let (min_x, max_x, min_y, max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs); let bounds = camera::get_screen_bounds(&gs.ecs);
let player_entity = gs.ecs.fetch::<Entity>(); let player_entity = gs.ecs.fetch::<Entity>();
let player_pos = gs.ecs.fetch::<Point>(); let player_pos = gs.ecs.fetch::<Point>();
let viewsheds = gs.ecs.read_storage::<Viewshed>(); let viewsheds = gs.ecs.read_storage::<Viewshed>();
ctx.print_color( ctx.print_color(
1 + x_offset, 1 + bounds.x_offset,
1 + y_offset, 1 + bounds.y_offset,
RGB::named(WHITE), RGB::named(WHITE),
RGB::named(BLACK), RGB::named(BLACK),
"Targeting which tile? [mouse input]" "Targeting which tile? [mouse input]"
@ -1212,15 +1212,19 @@ pub fn ranged_target(
for idx in visible.visible_tiles.iter() { for idx in visible.visible_tiles.iter() {
let distance = DistanceAlg::Pythagoras.distance2d(*player_pos, *idx); let distance = DistanceAlg::Pythagoras.distance2d(*player_pos, *idx);
if distance <= (range as f32) { if distance <= (range as f32) {
let screen_x = idx.x - min_x; let screen_x = idx.x - bounds.min_x;
let screen_y = idx.y - min_y; let screen_y = idx.y - bounds.min_y;
if if
screen_x > 1 && screen_x > 1 &&
screen_x < max_x - min_x - 1 && screen_x < bounds.max_x - bounds.min_x - 1 &&
screen_y > 1 && screen_y > 1 &&
screen_y < max_y - min_y - 1 screen_y < bounds.max_y - bounds.min_y - 1
{ {
ctx.set_bg(screen_x + x_offset, screen_y + y_offset, TARGETING_VALID_COL); ctx.set_bg(
screen_x + bounds.x_offset,
screen_y + bounds.y_offset,
TARGETING_VALID_COL
);
available_cells.push(idx); available_cells.push(idx);
} }
} }
@ -1231,13 +1235,13 @@ pub fn ranged_target(
// Draw mouse cursor // Draw mouse cursor
let mouse_pos = (x, y); let mouse_pos = (x, y);
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs); let bounds = camera::get_screen_bounds(&gs.ecs);
let x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W); let x = x.clamp(bounds.x_offset, bounds.x_offset - 1 + VIEWPORT_W);
let y = y.clamp(y_offset, y_offset - 1 + VIEWPORT_H); let y = y.clamp(bounds.y_offset, bounds.y_offset - 1 + VIEWPORT_H);
let mut mouse_pos_adjusted = mouse_pos; let mut mouse_pos_adjusted = mouse_pos;
mouse_pos_adjusted.0 += min_x - x_offset; mouse_pos_adjusted.0 += bounds.min_x - bounds.x_offset;
mouse_pos_adjusted.1 += min_y - y_offset; mouse_pos_adjusted.1 += bounds.min_y - bounds.y_offset;
let map = gs.ecs.fetch::<Map>(); let map = gs.ecs.fetch::<Map>();
let mut valid_target = false; let mut valid_target = false;
for idx in available_cells.iter() { for idx in available_cells.iter() {
@ -1257,8 +1261,8 @@ pub fn ranged_target(
continue; continue;
} }
ctx.set( ctx.set(
point.x + x_offset - min_x, point.x + bounds.x_offset - bounds.min_x,
point.y + y_offset - min_y, point.y + bounds.y_offset - bounds.min_y,
RGB::named(TARGETING_LINE_COL), RGB::named(TARGETING_LINE_COL),
RGB::named(TARGETING_VALID_COL), RGB::named(TARGETING_VALID_COL),
to_cp437('~') to_cp437('~')
@ -1285,7 +1289,11 @@ pub fn ranged_target(
let col2 = BLACK; let col2 = BLACK;
((col1.0 + col2.0) / 2, (col1.1 + col2.1) / 2, (col1.2 + col2.2) / 2) ((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(
tile.x - bounds.min_x + bounds.x_offset,
tile.y - bounds.min_y + bounds.y_offset,
bg
);
} }
} }

View file

@ -117,12 +117,12 @@ pub fn remove_curse(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<
} }
// Get display args // Get display args
let width = get_max_inventory_width(&player_inventory); let width = get_max_inventory_width(&player_inventory);
let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs); let offsets = crate::camera::get_offset();
let (x, y) = (x_offset + 1, y_offset + 3); let (x, y) = (offsets.x + 1, offsets.y + 3);
// Draw menu // Draw menu
ctx.print_color( ctx.print_color(
1 + x_offset, 1 + offsets.x,
1 + y_offset, 1 + offsets.y,
RGB::named(WHITE), RGB::named(WHITE),
RGB::named(BLACK), RGB::named(BLACK),
"Decurse which item? [aA-zZ][Esc.]" "Decurse which item? [aA-zZ][Esc.]"

View file

@ -64,7 +64,7 @@ impl Tooltip {
#[rustfmt::skip] #[rustfmt::skip]
pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) { 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); let bounds = get_screen_bounds(ecs);
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let names = ecs.read_storage::<Name>(); let names = ecs.read_storage::<Name>();
let positions = ecs.read_storage::<Position>(); let positions = ecs.read_storage::<Position>();
@ -77,8 +77,8 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) {
let mouse_pos = if xy.is_none() { ctx.mouse_pos() } else { xy.unwrap() }; let mouse_pos = if xy.is_none() { ctx.mouse_pos() } else { xy.unwrap() };
let mut mouse_pos_adjusted = mouse_pos; let mut mouse_pos_adjusted = mouse_pos;
mouse_pos_adjusted.0 += min_x - x_offset; mouse_pos_adjusted.0 += bounds.min_x - bounds.x_offset;
mouse_pos_adjusted.1 += min_y - y_offset; mouse_pos_adjusted.1 += bounds.min_y - bounds.y_offset;
if mouse_pos_adjusted.0 >= map.width if mouse_pos_adjusted.0 >= map.width
|| mouse_pos_adjusted.1 >= map.height || mouse_pos_adjusted.1 >= map.height
|| mouse_pos_adjusted.1 < 0 // Might need to be 1, and -1 from map height/width. || mouse_pos_adjusted.1 < 0 // Might need to be 1, and -1 from map height/width.

View file

@ -7,9 +7,9 @@ use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator };
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use std::collections::HashMap; use std::collections::HashMap;
const TILESIZE: u32 = 16; const TILESIZE: f32 = 16.0;
const DISPLAYWIDTH: u32 = 100 * TILESIZE; const DISPLAYWIDTH: u32 = 100 * (TILESIZE as u32);
const DISPLAYHEIGHT: u32 = 56 * TILESIZE; const DISPLAYHEIGHT: u32 = 56 * (TILESIZE as u32);
#[notan_main] #[notan_main]
fn main() -> Result<(), String> { fn main() -> Result<(), String> {
@ -155,8 +155,11 @@ enum DrawType {
VisibleAndRemember, VisibleAndRemember,
Telepathy, Telepathy,
} }
#[derive(PartialEq, Eq, Hash)]
struct DrawKey { struct DrawKey {
idx: usize, x: i32,
y: i32,
render_order: i32, render_order: i32,
} }
struct DrawInfo { struct DrawInfo {
@ -165,9 +168,10 @@ struct DrawInfo {
} }
fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) { fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let bounds = crate::camera::get_screen_bounds(ecs);
render_map_in_view(&*map, ecs, draw, bounds); render_map_in_view(&*map, ecs, draw, atlas);
{ {
let bounds = crate::camera::get_screen_bounds(ecs);
let positions = ecs.read_storage::<Position>(); let positions = ecs.read_storage::<Position>();
let renderables = ecs.read_storage::<Renderable>(); let renderables = ecs.read_storage::<Renderable>();
let hidden = ecs.read_storage::<Hidden>(); let hidden = ecs.read_storage::<Hidden>();
@ -180,8 +184,8 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
let mut to_draw: HashMap<DrawKey, DrawInfo> = HashMap::new(); let mut to_draw: HashMap<DrawKey, DrawInfo> = HashMap::new();
for (pos, render, e, _h) in data.iter() { for (pos, render, e, _h) in data.iter() {
let idx = map.xy_idx(pos.x, pos.y); let idx = map.xy_idx(pos.x, pos.y);
let entity_offset_x = pos.x - bounds.x_offset; let offset_x = pos.x - bounds.min_x + bounds.x_offset;
let entity_offset_y = pos.y - bounds.y_offset; let offset_y = pos.y - bounds.min_y + bounds.y_offset;
if if
crate::camera::in_bounds( crate::camera::in_bounds(
pos.x, pos.x,
@ -211,6 +215,8 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
// draw these, but it uses a unique enum variant so // draw these, but it uses a unique enum variant so
// it can be treated differently if needed in future. // it can be treated differently if needed in future.
DrawType::Telepathy DrawType::Telepathy
} else {
DrawType::None
} }
} else { } else {
// If we don't see it, and we don't sense it with // If we don't see it, and we don't sense it with
@ -219,16 +225,17 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
}; };
match draw_type { match draw_type {
DrawType::None => {} DrawType::None => {}
_ => _ => {
to_draw.insert( to_draw.insert(
DrawKey { idx, render_order: render.render_order }, DrawKey { x: offset_x, y: offset_y, render_order: render.render_order },
DrawInfo { e, draw_type } DrawInfo { e: *e, draw_type }
), );
}
} }
} }
} }
let mut entries: Vec<(&DrawKey, &DrawInfo)> = to_draw.iter().collect(); let mut entries: Vec<(&DrawKey, &DrawInfo)> = to_draw.iter().collect();
entries.sort_by_key(|&(k, _v)| *k.render_order); entries.sort_by_key(|&(k, _v)| k.render_order);
for entry in entries.iter() { for entry in entries.iter() {
match entry.1.draw_type { match entry.1.draw_type {
DrawType::Visible | DrawType::Telepathy => { DrawType::Visible | DrawType::Telepathy => {
@ -237,10 +244,17 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
// Draw health bar // Draw health bar
} }
} }
draw.image(atlas.get("ui_heart_full").unwrap()).position(
(entry.0.x as f32) * TILESIZE,
(entry.0.y as f32) * TILESIZE
);
// Draw entity // Draw entity
} }
DrawType::VisibleAndRemember => { DrawType::VisibleAndRemember => {
// Draw it, and remember it draw.image(atlas.get("ui_crystal_full").unwrap()).position(
(entry.0.x as f32) * TILESIZE,
(entry.0.y as f32) * TILESIZE
);
} }
_ => {} _ => {}
} }
@ -248,8 +262,8 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
} }
} }
use crate::camera::ScreenBounds; fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, bounds: ScreenBounds) { let bounds = crate::camera::get_screen_bounds(ecs);
for tile_y in bounds.min_y..bounds.max_y { for tile_y in bounds.min_y..bounds.max_y {
for tile_x in bounds.min_x..bounds.max_x { for tile_x in bounds.min_x..bounds.max_x {
if crate::camera::in_bounds(tile_x, tile_y, 0, 0, map.width, map.height) { if crate::camera::in_bounds(tile_x, tile_y, 0, 0, map.width, map.height) {
@ -286,8 +300,7 @@ fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, bounds: ScreenBou
fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) { fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
let mut draw = gfx.create_draw(); let mut draw = gfx.create_draw();
draw.clear(Color::BLACK); draw.clear(Color::BLACK);
match *gs.ecs.fetch::<RunState>() {
match gs.ecs.fetch::<RunState>() {
| RunState::MainMenu { .. } | RunState::MainMenu { .. }
| RunState::CharacterCreation { .. } | RunState::CharacterCreation { .. }
| RunState::PreRun { .. } => {} | RunState::PreRun { .. } => {}
@ -299,7 +312,7 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
let map = gs.ecs.fetch::<Map>(); let map = gs.ecs.fetch::<Map>();
let ppos = gs.ecs.fetch::<Point>(); let ppos = gs.ecs.fetch::<Point>();
let offsets = crate::camera::get_offset(); let offsets = crate::camera::get_offset();
let px = idx_to_px(map.xy_idx(ppos.x + offsets.0, ppos.y + offsets.1), &map); let px = idx_to_px(map.xy_idx(ppos.x + offsets.x, ppos.y + offsets.y), &map);
draw.image(gs.atlas.get("ui_heart_full").unwrap()).position(px.0, px.1); draw.image(gs.atlas.get("ui_heart_full").unwrap()).position(px.0, px.1);
// Render batch // Render batch
gfx.render(&draw); gfx.render(&draw);

View file

@ -749,9 +749,12 @@ pub fn player_input(gs: &mut State, ctx: &mut App, on_overmap: bool) -> RunState
return RunState::SaveGame; return RunState::SaveGame;
} }
KeyCode::X => { KeyCode::X => {
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs); let bounds = get_screen_bounds(&gs.ecs);
let ppos = gs.ecs.fetch::<Point>(); let ppos = gs.ecs.fetch::<Point>();
let (x, y) = (ppos.x + x_offset - min_x, ppos.y + y_offset - min_y); let (x, y) = (
ppos.x + bounds.x_offset - bounds.min_x,
ppos.y + bounds.y_offset - bounds.min_y,
);
return RunState::Farlook { x, y }; return RunState::Farlook { x, y };
} }
_ => {} _ => {}

View file

@ -446,21 +446,20 @@ impl State {
if let Some(ranged_item) = ranged_item { if let Some(ranged_item) = ranged_item {
let is_aoe = self.ecs.read_storage::<AOE>(); let is_aoe = self.ecs.read_storage::<AOE>();
let aoe_item = is_aoe.get(item_entity); let aoe_item = is_aoe.get(item_entity);
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = let bounds = camera::get_screen_bounds(&self.ecs);
camera::get_screen_bounds(&self.ecs);
let ppos = self.ecs.fetch::<Point>(); let ppos = self.ecs.fetch::<Point>();
if let Some(aoe_item) = aoe_item { if let Some(aoe_item) = aoe_item {
new_runstate = RunState::ShowTargeting { new_runstate = RunState::ShowTargeting {
x: ppos.x + x_offset - min_x, x: ppos.x + bounds.x_offset - bounds.min_x,
y: ppos.y + y_offset - min_y, y: ppos.y + bounds.y_offset - bounds.min_y,
range: ranged_item.range, range: ranged_item.range,
item: item_entity, item: item_entity,
aoe: aoe_item.radius, aoe: aoe_item.radius,
}; };
} else { } else {
new_runstate = RunState::ShowTargeting { new_runstate = RunState::ShowTargeting {
x: ppos.x + x_offset - min_x, x: ppos.x + bounds.x_offset - bounds.min_x,
y: ppos.y + y_offset - min_y, y: ppos.y + bounds.y_offset - bounds.min_y,
range: ranged_item.range, range: ranged_item.range,
item: item_entity, item: item_entity,
aoe: 0, aoe: 0,