Skip to content

Commit f9dd00a

Browse files
committed
feat(sounds): Add sound effects and background music
1 parent 3593ad2 commit f9dd00a

21 files changed

+216
-17
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ cargo run --features "metal"
5050
```
5151

5252
### Credits
53+
54+
- Main theme is : Frozen Jam by tgfcoder <https://twitter.com/tgfcoder> licensed under CC-BY-3 <http://creativecommons.org/licenses/by/3.0/>
55+
- Effects : 8-bit Platformer SFX commissioned by Mark McCorkle for OpenGameArt.org ( http://opengameart.org ) && Juhani Junkala

assets/audio/air.ogg

16.5 KB
Binary file not shown.

assets/audio/bonus.ogg

6.7 KB
Binary file not shown.

assets/audio/explosion.ogg

23.7 KB
Binary file not shown.

assets/audio/fire.ogg

21.8 KB
Binary file not shown.

assets/audio/hit.ogg

9.11 KB
Binary file not shown.

assets/audio/land.ogg

7.28 KB
Binary file not shown.

assets/audio/menu_music.ogg

2.34 MB
Binary file not shown.

assets/levels/level_1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"y":0
2424
},
2525
{
26-
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 0, 0, 0, 0, 0, 0, 0, 0, 97, 0, 0, 0, 97, 0, 0, 95, 96, 0, 0, 0, 93, 94, 0, 0, 0, 0, 0, 0],
2727
"height":30,
2828
"id":3,
2929
"name":"Entities",

assets/levels/level_1.png

108 Bytes
Loading

assets/sprites/main.png

222 Bytes
Loading

src/entities/collision.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ use amethyst::core::ecs::{Component, DenseVecStorage};
33
use geo::{Polygon, LineString};
44
use geo::intersects::Intersects;
55

6+
pub struct ButtonPlatform;
7+
8+
impl Component for ButtonPlatform {
9+
type Storage = DenseVecStorage<Self>;
10+
}
11+
612
pub struct LandingPlatform;
713

814
impl Component for LandingPlatform {

src/main.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use crate::systems::score_system::ScoreSystem;
3333
use crate::states::CurrentState;
3434
use crate::systems::blade_saw_system::BladeSawSystem;
3535
use crate::systems::bonus_system::BonusSystem;
36+
use amethyst::audio::{AudioBundle, DjSystemDesc, DjSystem};
37+
use crate::utils::sound::Sounds;
3638

3739
fn main() -> amethyst::Result<()> {
3840
amethyst::start_logger(Default::default());
@@ -62,8 +64,14 @@ fn main() -> amethyst::Result<()> {
6264
.with_plugin(RenderUi::default())
6365
.with_plugin(RenderFlat2D::default())
6466
)?
67+
.with_bundle(AudioBundle::default())?
6568
.with(
66-
ShipSystem.pausable(CurrentState::Level),
69+
DjSystem::new(|music: &mut Sounds| music.menu_music.next()),
70+
"dj",
71+
&[],
72+
)
73+
.with(
74+
ShipSystem::default().pausable(CurrentState::Level),
6775
"ship_system",
6876
&["input_system"],
6977
)
@@ -93,7 +101,7 @@ fn main() -> amethyst::Result<()> {
93101
&[],
94102
)
95103
.with(
96-
BulletSystem.pausable(CurrentState::Level),
104+
BulletSystem::default().pausable(CurrentState::Level),
97105
"bullet_system",
98106
&[],
99107
).with(

src/states/main_menu_state.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::entities::ship::Ship;
1010
use amethyst::input::{is_key_down, VirtualKeyCode};
1111
use crate::states::CurrentState;
1212
use crate::states::next_level::NextLevelState;
13+
use crate::utils::sound::{initialise_audio};
1314

1415
pub struct MainMenuState;
1516

@@ -34,7 +35,7 @@ impl SimpleState for MainMenuState {
3435
add_push_enter_text(world);
3536

3637
initialize_camera(world);
37-
38+
initialise_audio(world);
3839
}
3940

4041
fn handle_event(

src/systems/bonus_system.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use amethyst::core::ecs::{System, WriteStorage, Write, ReadStorage, Read, Join};
1+
use amethyst::core::ecs::{System, WriteStorage, Write, ReadStorage, Read, Join, ReadExpect};
22
use crate::entities::bonus::{Bonus, BonusKind};
33
use amethyst::core::{Transform, Time};
44
use crate::resources::main_resource::MainResource;
@@ -7,6 +7,10 @@ use crate::utils::sprites::sprite_to_entities::init_bonus_collider;
77
use crate::entities::collision::are_colliding;
88
use amethyst::renderer::SpriteRender;
99
use crate::utils::sprites::plasma_doors::EMPTY;
10+
use amethyst::assets::AssetStorage;
11+
use crate::utils::sound::{Sounds, play_bonus};
12+
use amethyst::audio::output::Output;
13+
use amethyst::audio::Source;
1014

1115
const DEFAULT_CHANGE_DIRECTION_TIMER :f32 = 0.6;
1216

@@ -32,9 +36,12 @@ impl<'s> System<'s> for BonusSystem {
3236
ReadStorage<'s, ShipParent>,
3337
WriteStorage<'s, SpriteRender>,
3438
Read<'s, Time>,
39+
Read<'s, AssetStorage<Source>>,
40+
ReadExpect<'s, Sounds>,
41+
Option<Read<'s, Output>>,
3542
);
3643

37-
fn run(&mut self, (mut bonuses, mut transforms, mut main_resource, ships, mut sprites, time): Self::SystemData) {
44+
fn run(&mut self, (mut bonuses, mut transforms, mut main_resource, ships, mut sprites, time, storage, sounds, audio_output): Self::SystemData) {
3845
self.change_direction_timer -= time.delta_seconds();
3946
if self.change_direction_timer <= 0. {
4047
self.change_direction_timer = DEFAULT_CHANGE_DIRECTION_TIMER;
@@ -60,6 +67,7 @@ impl<'s> System<'s> for BonusSystem {
6067
main_resource.bonus_heal();
6168
}
6269
}
70+
play_bonus(&*sounds, &storage, audio_output.as_deref());
6371
bonus.taken = true;
6472
sprite.sprite_number= EMPTY;
6573
}

src/systems/bullet_system.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use amethyst::core::ecs::{System, ReadStorage, WriteStorage, Join, Read, Entities, Write};
1+
use amethyst::core::ecs::{System, ReadStorage, WriteStorage, Join, Read, Entities, Write, ReadExpect};
22
use crate::entities::canons::{Bullet, Canon, CanonKind, canon_kind_to_bullet_speed, canon_kind_to_bullet_life_duration};
33
use amethyst::core::{Transform, Time};
44
use crate::utils::Direction;
@@ -8,8 +8,24 @@ use crate::utils::sprites::sprite_to_entities::init_bullet_collider;
88
use crate::resources::main_resource::MainResource;
99
use crate::entities::ship::ShipParent;
1010
use amethyst::core::math::Vector3;
11+
use amethyst::assets::AssetStorage;
12+
use amethyst::audio::Source;
13+
use crate::utils::sound::{Sounds, play_air, play_hit};
14+
use amethyst::audio::output::Output;
1115

12-
pub struct BulletSystem;
16+
const DEFAULT_AIR_TIMER:f32= 0.2;
17+
18+
pub struct BulletSystem{
19+
pub play_air_timer: f32
20+
}
21+
22+
impl Default for BulletSystem{
23+
fn default() -> Self {
24+
BulletSystem{
25+
play_air_timer: DEFAULT_AIR_TIMER
26+
}
27+
}
28+
}
1329

1430
impl<'s> System<'s> for BulletSystem {
1531
type SystemData = (
@@ -20,9 +36,14 @@ impl<'s> System<'s> for BulletSystem {
2036
ReadStorage<'s, ShipParent>,
2137
Write<'s, MainResource>,
2238
Read<'s, Time>,
23-
Entities<'s>,);
39+
Entities<'s>,
40+
Read<'s, AssetStorage<Source>>,
41+
ReadExpect<'s, Sounds>,
42+
Option<Read<'s, Output>>,
43+
);
2444

25-
fn run(&mut self, (mut bullets, canons, mut transforms, colliders, ships,mut main_resource, time, entities): Self::SystemData) {
45+
fn run(&mut self, (mut bullets, canons, mut transforms, colliders, ships,mut main_resource, time, entities, storage, sounds, audio_output): Self::SystemData) {
46+
self.play_air_timer -= time.delta_seconds();
2647
let mut ship_polygon = Vec::new();
2748
for (_ship, transform) in (&ships, &transforms).join() {
2849
ship_polygon = main_resource.get_colliders_polygons_for_collision(transform.translation().x, transform.translation().y);
@@ -37,6 +58,10 @@ impl<'s> System<'s> for BulletSystem {
3758
if are_colliding(colliders.polygons(), &ship_polygon) {
3859
match bullet.kind {
3960
CanonKind::Air => {
61+
if self.play_air_timer <= 0. {
62+
play_air(&*sounds, &storage, audio_output.as_deref());
63+
self.play_air_timer = DEFAULT_AIR_TIMER;
64+
}
4065
match bullet.direction {
4166
Direction::Left => {main_resource.x_force -= 3. * time.delta_seconds();},
4267
Direction::Right => {main_resource.x_force += 3. * time.delta_seconds();},
@@ -45,6 +70,7 @@ impl<'s> System<'s> for BulletSystem {
4570

4671
},
4772
_=> {
73+
play_hit(&*sounds, &storage, audio_output.as_deref());
4874
main_resource.bullet_hit();
4975

5076
let _res = entities.delete(entity);

src/systems/landing_system.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
use amethyst::core::ecs::{System, ReadStorage, Write, Join};
1+
use amethyst::core::ecs::{System, ReadStorage, Write, Join, Read, ReadExpect};
22
use crate::entities::collision::{Colliders, LandingPlatform, are_colliding};
33
use crate::entities::ship::ShipParent;
44
use amethyst::core::Transform;
55
use crate::resources::main_resource::MainResource;
66
use crate::systems::ship_systems::ANGLE_ROTATION_DEGREE_MODIFIER;
77
use crate::utils::sprites::TILE_SIZE;
8+
use amethyst::assets::AssetStorage;
9+
use amethyst::audio::Source;
10+
use crate::utils::sound::{Sounds, play_land};
11+
use amethyst::audio::output::Output;
812

913
pub struct LandingSystem;
1014

@@ -14,17 +18,21 @@ impl <'s> System<'s> for LandingSystem {
1418
ReadStorage<'s, LandingPlatform>,
1519
ReadStorage<'s, ShipParent>,
1620
ReadStorage<'s, Transform>,
17-
Write<'s, MainResource>
21+
Write<'s, MainResource>,
22+
Read<'s, AssetStorage<Source>>,
23+
ReadExpect<'s, Sounds>,
24+
Option<Read<'s, Output>>,
1825
);
1926

20-
fn run(&mut self, (colliders, landing_plateforms, ships, transforms, mut ship_resource): Self::SystemData) {
27+
fn run(&mut self, (colliders, landing_plateforms, ships, transforms, mut ship_resource, storage, sounds, audio_output): Self::SystemData) {
2128
for (_ship, transform) in (&ships, &transforms).join() {
2229
let ship_polygon = ship_resource.get_colliders_polygons_for_landing(transform.translation().x, transform.translation().y);
2330
for (collider, _) in (&colliders, &landing_plateforms).join() {
2431

2532
let struct_polygons = collider.polygons();
2633
if !ship_resource.is_exploding && !ship_resource.is_landed && are_colliding(&ship_polygon, struct_polygons) {
2734
if correct_landing_position(&ship_resource, transform, collider) {
35+
play_land(&*sounds, &storage, audio_output.as_deref());
2836
ship_resource.is_landed = true;
2937
ship_resource.y_force = 0.;
3038
ship_resource.x_force = 0.;

src/systems/ship_systems.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1-
use amethyst::core::ecs::{System, WriteStorage, ReadStorage, Read, Join, Write, Entities};
1+
use amethyst::core::ecs::{System, WriteStorage, ReadStorage, Read, Join, Write, Entities, ReadExpect};
22
use amethyst::core::{Transform, Time};
33
use crate::entities::ship::{Ship, ShipParent};
44
use amethyst::input::{InputHandler, StringBindings};
55
use amethyst::renderer::{SpriteRender, SpriteSheet};
66
use crate::resources::main_resource::MainResource;
77
use amethyst::core::num::FloatConst;
88
use crate::entities::explosion::Explosion;
9-
use amethyst::assets::Handle;
9+
use amethyst::assets::{Handle, AssetStorage};
1010
use crate::utils::sprites::TILE_SIZE;
11+
use crate::utils::sound::{play_explosion, Sounds, play_fire};
12+
use amethyst::audio::Source;
13+
use amethyst::audio::output::Output;
1114

12-
pub struct ShipSystem;
15+
const DEFAULT_FIRE_TIMER:f32= 0.2;
16+
17+
pub struct ShipSystem{
18+
pub play_fire_timer: f32
19+
}
20+
21+
impl Default for ShipSystem{
22+
fn default() -> Self {
23+
ShipSystem{
24+
play_fire_timer: DEFAULT_FIRE_TIMER
25+
}
26+
}
27+
}
1328

1429
fn angle_rotation_modifier_bind_to_pi() -> f32 { f32::PI() / 96. }
1530

@@ -27,9 +42,13 @@ impl<'s> System<'s> for ShipSystem {
2742
Read<'s, Time>,
2843
WriteStorage<'s, Explosion>,
2944
Entities<'s>,
45+
Read<'s, AssetStorage<Source>>,
46+
ReadExpect<'s, Sounds>,
47+
Option<Read<'s, Output>>,
3048
);
3149

32-
fn run(&mut self, (mut transforms, ships, ships_parent, input, mut sprites, mut main_resource, time,mut explosions, entities): Self::SystemData) {
50+
fn run(&mut self, (mut transforms, ships, ships_parent, input, mut sprites, mut main_resource, time,mut explosions, entities, storage, sounds, audio_output): Self::SystemData) {
51+
self.play_fire_timer -= time.delta_seconds();
3352
if main_resource.bullet_hit_timer > 0. {
3453
main_resource.bullet_hit_timer -= time.delta_seconds();
3554
}
@@ -39,6 +58,10 @@ impl<'s> System<'s> for ShipSystem {
3958
sprite_render.sprite_number = main_resource.sprite_nb();
4059
let power = input.action_is_down("power");
4160
if main_resource.ship_fuel > 0. && power.is_some() && power.unwrap() {
61+
if self.play_fire_timer <= 0. {
62+
play_fire(&*sounds, &storage, audio_output.as_deref());
63+
self.play_fire_timer = DEFAULT_FIRE_TIMER;
64+
}
4265
main_resource.power(time.delta_seconds(), transform.rotation());
4366
} else {
4467
main_resource.apply_gravity(time.delta_seconds());
@@ -88,6 +111,7 @@ impl<'s> System<'s> for ShipSystem {
88111
}
89112

90113
if main_resource.ship_life <= 0 {
114+
play_explosion(&*sounds, &storage, audio_output.as_deref());
91115
main_resource.is_exploding = true;
92116
let mut explosion_transform = Transform::default();
93117
explosion_transform.set_translation_xyz(ship_transform.0, ship_transform.1, 0.9);

src/utils/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod sprites;
22
pub mod level_reader;
3+
pub mod sound;
34

45
#[derive(Debug)]
56
pub struct Point2D {

0 commit comments

Comments
 (0)