trapdoors
This commit is contained in:
parent
bd450e806b
commit
06d5674199
10 changed files with 160 additions and 125 deletions
|
|
@ -88,6 +88,12 @@ pub struct Renderable {
|
|||
pub fg: RGB,
|
||||
pub bg: RGB,
|
||||
pub render_order: i32,
|
||||
// 0 = always on top: particle effects
|
||||
// 1 = things that should appear infront of the player: railings, etc.
|
||||
// 2 = the player
|
||||
// 3 = other mobs
|
||||
// 4 = interactable items
|
||||
// 5 = other props: table, etc.
|
||||
}
|
||||
|
||||
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
||||
|
|
@ -175,6 +181,9 @@ pub struct BlocksVisibility {}
|
|||
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Door {
|
||||
pub open: bool,
|
||||
pub locked: bool,
|
||||
pub blocks_vis: bool,
|
||||
pub blocks_move: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -271,6 +271,7 @@ impl TownBuilder {
|
|||
building.1 + building.3 / 2
|
||||
);
|
||||
build_data.map.tiles[exit_idx] = TileType::DownStair;
|
||||
build_data.spawn_list.push((exit_idx, "trapdoor".to_string()));
|
||||
let mut to_place: Vec<&str> = vec!["npc_miner", "npc_miner", "npc_guard", "prop_chair"];
|
||||
self.random_building_spawn(building, build_data, rng, &mut to_place, exit_idx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,10 +164,10 @@ fn draw_map(ecs: &World) -> String {
|
|||
if idx == map.xy_idx(point.x, point.y) {
|
||||
glyph_u16 = to_cp437('@');
|
||||
} else if crate::spatial::has_tile_content(idx) {
|
||||
let mut render_order = 0;
|
||||
let mut render_order = 4;
|
||||
crate::spatial::for_each_tile_content(idx, |e| {
|
||||
if let Some(renderable) = ecs.read_storage::<Renderable>().get(e) {
|
||||
if renderable.render_order >= render_order {
|
||||
if renderable.render_order <= render_order {
|
||||
render_order = renderable.render_order;
|
||||
glyph_u16 = renderable.glyph;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,12 +115,16 @@ pub fn try_door(i: i32, j: i32, ecs: &mut World) -> RunState {
|
|||
}
|
||||
} else {
|
||||
door.open = false;
|
||||
blocks_visibility
|
||||
.insert(potential_target, BlocksVisibility {})
|
||||
.expect("Unable to insert BlocksVisibility.");
|
||||
blocks_movement
|
||||
.insert(potential_target, BlocksTile {})
|
||||
.expect("Unable to insert BlocksTile.");
|
||||
if door.blocks_vis {
|
||||
blocks_visibility
|
||||
.insert(potential_target, BlocksVisibility {})
|
||||
.expect("Unable to insert BlocksVisibility.");
|
||||
}
|
||||
if door.blocks_move {
|
||||
blocks_movement
|
||||
.insert(potential_target, BlocksTile {})
|
||||
.expect("Unable to insert BlocksTile.");
|
||||
}
|
||||
if let Some(name) = names.get(potential_target) {
|
||||
gamelog::Logger
|
||||
::new()
|
||||
|
|
|
|||
|
|
@ -9,4 +9,13 @@ pub struct Prop {
|
|||
pub renderable: Option<Renderable>,
|
||||
pub flags: Option<Vec<String>>,
|
||||
pub effects: Option<HashMap<String, String>>,
|
||||
pub door: Option<Door>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Door {
|
||||
pub open: bool,
|
||||
pub locked: bool,
|
||||
pub blocks_vis: bool,
|
||||
pub blocks_move: bool,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,11 +53,6 @@ macro_rules! apply_flags {
|
|||
"BLOCKS_VISIBILITY" => $eb = $eb.with(BlocksVisibility {}),
|
||||
"ENTRY_TRIGGER" => $eb = $eb.with(EntryTrigger {}),
|
||||
"SINGLE_ACTIVATION" => $eb = $eb.with(SingleActivation {}),
|
||||
"DOOR" => {
|
||||
$eb = $eb.with(Door { open: false });
|
||||
$eb = $eb.with(BlocksVisibility {});
|
||||
$eb = $eb.with(BlocksTile {});
|
||||
}
|
||||
// --- EFFECT FLAGS ---
|
||||
"FOOD" => $eb = $eb.with(ProvidesNutrition {}),
|
||||
"CONSUMABLE" => $eb = $eb.with(Consumable {}),
|
||||
|
|
@ -656,6 +651,23 @@ pub fn spawn_named_prop(
|
|||
if let Some(effects_list) = &prop_template.effects {
|
||||
apply_effects!(effects_list, eb);
|
||||
}
|
||||
|
||||
if let Some(door) = &prop_template.door {
|
||||
eb = eb.with(Door {
|
||||
open: door.open,
|
||||
locked: door.locked,
|
||||
blocks_vis: door.blocks_vis,
|
||||
blocks_move: door.blocks_move,
|
||||
});
|
||||
if !door.open {
|
||||
if door.blocks_vis {
|
||||
eb = eb.with(BlocksVisibility {});
|
||||
}
|
||||
if door.blocks_move {
|
||||
eb = eb.with(BlocksTile {});
|
||||
}
|
||||
}
|
||||
}
|
||||
// BUILD THE ENTITY
|
||||
return Some(eb.build());
|
||||
}
|
||||
|
|
@ -701,11 +713,11 @@ fn get_renderable_component(
|
|||
recolour: if let Some(colour) = spriteinfo.colour {
|
||||
colour
|
||||
} else {
|
||||
false
|
||||
true
|
||||
},
|
||||
alt: spriteinfo.alt.clone(),
|
||||
offset: (x, y),
|
||||
alt_offset: (x, y),
|
||||
offset: (x, -y), // Invert y so that positive y = move upwards.
|
||||
alt_offset: (alt_x, -alt_y),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
|||
sprite: Some(SpriteInfo::colourable("@")),
|
||||
fg: RGB::named(YELLOW),
|
||||
bg: RGB::named(BLACK),
|
||||
render_order: 0,
|
||||
render_order: 2,
|
||||
})
|
||||
.with(Bleeds { colour: RGB::named(BLOODSTAIN_COLOUR) })
|
||||
.with(Player {})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue