FINISHED THE BOOK

This commit is contained in:
Tyrel Souza 2021-08-31 23:55:04 -04:00
parent 488e73ea46
commit 8c007af22e
8 changed files with 64 additions and 24 deletions

View File

@ -9,4 +9,7 @@ edition = "2018"
bracket-lib = "~0.8.1"
legion = "~0.3.1"
serde = { version = "=1.0.115"}
ron = "=0.6.1"
ron = "=0.6.1"
[profile.release]
lto = "thin"

View File

@ -55,10 +55,26 @@ Templates(
Template(
entity_type: Item,
name : "Rusty Sword",
glyph: '/',
glyph: 's',
levels : [0,1,2],
frequency: 2,
frequency: 1,
base_damage: Some(1)
),
Template(
entity_type: Item,
name : "Shiny Sword",
glyph: 'S',
levels : [0,1,2],
frequency: 1,
base_damage: Some(2)
)
),
Template(
entity_type: Item,
name : "Huge Sword",
glyph: '/',
levels : [1,2],
frequency: 1,
base_damage: Some(3)
),
]
)

View File

@ -11,10 +11,10 @@ mod prelude {
pub use legion::systems::CommandBuffer;
pub use legion::world::SubWorld;
pub use legion::*;
pub const SCREEN_WIDTH: i32 = 80;
pub const SCREEN_HEIGHT: i32 = 50;
pub const DISPLAY_WIDTH: i32 = SCREEN_WIDTH / 2;
pub const DISPLAY_HEIGHT: i32 = SCREEN_HEIGHT / 2;
pub const SCREEN_WIDTH: i32 = 100;
pub const SCREEN_HEIGHT: i32 = 80;
pub const DISPLAY_WIDTH: i32 = 40;
pub const DISPLAY_HEIGHT: i32 = 25;
pub use crate::camera::*;
pub use crate::components::*;
pub use crate::map::*;

View File

@ -7,7 +7,6 @@ mod themes;
use automata::CellularAutomataArchitect;
use drunkard::DrunkardsWalkArchitect;
use empty::EmptyArchitect;
use rooms::RoomsArchitect;
use themes::*;

View File

@ -2,17 +2,18 @@ use crate::prelude::*;
const FORTRESS: (&str, i32, i32) = (
"
#-##########
#-#--------#
#-#-######-#
#-#-#MMMM#-#
#-#-#MMMM#-#
#-#-#----#-#
#-#-####-#-#
#-#------#-#
#-########-#
#----------#
############
------------
-##########-
----------#-
-########-#-
-#------#-#-
-#-####-#-#-
-#-#MMMM#-#-
-#-#MMMM#-#-
-#-######-#-
-#--------#-
-##########-
------------
",
12,
11,

View File

@ -12,12 +12,14 @@ pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) {
.iter(ecs)
.map(|(entity, attack)| (*entity, attack.attacker, attack.victim))
.collect();
victims.iter().for_each(|(message, attacker, victim)| {
let is_player = ecs
.entry_ref(*victim)
.unwrap()
.get_component::<Player>()
.is_ok();
let base_damage = if let Ok(v) = ecs.entry_ref(*attacker) {
if let Ok(dmg) = v.get_component::<Damage>() {
dmg.0
@ -26,16 +28,21 @@ pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) {
}
} else {
0
};
}; // (1)
let weapon_damage: i32 = <(&Carried, &Damage)>::query()
.iter(ecs)
.filter(|(carried, _)| carried.0 == *attacker)
.map(|(_, dmg)| dmg.0)
.sum();
.sum(); // (2)
let final_damage = base_damage + weapon_damage;
if let Ok(mut health) = ecs.entry_mut(*victim).unwrap().get_component::<Health>() {
if let Ok(mut health) = ecs
.entry_mut(*victim)
.unwrap()
.get_component_mut::<Health>()
{
health.current -= final_damage;
if health.current < 1 && !is_player {
commands.remove(*victim);

View File

@ -29,7 +29,7 @@ pub fn hud(ecs: &SubWorld) {
ColorPair::new(WHITE, RED),
);
let (player, map_level) = <(Entity, &Player)>::query()
let (_player, map_level) = <(Entity, &Player)>::query()
.iter(ecs)
.find_map(|(entity, player)| Some((*entity, player.map_level)))
.unwrap();

View File

@ -7,6 +7,7 @@ use crate::prelude::*;
#[write_component(Health)]
#[read_component(Item)]
#[read_component(Carried)]
#[read_component(Weapon)]
pub fn player_input(
ecs: &mut SubWorld,
commands: &mut CommandBuffer,
@ -25,6 +26,7 @@ pub fn player_input(
.iter(ecs)
.find_map(|(entity, pos)| Some((*entity, *pos)))
.unwrap();
let mut items = <(Entity, &Item, &Point)>::query();
items
.iter(ecs)
@ -32,7 +34,19 @@ pub fn player_input(
.for_each(|(entity, _item, _item_pos)| {
commands.remove_component::<Point>(*entity);
commands.add_component(*entity, Carried(player));
if let Ok(e) = ecs.entry_ref(*entity) {
if e.get_component::<Weapon>().is_ok() {
<(Entity, &Carried, &Weapon)>::query()
.iter(ecs)
.filter(|(_, c, _)| c.0 == player)
.for_each(|(e, _c, _w)| {
commands.remove(*e);
})
}
}
});
Point::new(0, 0)
}
VirtualKeyCode::Key1 => use_item(0, ecs, commands),