From 8c007af22eb228a2837cc8987d34e86e14405ccf Mon Sep 17 00:00:00 2001 From: Tyrel Souza <923113+tyrelsouza@users.noreply.github.com> Date: Tue, 31 Aug 2021 23:55:04 -0400 Subject: [PATCH] FINISHED THE BOOK --- Cargo.toml | 5 ++++- resources/template.ron | 22 +++++++++++++++++++--- src/main.rs | 8 ++++---- src/map_builder/mod.rs | 1 - src/map_builder/prefab.rs | 23 ++++++++++++----------- src/systems/combat.rs | 13 ++++++++++--- src/systems/hud.rs | 2 +- src/systems/player_input.rs | 14 ++++++++++++++ 8 files changed, 64 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4abd1fd..3b42095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,7 @@ edition = "2018" bracket-lib = "~0.8.1" legion = "~0.3.1" serde = { version = "=1.0.115"} -ron = "=0.6.1" \ No newline at end of file +ron = "=0.6.1" + +[profile.release] +lto = "thin" \ No newline at end of file diff --git a/resources/template.ron b/resources/template.ron index d2964ab..5656e3c 100644 --- a/resources/template.ron +++ b/resources/template.ron @@ -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) + ), ] ) \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3e536b2..b92b40b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::*; diff --git a/src/map_builder/mod.rs b/src/map_builder/mod.rs index e9932a7..1b43034 100644 --- a/src/map_builder/mod.rs +++ b/src/map_builder/mod.rs @@ -7,7 +7,6 @@ mod themes; use automata::CellularAutomataArchitect; use drunkard::DrunkardsWalkArchitect; -use empty::EmptyArchitect; use rooms::RoomsArchitect; use themes::*; diff --git a/src/map_builder/prefab.rs b/src/map_builder/prefab.rs index 9b001da..1b1cedd 100644 --- a/src/map_builder/prefab.rs +++ b/src/map_builder/prefab.rs @@ -2,17 +2,18 @@ use crate::prelude::*; const FORTRESS: (&str, i32, i32) = ( " -#-########## -#-#--------# -#-#-######-# -#-#-#MMMM#-# -#-#-#MMMM#-# -#-#-#----#-# -#-#-####-#-# -#-#------#-# -#-########-# -#----------# -############ +------------ +-##########- +----------#- +-########-#- +-#------#-#- +-#-####-#-#- +-#-#MMMM#-#- +-#-#MMMM#-#- +-#-######-#- +-#--------#- +-##########- +------------ ", 12, 11, diff --git a/src/systems/combat.rs b/src/systems/combat.rs index 7f38b4a..18da979 100644 --- a/src/systems/combat.rs +++ b/src/systems/combat.rs @@ -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::() .is_ok(); + let base_damage = if let Ok(v) = ecs.entry_ref(*attacker) { if let Ok(dmg) = v.get_component::() { 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::() { + if let Ok(mut health) = ecs + .entry_mut(*victim) + .unwrap() + .get_component_mut::() + { health.current -= final_damage; if health.current < 1 && !is_player { commands.remove(*victim); diff --git a/src/systems/hud.rs b/src/systems/hud.rs index 576dab9..e6248df 100644 --- a/src/systems/hud.rs +++ b/src/systems/hud.rs @@ -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(); diff --git a/src/systems/player_input.rs b/src/systems/player_input.rs index 3ec8028..8a6b79a 100644 --- a/src/systems/player_input.rs +++ b/src/systems/player_input.rs @@ -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::(*entity); commands.add_component(*entity, Carried(player)); + + if let Ok(e) = ecs.entry_ref(*entity) { + if e.get_component::().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),