sprites init

This commit is contained in:
Llywelwyn 2023-09-23 18:02:51 +01:00
parent 8337f202cf
commit cee4d02ce2
14 changed files with 319 additions and 50 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

BIN
resources/vga8x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
resources/world16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View file

@ -3,6 +3,8 @@ use bracket_lib::prelude::*;
use specs::prelude::*; use specs::prelude::*;
use std::ops::Mul; use std::ops::Mul;
use super::data::visuals::{ VIEWPORT_W, VIEWPORT_H }; use super::data::visuals::{ VIEWPORT_W, VIEWPORT_H };
use super::data::sprites::*;
use super::data::prelude::*;
const SHOW_BOUNDARIES: bool = false; const SHOW_BOUNDARIES: bool = false;
@ -44,13 +46,29 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
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] {
let (glyph, fg, bg) = crate::map::themes::get_tile_renderables_for_id( if 1 == 2 {
idx, let (glyph, fg, bg) = crate::map::themes::get_tile_renderables_for_id(
&*map, idx,
Some(*ecs.fetch::<Point>()), &*map,
None Some(*ecs.fetch::<Point>()),
); None
ctx.set(x + x_offset, y + y_offset, fg, bg, glyph); );
ctx.set(x + x_offset, y + y_offset, fg, bg, glyph);
} else {
ctx.set_active_console(0);
let (id, tint) = crate::map::themes::get_sprite_for_id(
idx,
&*map,
Some(*ecs.fetch::<Point>())
);
ctx.add_sprite(
Rect::with_size(x * 16 + x_offset * 16, y * 16 + y_offset * 16, 16, 16),
0,
tint,
id
);
ctx.set_active_console(TILE_LAYER);
}
} }
} else if SHOW_BOUNDARIES { } else if SHOW_BOUNDARIES {
ctx.set( ctx.set(
@ -68,6 +86,8 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
// Render entities // Render entities
{ {
ctx.set_active_console(ENTITY_LAYER);
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 pools = ecs.read_storage::<Pools>(); let pools = ecs.read_storage::<Pools>();
@ -86,12 +106,7 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
if pos.x < max_x && pos.y < max_y && pos.x >= min_x && pos.y >= min_y { if pos.x < max_x && pos.y < max_y && pos.x >= min_x && pos.y >= min_y {
let mut draw = false; let mut draw = false;
let mut fg = render.fg; let mut fg = render.fg;
let mut bg = crate::map::themes::get_tile_renderables_for_id( let bg = BLACK;
idx,
&*map,
Some(*ecs.fetch::<Point>()),
None
).2;
// Draw entities on visible tiles // Draw entities on visible tiles
if map.visible_tiles[idx] { if map.visible_tiles[idx] {
draw = true; draw = true;
@ -106,9 +121,6 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
let has_mind = minds.get(*ent); let has_mind = minds.get(*ent);
if let Some(_) = has_mind { if let Some(_) = has_mind {
draw = true; draw = true;
if !map.revealed_tiles[idx] {
bg = RGB::named(BLACK);
}
} }
} }
} }
@ -129,7 +141,7 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
); );
if let Some(pool) = pools.get(*ent) { if let Some(pool) = pools.get(*ent) {
if pool.hit_points.current < pool.hit_points.max { if pool.hit_points.current < pool.hit_points.max {
ctx.set_active_console(2); 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 + x_offset) * 16 + 2,
@ -142,12 +154,13 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
false, false,
false false
); );
ctx.set_active_console(0); ctx.set_active_console(ENTITY_LAYER);
} }
} }
} }
} }
} }
ctx.set_active_console(TILE_LAYER);
} }
} }

View file

@ -5,3 +5,8 @@ pub mod char_create;
pub mod events; pub mod events;
pub mod ids; pub mod ids;
pub mod names; pub mod names;
pub mod sprites;
pub mod prelude {
pub use super::visuals::{ TILE_LAYER, ENTITY_LAYER, TEXT_LAYER, HP_BAR_LAYER };
}

119
src/data/sprites.rs Normal file
View file

@ -0,0 +1,119 @@
// Row 1
pub const UNKN: usize = 0;
pub const UNKN2: usize = 1;
pub const UNKN3: usize = 2;
pub const CANDLE: usize = 3;
pub const CANDLE2: usize = 4;
pub const CANDLE3: usize = 5;
pub const CANDLE4: usize = 6;
pub const CANDLE5: usize = 7;
pub const CANDLE6: usize = 8;
pub const CAULDRON: usize = 9;
pub const CAULDRON2: usize = 10;
pub const POTS: usize = 11;
pub const POTS2: usize = 12;
pub const POT: usize = 13;
pub const SPIKES: usize = 14;
pub const SPIKES2: usize = 15;
// Row 2
pub const WINDOW: usize = 16;
pub const DOOR: usize = 17;
pub const DOOR_OPEN: usize = 18;
pub const ROOF_BASE: usize = 19;
pub const ROOF_BASE2: usize = 20;
pub const ROOF: usize = 21;
pub const ROOF2: usize = 22;
pub const ROOF_CHIMNEY: usize = 23;
pub const SIGN: usize = 24;
pub const SIGN_BLACKSMITH: usize = 25;
pub const SIGN_POTION: usize = 26;
pub const SIGN_FURNITURE: usize = 27;
pub const WINDOW_LIT: usize = 28;
pub const STATUE_ANGEL: usize = 29;
pub const STATUE: usize = 30;
pub const STATUE_SPIDER: usize = 31;
// Row 3
pub const UNKN4: usize = 32;
pub const UNKN5: usize = 33;
pub const UNKN6: usize = 34;
pub const UNKN7: usize = 35;
pub const UNKN8: usize = 36;
pub const TREE: usize = 37;
pub const TREE2: usize = 38;
pub const PATH_GRASS: usize = 39;
pub const PATH_GRASS_QUAD: usize = 40;
pub const PATH_GRASS_QUAD2: usize = 41;
pub const PATH_GRASS_QUAD3: usize = 42;
pub const CAMPFIRE: usize = 43;
pub const CAMPFIRE_LIT: usize = 44;
pub const CAMPFIRE_LIT2: usize = 45; // ANIMATE WITH % 2 AND SOMETHING TO DO WITH FRAME TIME
pub const THRONE: usize = 46;
pub const THRONE2: usize = 47;
// Row 4
pub const BOOKSHELF: usize = 48;
pub const BOOKSHELF_EMPTY: usize = 49;
pub const BED: usize = 50;
pub const CHAIR: usize = 51;
pub const TABLE: usize = 52;
pub const TABLE_L: usize = 53;
pub const TABLE_M: usize = 54;
pub const TABLE_R: usize = 55;
pub const CHAIR_AT_TABLE_L: usize = 56;
pub const TABLE_M_PARCHMENT: usize = 57;
pub const CHAIR_AT_TABLE_R: usize = 58;
pub const TABLE_DARK: usize = 59;
pub const TABLE_DARK_SKULL: usize = 60;
pub const TABLE_DARK_L: usize = 61;
pub const TABLE_DARK_M: usize = 62;
pub const TABLE_DARK_R: usize = 63;
// Row 5
pub const GRASS: usize = 64;
pub const GRASS2: usize = 65;
pub const GRASS3: usize = 66;
pub const GRASS4: usize = 67;
pub const GRASS5: usize = 68;
pub const MUSHROOM: usize = 69;
pub const MUSHROOM_PURPLE: usize = 70;
pub const MUSHROOM_ORANGE: usize = 71;
pub const LILYPAD: usize = 72;
pub const LILYPAD2: usize = 73;
pub const LILYPAD3: usize = 74;
pub const LILYPAD4: usize = 75;
pub const LILYPAD5: usize = 76;
pub const LILYPAD6: usize = 77;
pub const LILYPAD7: usize = 78;
pub const LILYPAD8: usize = 79;
// Row 6 (80-95)
// Row 7 (96-111)
// Row 8 (112-127)
pub const FLOOR_WOOD: usize = 123;
// Row 9 (128-143)
// Row 10 (144-159)
// Row 11 (160-175)
pub const WATER_DEEP: usize = 164;
// Row 12 (176-191)
// Row 13 (192-207)
// Row 14 (208-223)
pub const FLOOR_GRASS: usize = 216;
// Row 15 (224-239)
pub const FLOOR: usize = 224;
// Row 16 (240-255)
// Row 17 (256-271)
// Row 18 (272-287)
// Row 19 (288-303)
pub const WALL_BASE: usize = 288;
pub const WALL_BASE2: usize = 289;
pub const WALL_BASE3: usize = 290;
pub const WALL_BASE4: usize = 291;
pub const WALL_CLOTH_BASE: usize = 292;
pub const WALL_CRACKED_BASE: usize = 293;
pub const WALL: usize = 294;
pub const WALL2: usize = 295;
pub const WALL3: usize = 296;
pub const WALL4: usize = 297;
pub const WALL_CRACKED: usize = 298;
pub const WALL_CLOTH_H: usize = 299;
pub const STAIR_D: usize = 300;
pub const STAIR_A: usize = 301;
pub const BASIN: usize = 302;
pub const BASIN_EMPTY: usize = 303;

View file

@ -5,6 +5,11 @@ pub const WITH_DARKEN_BY_DISTANCE: bool = true; // If further away tiles should
pub const VIEWPORT_W: i32 = 69; pub const VIEWPORT_W: i32 = 69;
pub const VIEWPORT_H: i32 = 41; pub const VIEWPORT_H: i32 = 41;
pub const TILE_LAYER: usize = 1;
pub const ENTITY_LAYER: usize = 2;
pub const TEXT_LAYER: usize = 3;
pub const HP_BAR_LAYER: usize = 4;
pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16; pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16;
pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5; pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5;
pub const GLOBAL_OFFSET_MAX_CLAMP: f32 = 1.0; pub const GLOBAL_OFFSET_MAX_CLAMP: f32 = 1.0;

View file

@ -28,6 +28,7 @@ use bracket_lib::prelude::*;
use serde::{ Deserialize, Serialize }; use serde::{ Deserialize, Serialize };
use specs::prelude::*; use specs::prelude::*;
use std::collections::HashMap; use std::collections::HashMap;
use crate::data::prelude::*;
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, PartialEq)]
pub enum Ancestry { pub enum Ancestry {
@ -112,7 +113,7 @@ pub enum CharCreateResult {
/// Handles the player character creation screen. /// Handles the player character creation screen.
pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult { pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult {
ctx.set_active_console(1); ctx.set_active_console(TEXT_LAYER);
let runstate = gs.ecs.fetch::<RunState>(); let runstate = gs.ecs.fetch::<RunState>();
let mut x = 2; let mut x = 2;
@ -246,7 +247,7 @@ pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult {
} }
} }
} }
ctx.set_active_console(0); ctx.set_active_console(TILE_LAYER);
return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class: Class::Fighter }; return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class: Class::Fighter };
} }

View file

@ -34,6 +34,7 @@ use super::{
BUC, BUC,
data::ids::get_local_col, data::ids::get_local_col,
}; };
use crate::data::prelude::*;
use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH; use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH;
use crate::data::visuals::{ use crate::data::visuals::{
TARGETING_LINE_COL, TARGETING_LINE_COL,
@ -110,7 +111,7 @@ pub fn draw_lerping_bar(
pub const TEXT_FONT_MOD: i32 = 2; pub const TEXT_FONT_MOD: i32 = 2;
pub fn draw_ui(ecs: &World, ctx: &mut BTerm) { pub fn draw_ui(ecs: &World, ctx: &mut BTerm) {
ctx.set_active_console(1); ctx.set_active_console(TEXT_LAYER);
// Render stats // Render stats
let pools = ecs.read_storage::<Pools>(); let pools = ecs.read_storage::<Pools>();
let attributes = ecs.read_storage::<Attributes>(); let attributes = ecs.read_storage::<Attributes>();
@ -474,7 +475,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut BTerm) {
// Render the message log at [1, 7], ascending, with 7 lines and a max width of 68. // Render the message log at [1, 7], ascending, with 7 lines and a max width of 68.
gamelog::print_log( gamelog::print_log(
&mut BACKEND_INTERNAL.lock().consoles[1].console, &mut BACKEND_INTERNAL.lock().consoles[TEXT_LAYER].console,
Point::new(1 * TEXT_FONT_MOD, 7), Point::new(1 * TEXT_FONT_MOD, 7),
false, false,
7, 7,
@ -539,7 +540,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut BTerm) {
RGB::named(WHITE), RGB::named(WHITE),
RGB::named(BLACK) RGB::named(BLACK)
); // Side box ); // Side box
ctx.set_active_console(0); ctx.set_active_console(TILE_LAYER);
tooltip::draw_tooltips(ecs, ctx, None); tooltip::draw_tooltips(ecs, ctx, None);
} }
@ -999,7 +1000,7 @@ pub fn get_player_inventory(ecs: &World) -> PlayerInventory {
} }
pub fn show_inventory(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Entity>) { pub fn show_inventory(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Entity>) {
ctx.set_active_console(1); ctx.set_active_console(TEXT_LAYER);
let player_inventory = get_player_inventory(&gs.ecs); let player_inventory = get_player_inventory(&gs.ecs);
let count = player_inventory.len(); let count = player_inventory.len();
@ -1021,7 +1022,7 @@ pub fn show_inventory(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Optio
ctx.draw_box(x, y, width + 2, (count + 1) as i32, RGB::named(WHITE), RGB::named(BLACK)); ctx.draw_box(x, y, width + 2, (count + 1) as i32, RGB::named(WHITE), RGB::named(BLACK));
print_options(&player_inventory, x + 1, y + 1, ctx); print_options(&player_inventory, x + 1, y + 1, ctx);
ctx.set_active_console(0); ctx.set_active_console(TILE_LAYER);
match ctx.key { match ctx.key {
None => (ItemMenuResult::NoResponse, None), None => (ItemMenuResult::NoResponse, None),

View file

@ -12,6 +12,7 @@ use super::{
}; };
use crate::TileType; use crate::TileType;
use crate::data::ids::*; use crate::data::ids::*;
use crate::data::prelude::*;
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use specs::prelude::*; use specs::prelude::*;
@ -45,7 +46,7 @@ impl Tooltip {
return (self.lines.len() as i32) + 2i32; return (self.lines.len() as i32) + 2i32;
} }
fn render(&self, ctx: &mut BTerm, x: i32, y: i32) { fn render(&self, ctx: &mut BTerm, x: i32, y: i32) {
ctx.set_active_console(1); ctx.set_active_console(TEXT_LAYER);
ctx.draw_box( ctx.draw_box(
x, x,
y, y,
@ -57,7 +58,7 @@ impl Tooltip {
for (i, s) in self.lines.iter().enumerate() { for (i, s) in self.lines.iter().enumerate() {
ctx.print_color(x + 1, y + (i as i32) + 1, s.1, RGB::named(BLACK), &s.0); ctx.print_color(x + 1, y + (i as i32) + 1, s.1, RGB::named(BLACK), &s.0);
} }
ctx.set_active_console(0); ctx.set_active_console(TILE_LAYER);
} }
} }
@ -177,9 +178,9 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) {
arrow = to_cp437('←'); arrow = to_cp437('←');
arrow_x = (mouse_pos.0 + 1) * 2; arrow_x = (mouse_pos.0 + 1) * 2;
} }
ctx.set_active_console(1); ctx.set_active_console(TEXT_LAYER);
ctx.set(arrow_x, arrow_y, white, RGB::named(BLACK), arrow); ctx.set(arrow_x, arrow_y, white, RGB::named(BLACK), arrow);
ctx.set_active_console(0); ctx.set_active_console(TILE_LAYER);
let mut total_height = 0; let mut total_height = 0;
for t in tooltips.iter() { for t in tooltips.iter() {

View file

@ -8,18 +8,23 @@ const DISPLAYHEIGHT: i32 = 56;
fn main() -> BError { fn main() -> BError {
// Embedded resources for use in wasm build // Embedded resources for use in wasm build
const CURSES_16_16_BYTES: &[u8] = include_bytes!("../resources/curses16x16.png"); {
const CURSES_8_16_BYTES: &[u8] = include_bytes!("../resources/curses8x16.png"); const WORLD_16_16_BYTES: &[u8] = include_bytes!("../resources/world16x16.png");
const SINGLE_1_1_BYTES: &[u8] = include_bytes!("../resources/healthbar22x2.png"); const CURSES_16_16_BYTES: &[u8] = include_bytes!("../resources/curses16x16.png");
bracket_lib::terminal::EMBED const CURSES_8_16_BYTES: &[u8] = include_bytes!("../resources/curses8x16.png");
.lock() const SINGLE_1_1_BYTES: &[u8] = include_bytes!("../resources/healthbar22x2.png");
.add_resource("resources/curses16x16.png".to_string(), CURSES_16_16_BYTES); let mut lock = bracket_lib::terminal::EMBED.lock();
bracket_lib::terminal::EMBED lock.add_resource("resources/world16x16.png".to_string(), WORLD_16_16_BYTES);
.lock() lock.add_resource("resources/curses16x16.png".to_string(), CURSES_16_16_BYTES);
.add_resource("resources/curses8x16.png".to_string(), CURSES_8_16_BYTES); lock.add_resource("resources/curses8x16.png".to_string(), CURSES_8_16_BYTES);
bracket_lib::terminal::EMBED lock.add_resource("resources/healthbar22x2.png".to_string(), SINGLE_1_1_BYTES);
.lock() }
.add_resource("resources/healthbar22x2.png".to_string(), SINGLE_1_1_BYTES);
let world_sheet = SpriteSheet {
filename: "resources/world16x16.png".to_string(),
sprites: register_spritesheet(16, 16, 19, 16),
backing: None,
};
let mut context = BTermBuilder::new() let mut context = BTermBuilder::new()
.with_title("rust-rl") .with_title("rust-rl")
@ -29,7 +34,10 @@ fn main() -> BError {
.with_font("healthbar22x2.png", 1, 1) .with_font("healthbar22x2.png", 1, 1)
.with_tile_dimensions(16, 16) .with_tile_dimensions(16, 16)
.with_gutter(2) .with_gutter(2)
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "curses16x16.png") .with_sprite_console(DISPLAYWIDTH * 16, DISPLAYHEIGHT * 16, 0)
.with_sprite_sheet(world_sheet)
.with_simple_console_no_bg(DISPLAYWIDTH, DISPLAYHEIGHT, "curses16x16.png")
.with_simple_console_no_bg(DISPLAYWIDTH, DISPLAYHEIGHT, "curses16x16.png")
.with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses8x16.png") .with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses8x16.png")
.with_sparse_console(DISPLAYWIDTH * 16, DISPLAYHEIGHT * 16, "healthbar22x2.png") .with_sparse_console(DISPLAYWIDTH * 16, DISPLAYHEIGHT * 16, "healthbar22x2.png")
.build()?; .build()?;
@ -37,6 +45,19 @@ fn main() -> BError {
context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn); 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 { let mut gs = State {
ecs: World::new(), ecs: World::new(),
mapgen_next_state: Some(RunState::MainMenu { mapgen_next_state: Some(RunState::MainMenu {
@ -149,3 +170,15 @@ fn main() -> BError {
main_loop(context, gs) main_loop(context, gs)
} }
fn register_spritesheet(width: i32, height: i32, rows: i32, columns: i32) -> Vec<Sprite> {
let mut sprites: Vec<Sprite> = Vec::new();
for y in 0..rows {
for x in 0..columns {
sprites.push(
Sprite::new(Rect::with_size(x * width + 1, y * height + 1, width, height))
);
}
}
sprites
}

View file

@ -5,6 +5,22 @@ use crate::data::ids::*;
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use std::ops::{ Add, Mul }; use std::ops::{ Add, Mul };
pub fn get_sprite_for_id(idx: usize, map: &Map, other_pos: Option<Point>) -> (usize, RGBA) {
let x = (idx as i32) % map.width;
let y = (idx as i32) / map.width;
let tile = map.tiles[idx];
let base = match tile {
TileType::Wall => wall_sprite(tile.sprite(), map, x, y),
_ => tile.sprite(),
};
let sprite_id = pick_variant(base, tile.variants(), idx, map);
let tint = if !map.visible_tiles[idx] {
RGBA::from_f32(0.75, 0.75, 0.75, 1.0)
} else {
RGBA::named(WHITE)
};
return (sprite_id, tint);
}
/// Gets the renderables for a tile, with darkening/offset/post-processing/etc. Passing a val for "debug" will ignore viewshed. /// 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( pub fn get_tile_renderables_for_id(
idx: usize, idx: usize,
@ -142,6 +158,20 @@ fn is_revealed_and_wall(map: &Map, x: i32, y: i32, debug: Option<bool>) -> bool
(if debug.is_none() { map.revealed_tiles[idx] } else { true }) (if debug.is_none() { map.revealed_tiles[idx] } else { true })
} }
fn wall_sprite(id: usize, map: &Map, x: i32, y: i32) -> usize {
if y > map.height - (2 as i32) {
return id;
}
if is_revealed_and_wall(map, x, y + 1, None) {
return id + 6;
}
return id;
}
fn pick_variant(base: usize, variants: usize, idx: usize, map: &Map) -> usize {
return base + ((map.colour_offset[idx].0.0 * (variants as f32)) as usize);
}
fn wall_glyph(map: &Map, x: i32, y: i32, debug: Option<bool>) -> FontCharType { fn wall_glyph(map: &Map, x: i32, y: i32, debug: Option<bool>) -> FontCharType {
if if
x < 1 || x < 1 ||

View file

@ -1,4 +1,5 @@
use serde::{ Deserialize, Serialize }; use serde::{ Deserialize, Serialize };
use crate::data::sprites::*;
#[derive(PartialEq, Eq, Hash, Copy, Clone, Serialize, Deserialize, Debug)] #[derive(PartialEq, Eq, Hash, Copy, Clone, Serialize, Deserialize, Debug)]
pub enum TileType { pub enum TileType {
@ -27,6 +28,57 @@ pub enum TileType {
ToOvermap(i32), ToOvermap(i32),
ToLocal(i32), ToLocal(i32),
} }
impl TileType {
pub fn sprite(&self) -> usize {
match self {
TileType::ImpassableMountain => STATUE,
TileType::Wall => WALL_BASE,
TileType::DeepWater => WATER_DEEP,
TileType::Fence => WALL_BASE,
TileType::Bars => WALL_BASE,
TileType::Floor => FLOOR,
TileType::WoodFloor => FLOOR_WOOD,
TileType::Gravel => FLOOR,
TileType::Road => PATH_GRASS,
TileType::Grass => FLOOR_GRASS,
TileType::Foliage => FLOOR_GRASS,
TileType::HeavyFoliage => FLOOR_GRASS,
TileType::Sand => FLOOR,
TileType::ShallowWater => WATER_DEEP,
TileType::Bridge => FLOOR,
TileType::DownStair => STAIR_D,
TileType::UpStair => STAIR_A,
TileType::ToLocal(_) => MUSHROOM,
TileType::ToOvermap(_) => MUSHROOM_ORANGE,
}
}
pub fn variants(&self) -> usize {
match self {
TileType::ImpassableMountain => 1,
TileType::Wall => 4,
TileType::DeepWater => 2,
TileType::Fence => 1,
TileType::Bars => 1,
TileType::Floor => 6,
TileType::WoodFloor => 3,
TileType::Gravel => 1,
TileType::Road => 4,
TileType::Grass => 6,
TileType::Foliage => 1,
TileType::HeavyFoliage => 1,
TileType::Sand => 1,
TileType::ShallowWater => 2,
TileType::Bridge => 1,
TileType::DownStair => 1,
TileType::UpStair => 1,
TileType::ToLocal(_) => 1,
TileType::ToOvermap(_) => 1,
}
}
}
pub fn tile_walkable(tt: TileType) -> bool { pub fn tile_walkable(tt: TileType) -> bool {
match tt { match tt {
| TileType::ImpassableMountain | TileType::ImpassableMountain

View file

@ -23,6 +23,7 @@ use crate::camera;
use crate::saveload_system; use crate::saveload_system;
use crate::morgue; use crate::morgue;
use crate::damage_system; use crate::damage_system;
use crate::data::prelude::*;
pub struct State { pub struct State {
pub ecs: World, pub ecs: World,
@ -164,12 +165,16 @@ impl GameState for State {
new_runstate = *runstate; new_runstate = *runstate;
} }
// Clear screen // Clear screen
ctx.set_active_console(2);
ctx.cls();
ctx.set_active_console(1);
ctx.cls();
ctx.set_active_console(0); ctx.set_active_console(0);
ctx.cls(); ctx.cls();
ctx.set_active_console(HP_BAR_LAYER);
ctx.cls();
ctx.set_active_console(TEXT_LAYER);
ctx.cls();
ctx.set_active_console(ENTITY_LAYER);
ctx.cls();
ctx.set_active_console(TILE_LAYER);
ctx.cls();
particle_system::particle_ticker(&mut self.ecs, ctx); particle_system::particle_ticker(&mut self.ecs, ctx);
match new_runstate { match new_runstate {
@ -564,12 +569,16 @@ impl GameState for State {
new_runstate = self.mapgen_next_state.unwrap(); new_runstate = self.mapgen_next_state.unwrap();
} }
if self.mapgen_history.len() != 0 { 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); ctx.set_active_console(0);
ctx.cls(); ctx.cls();
ctx.set_active_console(HP_BAR_LAYER);
ctx.cls();
ctx.set_active_console(TEXT_LAYER);
ctx.cls();
ctx.set_active_console(ENTITY_LAYER);
ctx.cls();
ctx.set_active_console(TILE_LAYER);
ctx.cls();
camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx); camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);
self.mapgen_timer += ctx.frame_time_ms; self.mapgen_timer += ctx.frame_time_ms;