Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bevy = { version = "0.17.2", default-features = false, features = [
"png",
"std",
"vorbis",
"wav",
"wayland",
"webgl2",
"x11",
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you are playing it before the jam entry is submitted, the password is `ldgjam
## Design Notes

### Plot
you are a trainee pilot thrust into the action when you stumble across the roguelike boss during a routine (tutorial) patrol
You are a space explorer searching for a new habitable planet for humanity.

### Areas
classic shmup level
Expand All @@ -35,12 +35,12 @@ cities for shopping and upgrading

### Required Art Assets

- [ ] Title
- [ ] Splash
- [x] Title
- [x] Splash
- [x] Player Ship Sprite
- [ ] Player Projectile Sprite
- [x] Player Projectile Sprite
- [x] Asteroid Sprite
- [ ] Enemy Ship Sprite
- [ ] Enemy Boss Ship Sprite
- [ ] Backgrounds
- [ ] Explosion Sprite/Animation
- [x] Backgrounds
- [x] Explosion Sprite/Animation
Binary file added assets/sfx/explosion.wav
Binary file not shown.
Binary file added assets/sfx/shooting.wav
Binary file not shown.
Binary file added assets/soundtrack/the-last-parsec.ogg
Binary file not shown.
Binary file added assets/soundtrack/through-space.ogg
Binary file not shown.
Binary file added assets/sprites/explosion.aseprite
Binary file not shown.
Binary file added assets/sprites/explosion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/planet-smol.aseprite
Binary file not shown.
Binary file added assets/sprites/planet-smol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/planet.aseprite
Binary file not shown.
Binary file added assets/sprites/planet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ships/ship3-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ships/ship3-fast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ships/ship3-slow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/sprites/ships/ship3.aseprite
Binary file not shown.
Binary file modified assets/sprites/ships/ship3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 108 additions & 45 deletions src/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,131 @@ use bevy::{
};

pub(super) fn plugin(app: &mut App) {
app.add_systems(Startup, setup_audio);
// app.add_observer(on_play_soundtrack_event);
app.init_resource::<Soundtracks>();
app.init_resource::<SfxLibrary>();
app.add_observer(on_play_soundtrack_event);
app.add_observer(on_play_sfx_event);
app.add_systems(Update, fade_in);
}

// #[derive(Resource)]
// pub struct Soundtracks {
// pub main_theme: Handle<AudioSource>,
// pub battle_theme: Handle<AudioSource>,
// }
#[derive(Resource)]
pub struct SfxLibrary {
pub shoot: Handle<AudioSource>,
pub explosion: Handle<AudioSource>,
}

impl FromWorld for SfxLibrary {
fn from_world(world: &mut World) -> Self {
let asset_server = world.resource::<AssetServer>();
let sfx = SfxLibrary {
shoot: asset_server.load("sfx/shooting.wav"),
explosion: asset_server.load("sfx/explosion.wav"),
};
Self {
shoot: sfx.shoot,
explosion: sfx.explosion,
}
}
}

pub enum SoundEffect {
Shoot,
Explosion,
}

#[derive(Event)]
pub struct PlaySfxEvent {
pub sfx: SoundEffect,
}

#[derive(Component)]
struct SoundtrackPlayer;

#[derive(Resource)]
pub struct Soundtracks {
pub main_theme: Handle<AudioSource>,
pub battle_theme: Handle<AudioSource>,
}

// pub enum Soundtrack {
// MainTheme,
// BattleTheme,
// }
impl FromWorld for Soundtracks {
fn from_world(world: &mut World) -> Self {
let asset_server = world.resource::<AssetServer>();
let soundtracks = Soundtracks {
main_theme: asset_server.load("soundtrack/spacetheme.ogg"),
battle_theme: asset_server.load("soundtrack/through-space.ogg"),
};
Self {
main_theme: soundtracks.main_theme,
battle_theme: soundtracks.battle_theme,
}
}
}

// #[derive(Event)]
// pub struct PlaySoundtrackEvent {
// soundtrack: Soundtrack,
// }
pub enum Soundtrack {
MainTheme,
BattleTheme,
}

fn setup_audio(mut commands: Commands, asset_server: Res<AssetServer>) {
let main_handle: Handle<AudioSource> = asset_server.load("soundtrack/spacetheme.ogg");
// let soundtracks = Soundtracks {
// main_theme: main_handle.clone(),
// battle_theme: asset_server.load("audio/soundtrack/battle_theme.ogg"),
// };
#[derive(Event)]
pub struct PlaySoundtrackEvent {
pub soundtrack: Soundtrack,
}

// commands.insert_resource(soundtracks);
fn on_play_soundtrack_event(
soundtrack_event: On<PlaySoundtrackEvent>,
mut commands: Commands,
soundtracks: Res<Soundtracks>,
mut audio_player: Query<
(Entity, &mut AudioPlayer, &mut PlaybackSettings),
With<SoundtrackPlayer>,
>,
) {
let track_handle = match soundtrack_event.soundtrack {
Soundtrack::MainTheme => soundtracks.main_theme.clone(),
Soundtrack::BattleTheme => soundtracks.battle_theme.clone(),
};

let Ok((entity, mut audio, mut playback)) = audio_player.single_mut() else {
commands.spawn((
SoundtrackPlayer,
AudioPlayer(track_handle.clone()),
PlaybackSettings {
mode: PlaybackMode::Loop,
volume: Volume::Linear(0.0),
..default()
},
FadeIn { duration: 4.0 },
Transform::default(),
GlobalTransform::default(),
));
return;
};

if audio.0 != track_handle {
audio.0 = track_handle.clone();
playback.volume = Volume::Linear(0.0);
commands.entity(entity).insert(FadeIn { duration: 4.0 });
}
}

fn on_play_sfx_event(sfx_event: On<PlaySfxEvent>, mut commands: Commands, sfx: Res<SfxLibrary>) {
let sfx_handle = match sfx_event.sfx {
SoundEffect::Shoot => sfx.shoot.clone(),
SoundEffect::Explosion => sfx.explosion.clone(),
};

commands.spawn((
AudioPlayer(main_handle.clone()),
AudioPlayer(sfx_handle),
PlaybackSettings {
mode: PlaybackMode::Loop,
volume: Volume::Linear(0.0),
mode: PlaybackMode::Remove,
volume: Volume::Linear(0.1),
..default()
},
FadeIn { duration: 4.0 },
Transform::default(),
GlobalTransform::default(),
));
}

// fn on_play_soundtrack_event(
// soundtrack_event: On<PlaySoundtrackEvent>,
// soundtracks: Res<Soundtracks>,
// ) {
// let track_handle = match soundtrack_event.soundtrack {
// Soundtrack::MainTheme => soundtracks.main_theme.clone(),
// Soundtrack::BattleTheme => soundtracks.battle_theme.clone(),
// };

// commands.spawn((
// AudioPlayer(track_handle),
// PlaybackSettings {
// mode: PlaybackMode::Loop,
// volume: Volume::Linear(1.0),
// ..default()
// },
// ));
// }

#[derive(Component)]
struct FadeIn {
duration: f32,
Expand Down
12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ use bevy::{
window::{WindowMode, WindowResized, WindowResolution},
};

// #[cfg(feature = "dev")]
// use bevy::remote::RemotePlugin;
// #[cfg(feature = "dev")]
// use bevy::remote::http::RemoteHttpPlugin;

use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode};

use crate::input::InputPlugin;

mod audio;
mod input;
mod screens;
mod stars;
mod sundry;

const RES_WIDTH: u32 = 853;
Expand Down Expand Up @@ -59,7 +55,10 @@ impl Plugin for AppPlugin {
primary_window: Some(Window {
title: "Star Journey".to_string(),
fit_canvas_to_parent: true,
#[cfg(not(debug_assertions))]
mode: WindowMode::BorderlessFullscreen(MonitorSelection::Current),
#[cfg(debug_assertions)]
mode: WindowMode::Windowed,
resolution: WindowResolution::new(1920, 1080),
resizable: false,
position: WindowPosition::Centered(MonitorSelection::Current),
Expand All @@ -76,8 +75,7 @@ impl Plugin for AppPlugin {

app.add_plugins(screens::plugin);

// #[cfg(feature = "dev")]
// app.add_plugins((RemotePlugin::default(), RemoteHttpPlugin::default()));
app.add_plugins(stars::plugin);

app.init_state::<Pause>();
app.configure_sets(Update, PausableSystems.run_if(in_state(Pause(false))));
Expand Down
Loading