From 670b365def873cb28a72a3274fa73cc12c87e93c Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Sat, 23 Sep 2023 19:35:51 +0100 Subject: [PATCH] refining the sprites --- raws/props.json | 2 +- src/camera.rs | 14 +++++++++++++- src/gui/farlook.rs | 14 ++++++++++---- src/gui/mod.rs | 5 ++--- src/main.rs | 13 ------------- src/player.rs | 2 ++ 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/raws/props.json b/raws/props.json index d72c5fd..f60ff11 100644 --- a/raws/props.json +++ b/raws/props.json @@ -2,7 +2,7 @@ { "id": "door", "name": "door", - "renderable": { "glyph": "+", "fg": "#00FFFF", "bg": "#000000", "order": 2 }, + "renderable": { "glyph": "+", "sprite": 17, "fg": "#00FFFF", "bg": "#000000", "order": 2 }, "flags": ["DOOR"] }, { diff --git a/src/camera.rs b/src/camera.rs index 15d24b5..c49a71e 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -3,7 +3,6 @@ use bracket_lib::prelude::*; use specs::prelude::*; use std::ops::Mul; use super::data::visuals::{ VIEWPORT_W, VIEWPORT_H }; -use super::data::sprites::*; use super::data::prelude::*; const SHOW_BOUNDARIES: bool = false; @@ -38,6 +37,19 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) { let map = ecs.fetch::(); let (min_x, max_x, min_y, max_y, x_offset, y_offset) = get_screen_bounds(ecs, ctx); + ctx.set_active_console(0); + for i in 0..16 { + for j in 0..19 { + ctx.add_sprite( + Rect::with_size(i * 16, j * 16, 16, 16), + 0, + RGBA::named(WHITE), + i + j * 16 + ); + } + } + ctx.set_active_console(1); + // Render map let mut y = 0; for t_y in min_y..max_y { diff --git a/src/gui/farlook.rs b/src/gui/farlook.rs index 69a9c7e..045b172 100644 --- a/src/gui/farlook.rs +++ b/src/gui/farlook.rs @@ -1,4 +1,11 @@ -use super::{ State, RunState, tooltip::draw_tooltips, camera::get_screen_bounds }; +use super::{ + State, + RunState, + tooltip::draw_tooltips, + camera::get_screen_bounds, + VIEWPORT_H, + VIEWPORT_W, +}; use bracket_lib::prelude::*; #[derive(PartialEq, Copy, Clone)] @@ -23,9 +30,8 @@ pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult { ); if let RunState::Farlook { x, y } = *runstate { - let (screen_x, screen_y) = (40, 30); - let x = x.clamp(x_offset, x_offset - 1 + (screen_x as i32)); - let y = y.clamp(y_offset, y_offset - 1 + (screen_y as i32)); + let x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W); + let y = y.clamp(y_offset, y_offset - 1 + VIEWPORT_H); ctx.set(x, y, RGB::named(WHITE), RGB::named(BLACK), to_cp437('X')); draw_tooltips(&gs.ecs, ctx, Some((x, y))); diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 35d427f..65482af 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1235,9 +1235,8 @@ pub fn ranged_target( &gs.ecs, ctx ); - let (screen_x, screen_y) = (40, 30); - let x = x.clamp(x_offset, x_offset - 1 + (screen_x as i32)); - let y = y.clamp(y_offset, y_offset - 1 + (screen_y as i32)); + let x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W); + let y = y.clamp(y_offset, y_offset - 1 + VIEWPORT_H); let mut mouse_pos_adjusted = mouse_pos; mouse_pos_adjusted.0 += min_x - x_offset; diff --git a/src/main.rs b/src/main.rs index 1703f1f..3cdaa0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,19 +45,6 @@ fn main() -> BError { context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn); } - context.set_active_console(0); - for i in 0..16 { - for j in 0..19 { - context.add_sprite( - Rect::with_size(i * 16, j * 16, 16, 16), - 0, - RGBA::named(WHITE), - i + j * 16 - ); - } - } - context.set_active_console(1); - let mut gs = State { ecs: World::new(), mapgen_next_state: Some(RunState::MainMenu { diff --git a/src/player.rs b/src/player.rs index 22e09cd..d91ba3b 100644 --- a/src/player.rs +++ b/src/player.rs @@ -134,6 +134,7 @@ pub fn try_door(i: i32, j: i32, ecs: &mut World) -> RunState { let mut renderables = ecs.write_storage::(); let render_data = renderables.get_mut(potential_target).unwrap(); render_data.glyph = to_cp437('+'); // Nethack open door, maybe just use '/' instead. + render_data.sprite = Some(17); // TODO: Enum door_pos = Some(Point::new(pos.x + delta_x, pos.y + delta_y)); } result = RunState::Ticking; @@ -231,6 +232,7 @@ pub fn open(i: i32, j: i32, ecs: &mut World) -> RunState { let mut renderables = ecs.write_storage::(); let render_data = renderables.get_mut(potential_target).unwrap(); render_data.glyph = to_cp437('▓'); // Nethack open door, maybe just use '/' instead. + render_data.sprite = Some(18); // TODO: Enum door_pos = Some(Point::new(pos.x + delta_x, pos.y + delta_y)); } result = RunState::Ticking;