From b62f2759de6f67ce60511e00d8166556a40d4e7d Mon Sep 17 00:00:00 2001 From: Alex Page Date: Tue, 1 Feb 2022 02:56:45 -0500 Subject: [PATCH] Add score for touching/whipping monsters --- src/resources/mod.rs | 4 ++++ src/state.rs | 1 + src/systems/whip_system.rs | 9 ++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 08af502..df734a6 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -70,4 +70,8 @@ impl Stats { true } } + + pub fn add_score(&mut self, score: u32) { + self.score += score; + } } diff --git a/src/state.rs b/src/state.rs index d035268..45232c9 100644 --- a/src/state.rs +++ b/src/state.rs @@ -144,6 +144,7 @@ impl State { } else { if let Some(e) = map.get_tile_content_at(destination) { if let Some(monster) = monsters.get(e) { + stats.add_score(damage_for_kind(monster.kind)); stats.take_gems(damage_for_kind(monster.kind)); sound_output.play_sound(sound_effect_for_kind( monster.kind, diff --git a/src/systems/whip_system.rs b/src/systems/whip_system.rs index f9b5ff1..4ffe493 100644 --- a/src/systems/whip_system.rs +++ b/src/systems/whip_system.rs @@ -4,8 +4,8 @@ use bracket_lib::prelude::*; use specs::prelude::*; use crate::{ - components::{Monster, Position, WantsToWhip}, - resources::{Map, SoundEffects, SoundOutput, StopClock}, + components::{monster::damage_for_kind, Monster, Position, WantsToWhip}, + resources::{Map, SoundEffects, SoundOutput, Stats, StopClock}, }; pub struct WhipSystem {} @@ -17,6 +17,7 @@ impl<'a> System<'a> for WhipSystem { WriteExpect<'a, StopClock>, WriteExpect<'a, SoundOutput>, ReadExpect<'a, SoundEffects>, + WriteExpect<'a, Stats>, ReadStorage<'a, Position>, WriteStorage<'a, WantsToWhip>, WriteStorage<'a, Monster>, @@ -29,6 +30,7 @@ impl<'a> System<'a> for WhipSystem { mut stop_clock, mut sound_output, sound_effects, + mut stats, positions, mut wants_to_whips, monsters, @@ -93,7 +95,8 @@ impl<'a> System<'a> for WhipSystem { if let Some(dest) = destination { if let Some(e) = map.get_tile_content_at(dest) { - if let Some(_monster) = monsters.get(e) { + if let Some(monster) = monsters.get(e) { + stats.add_score(damage_for_kind(monster.kind)); let _ = entities.delete(e); map.clear_tile_content_at(dest); if let Some(sound) = &mut wants_to_whip.sound {