Skip to content

Commit

Permalink
Add sound effect for combat.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankopf committed Aug 8, 2023
1 parent 11962f6 commit e4c5915
Show file tree
Hide file tree
Showing 108 changed files with 42 additions and 41 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ opt-level = 3
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "*"
bevy = { version = "*", features = [ "wav" ] }
rand = "*"
winit = "0.27.5"
image = "*"
Expand Down
Binary file added assets/RPG Sound Pack/.DS_Store
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/beetle/.DS_Store
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/beetle/bite-small.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/beetle/bite-small2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/beetle/bite-small3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/giant/.DS_Store
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/giant/giant1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/giant/giant2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/giant/giant3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/giant/giant4.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/giant/giant5.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/misc/.DS_Store
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/misc/wolfman.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/ogre/.DS_Store
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/ogre/ogre1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/ogre/ogre2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/ogre/ogre3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/ogre/ogre4.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/ogre/ogre5.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade10.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade11.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade12.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade13.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade14.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade15.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade4.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade5.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade6.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade7.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade8.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/shade/shade9.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime10.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime4.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime5.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime6.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime7.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime8.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/NPC/slime/slime9.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/battle/magic1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/battle/spell.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/battle/swing.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/battle/swing2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/battle/swing3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/battle/sword-unsheathe.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added assets/RPG Sound Pack/interface/interface1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/interface/interface2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/interface/interface3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/interface/interface4.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/interface/interface5.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/interface/interface6.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/armor-light.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/beads.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/bottle.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/bubble.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/bubble2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/bubble3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/chainmail1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/chainmail2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/cloth-heavy.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/cloth.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/coin.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/coin2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/coin3.wav
Binary file not shown.
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/metal-small1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/metal-small2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/metal-small3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/inventory/wood-small.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/misc/burp.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/misc/random1.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/misc/random2.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/misc/random3.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/misc/random4.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/misc/random5.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/misc/random6.wav
Binary file not shown.
Binary file added assets/RPG Sound Pack/world/door.wav
Binary file not shown.
18 changes: 15 additions & 3 deletions src/combat_system/melee.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::*;
use crate::{prelude::*, initializations::load::SoundEffect};

pub fn combat_system_melee(
mut commands: Commands,
Expand Down Expand Up @@ -104,24 +104,36 @@ fn do_melee_damage(
attacked_entity: Entity,
body1: &PhysicalBody,
body2: &mut PhysicalBody,
asset_server: &Res<AssetServer>
) {
body2.attributes.health -=
let damage =
1 +
(body1.attributes.strength - body2.attributes.constitution).max(0).min(20) +
(body1.skillset.brawling.level()).max(0).min(20)
;
body2.attributes.health -= damage;
if body2.attributes.health <= 0 {
commands.entity(attacked_entity).despawn_recursive();
}
body2.danger = Some(Danger {
danger_type: DangerType::Attacked,
danger_source: attacker_entity,
});

// 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,
));
}
pub fn attacked_entities_system(
mut commands: Commands,
attacked_query: Query<(Entity, &Attacked), With<Attacked>>,
mut physical_bodies: Query<(Entity, &mut PhysicalBody)>,
asset_server: Res<AssetServer>
) {
for (attacked_entity, attack_info) in attacked_query.iter() {
commands.entity(attacked_entity).remove::<Attacked>();
Expand All @@ -139,7 +151,7 @@ pub fn attacked_entities_system(
// Now do the damage to the attacked body.
for (entity, mut physical_body) in physical_bodies.iter_mut() {
if entity == attacked_entity {
do_melee_damage(&mut commands, attacker_entity, attacked_entity, &attacker_physical_body, &mut physical_body);
do_melee_damage(&mut commands, attacker_entity, attacked_entity, &attacker_physical_body, &mut physical_body, &asset_server);
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/initializations/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ pub fn load_font(
mut font_handle: ResMut<MyFont>,
) {
*font_handle = MyFont(asset_server.load("fonts/Helvetica.ttf"));
}
}
pub fn load_sfx(
mut commands: Commands,
asset_server: Res<AssetServer>
) {
// commands.spawn((
// AudioBundle {
// source: asset_server.load("RPG Sound Pack/battle/swing.wav"),
// settings: PlaybackSettings::ONCE.paused().with_volume(bevy::audio::Volume::new_relative(0.5)),
// },
// SoundEffect,
// ));
}

#[derive(Component)]
pub struct SoundEffect;
35 changes: 1 addition & 34 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
// use bevy::time::FixedTimestep;
mod prelude;
pub use crate::prelude::*;

// #[mod_use(
// biome,
// button_system,
// combat_system,
// components,
// constants,
// interface,
// load,
// main_menu,
// map,
// monstergenerator_system,
// moverandom_system,
// movetoward_system,
// namegiving_system,
// names_system,
// needs,
// pause,
// resources,
// seasons,
// selection_systems,
// spoilage_system,
// startup,
// statusdisplay_system,
// task_system,
// text_system,
// thinking_system,
// unitgenerator_system,
// window_system
// )]
mod button_system;
use button_system::*;
mod combat_system;
Expand Down Expand Up @@ -84,10 +54,7 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugin(BiomePlugin)
.add_systems(
PreStartup, (load_sprites, load_font)
)
.add_systems(
PreStartup, (load_sprites, load_font)
PreStartup, (load_sprites, load_font, load_sfx)
)
// .add_startup_system_to_stage(StartupStage::PreStartup, load_sprites)
// .add_startup_system_to_stage(StartupStage::PreStartup, load_font)
Expand Down
4 changes: 2 additions & 2 deletions src/unitgenerator_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn spawn_unit_from_template(
position: Position,
sprite_sheet: &Res<SpriteSheet>,
template: &UnitTemplate,
) {
) -> Entity {
let sprite = TextureAtlasSprite::new(template.actor_type.sprite_index());
commands
.spawn(SpriteSheetBundle {
Expand All @@ -39,7 +39,7 @@ pub fn spawn_unit_from_template(
attributes: template.attributes.clone(),
} )
.insert( Brain { ..default() } )
;
.id()
}

pub struct UnitTemplate {
Expand Down

0 comments on commit e4c5915

Please sign in to comment.