Skip to content

Commit

Permalink
Adding death. Removing iyessloopless
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankopf committed Aug 8, 2023
1 parent 0dcd91e commit 2357c9a
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 396 deletions.
526 changes: 154 additions & 372 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ bevy = { version = "*", features = [ "wav" ] }
rand = "*"
winit = "0.28.6"
image = "*"
iyes_loopless = "*"

[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"
5 changes: 5 additions & 0 deletions src/combat_system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::prelude::*;
mod death;
mod melee;
mod ranged;

Expand All @@ -25,6 +26,10 @@ impl Plugin for CombatPlugin {
.run_if(in_state(GameState::InGame)),
)
)
.add_systems(
Update,
death::death_system
)
// .add_system(
// ranged::combat_system_ranged
// .run_if(bevy::time::common_conditions::on_timer(bevy::utils::Duration::from_secs_f32(0.5)))
Expand Down
11 changes: 11 additions & 0 deletions src/combat_system/death.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::prelude::*;

pub fn death_system(
mut commands: Commands,
mut entities: Query<(Entity, &mut Brain, &mut PhysicalBody, &Position), With<Dying>>,
) {
for (entity, mut brain, mut physical_body, position) in entities.iter_mut() {
commands.entity(entity).despawn_recursive();
// TO DO: Make a corpse and drop loot.
}
}
16 changes: 8 additions & 8 deletions src/combat_system/melee.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{prelude::*, initializations::load::SoundEffect};
use crate::prelude::*;

pub fn combat_system_melee(
mut commands: Commands,
Expand Down Expand Up @@ -121,13 +121,13 @@ fn do_melee_damage(
});

// Play a sound effect.
commands.spawn((
AudioBundle {
source: asset_server.load("RPG Sound Pack/battle/swing.wav"),
settings: PlaybackSettings::ONCE.with_volume(bevy::audio::Volume::new_relative(0.1)),
},
SoundEffect,
));
// commands.spawn((
// AudioBundle {
// source: asset_server.load("RPG Sound Pack/battle/swing.wav"),
// settings: PlaybackSettings::ONCE.with_volume(bevy::audio::Volume::new_relative(0.1)),
// },
// SoundEffect,
// ));
}
pub fn attacked_entities_system(
mut commands: Commands,
Expand Down
34 changes: 32 additions & 2 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ pub struct PhysicalBody {
pub skillset: Skillset,
pub attributes: Attributeset,
}
impl InfoPanel for PhysicalBody {
fn info_panel(&self) -> Vec<String> {
impl PhysicalBody {
pub fn info_panel_needs(&self) -> Vec<String> {
let mut info_lines = Vec::new();
if let Some(needs_food) = &self.needs_food {
info_lines.push(format!("Food: {:.2}%", needs_food.current / needs_food.max * 100.0));
Expand All @@ -413,11 +413,41 @@ impl InfoPanel for PhysicalBody {
}
info_lines
}
pub fn info_panel_attributes(&self) -> Vec<String> {
let mut info_lines = Vec::new();
info_lines.push(format!("Health: {}", self.attributes.health));
info_lines.push(format!("Strength: {}", self.attributes.strength));
info_lines.push(format!("Dexterity: {}", self.attributes.dexterity));
info_lines.push(format!("Constitution: {}", self.attributes.constitution));
info_lines.push(format!("Intelligence: {}", self.attributes.intelligence));
info_lines.push(format!("Wisdom: {}", self.attributes.wisdom));
info_lines.push(format!("Charisma: {}", self.attributes.charisma));
info_lines
}
pub fn info_panel_skills(&self) -> Vec<String> {
let mut info_lines = Vec::new();
info_lines.push(format!("Animal Raising: {} ({} xp)", self.skillset.animal_raising.level(), self.skillset.animal_raising.experience));
info_lines.push(format!("Brawling: {} ({} xp)", self.skillset.brawling.level(), self.skillset.brawling.experience));
info_lines.push(format!("Construction: {} ({} xp)", self.skillset.construction.level(), self.skillset.construction.experience));
info_lines.push(format!("Cooking: {} ({} xp)", self.skillset.cooking.level(), self.skillset.cooking.experience));
info_lines.push(format!("Crafting: {} ({} xp)", self.skillset.crafting.level(), self.skillset.crafting.experience));
info_lines.push(format!("Doctoring: {} ({} xp)", self.skillset.doctoring.level(), self.skillset.doctoring.experience));
info_lines.push(format!("Farming: {} ({} xp)", self.skillset.farming.level(), self.skillset.farming.experience));
info_lines.push(format!("Fishing: {} ({} xp)", self.skillset.fishing.level(), self.skillset.fishing.experience));
info_lines.push(format!("Foraging: {} ({} xp)", self.skillset.foraging.level(), self.skillset.foraging.experience));
info_lines.push(format!("Hunting: {} ({} xp)", self.skillset.hunting.level(), self.skillset.hunting.experience));
info_lines.push(format!("Mining: {} ({} xp)", self.skillset.mining.level(), self.skillset.mining.experience));
info_lines.push(format!("Social: {} ({} xp)", self.skillset.social.level(), self.skillset.social.experience));
info_lines.push(format!("Woodcutting: {} ({} xp)", self.skillset.woodcutting.level(), self.skillset.woodcutting.experience));
info_lines
}
}
#[derive(Component)]
pub struct Attacked {
pub attacker: Entity,
}
#[derive(Component)]
pub struct Dying;

#[derive(PartialEq)]
pub enum Order {
Expand Down
4 changes: 0 additions & 4 deletions src/interface/click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ pub fn object_finder_system(
mut commands: Commands,
mut event: EventReader<ObjectFinderEvent>,
mut people: Query<(Entity, &Position, &mut Brain, Option<&PhysicalBody>, Option<&ClickedOn>)>,
mut info_panel: ResMut<InfoPanelInformation>,
) {
for event in event.iter() {
for (entity, position, _brain, physical_body, clickedon) in people.iter_mut() {
Expand All @@ -209,9 +208,6 @@ pub fn object_finder_system(
if position == &event.position {
if let Some(physical_body) = physical_body {
commands.entity(entity).insert(ClickedOn);
info_panel.info = vec![];
info_panel.info.push(format!("Position: {}, {}", position.x, position.y));
info_panel.info.extend_from_slice(&physical_body.info_panel());
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/interface/info_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,25 @@ pub fn show_info_panel(

pub fn info_system(
mut commands: Commands,
mut people: Query<(Entity, &Position, &Brain, &PhysicalBody, &ClickedOn, Option<&HasName>)>,
mut people: Query<(Entity, &Position, &Brain, &PhysicalBody, Option<&HasName>), With<ClickedOn>>,
mut info_panel: ResMut<InfoPanelInformation>,
) {
if let Some((_, position, brain, physical_body, _clickedon, has_name)) = people.iter_mut().last() {
if let Some((_, position, brain, physical_body, has_name)) = people.iter_mut().last() {
if let Some(has_name) = has_name {
info_panel.name = has_name.name.clone();
} else {
info_panel.name = String::from("");
}
info_panel.info = vec![];
info_panel.info.push(format!("Position: {}, {}", position.x, position.y));
info_panel.info.extend_from_slice(&physical_body.info_panel());
info_panel.info.extend_from_slice(&physical_body.info_panel_needs());
info_panel.info.extend_from_slice(&brain.info_panel());
info_panel.needs.extend_from_slice(&physical_body.info_panel_needs());
info_panel.attributes.extend_from_slice(&physical_body.info_panel_attributes());
info_panel.skills.extend_from_slice(&physical_body.info_panel_skills());
}
let count = people.iter().count();
for (index, (entity, _, _, _, _, _)) in people.iter_mut().enumerate() {
for (index, (entity, _, _, _, _)) in people.iter_mut().enumerate() {
if index < count - 1 {
commands.entity(entity).remove::<ClickedOn>();
}
Expand Down
4 changes: 1 addition & 3 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use super::components::{
ActorType, Affliction, AfflictionType, AfflictionLocation, Attackable, Attacked, Attributeset,
Bed, Brain, Choppable, ClickedOn, Danger, DangerType, Food, Foragable, ForageType, GameState, GeneratedBy,
Bed, Brain, Choppable, ClickedOn, Danger, DangerType, Dying, Food, Foragable, ForageType, GameState, GeneratedBy,
GiveMeAName, HasName, HasNameShown, HighlightBox, Highlighted, HoverNote, InfoPanel, InGameButton, IsName, ItemType,
Logs, MainMenuOverlay, MapTile, MenuStates, MonsterGenerator, Motivation, MoveRandom,
MoveTowardsNearestAttackable, MoveTowardsTarget, NearestEntity, Need,
Expand All @@ -12,8 +12,6 @@ pub use crate::constants::*;
pub use crate::resources::*;
pub use bevy::input::mouse::MouseWheel;
pub use bevy::prelude::*;
// pub use bevy::time::FixedTimestep;
pub use iyes_loopless::prelude::*;
pub use rand::prelude::random;
pub use rand::seq::SliceRandom;
pub use rand::Rng;
Expand Down
5 changes: 4 additions & 1 deletion src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ pub struct SelectedObjectInformation {
}
#[derive(Resource, Default)]
pub struct InfoPanelInformation {
pub info: Vec<String>,
pub name: String,
pub info: Vec<String>,
pub needs: Vec<String>,
pub attributes: Vec<String>,
pub skills: Vec<String>,
}

#[derive(Resource)]
Expand Down
1 change: 0 additions & 1 deletion src/unitgenerator_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub fn spawn_unit_from_template(
})
.insert(position)
.insert(position.to_transform_layer(1.0))
.insert(Attackable)
.insert( GiveMeAName )
.insert( PhysicalBody {
needs_food: Some(template.food_need.into()),
Expand Down

0 comments on commit 2357c9a

Please sign in to comment.