Add traps

This commit is contained in:
2022-01-29 16:07:01 +01:00
parent 835a416013
commit 7c67291031
13 changed files with 213 additions and 42 deletions

View File

@@ -4,7 +4,7 @@ use rltk::{FontCharType, RandomNumberGenerator, RGB};
use specs::prelude::*;
use specs::saveload::{MarkedBuilder, SimpleMarker};
use crate::{AreaOfEffect, BlocksTile, CombatStats, Confusion, Consumable, DefenseBonus, EquipmentSlot, Equippable, HungerClock, HungerState, InflictsDamage, Item, MagicMapper, MAP_WIDTH, MAX_MONSTER, MeleePowerBonus, Monster, Name, Player, Position, ProvidesFood, ProvidesHealing, Ranged, Renderable, SerializeMe, Viewshed};
use crate::{AreaOfEffect, BlocksTile, CombatStats, Confusion, Consumable, DefenseBonus, EntryTrigger, EquipmentSlot, Equippable, Hidden, HungerClock, HungerState, InflictsDamage, Item, MagicMapper, MAP_WIDTH, MAX_MONSTER, MeleePowerBonus, Monster, Name, Player, Position, ProvidesFood, ProvidesHealing, Ranged, Renderable, SerializeMe, SingleActivation, Viewshed};
use crate::random_table::RandomTable;
use crate::rect::Rect;
@@ -127,6 +127,7 @@ pub fn spawn_room(ecs: &mut World, room: &Rect, map_depth: i32) {
"Sabatons" => sabatons(ecs, x, y),
"Rations" => rations(ecs, x, y),
"Magic Mapping Scroll" => magic_mapper_scroll(ecs, x, y),
"Bear Trap" => bear_trap(ecs, x, y),
_ => {}
}
}
@@ -230,6 +231,7 @@ pub fn room_table(map_depth: i32) -> RandomTable {
.add("Sabatons", map_depth - 4)
.add("Rations", 10)
.add("Magic Mapping Scroll", 2)
.add("Bear Trap", 2)
}
fn dagger(ecs: &mut World, x: i32, y: i32) {
@@ -438,4 +440,24 @@ fn magic_mapper_scroll(ecs: &mut World, x: i32, y: i32) {
.with(MagicMapper {})
.marked::<SimpleMarker<SerializeMe>>()
.build();
}
}
fn bear_trap(ecs: &mut World, x: i32, y: i32) {
ecs.create_entity()
.with(Position { x, y })
.with(Renderable {
glyph: rltk::to_cp437('^'),
render_order: 2,
fg: RGB::named(rltk::RED),
bg: RGB::named(rltk::BLACK),
})
.with(Name {
name: "Bear Trap".to_string(),
})
.with(Hidden {})
.with(EntryTrigger {})
.with(InflictsDamage { damage: 6 })
.with(SingleActivation {})
.marked::<SimpleMarker<SerializeMe>>()
.build();
}