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
551 changes: 527 additions & 24 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ bevy = { version = "0.17.2", default-features = false, features = [
"bevy_sprite",
"bevy_sprite_render",
"bevy_text",
"bevy_ui",
"bevy_ui_render",
"bevy_gilrs",
"bevy_window",
"bevy_winit",
"bevy_state",
"bevy_audio",
"default_font",
"multi_threaded",
"png",
"std",
"vorbis",
"wayland",
"webgl2",
"x11",
"zstd_rust",
"wayland"
] }
bevy_embedded_assets = "0.14.0"
leafwing-input-manager = "0.18.0"
Expand All @@ -31,7 +37,7 @@ log = { version = "*", features = [
rand = "0.9.2"

[target.wasm32-unknown-unknown.dependencies]
getrandom = { version = "0.3", features = ["wasm_js"] }
getrandom = { version = "0.3.4", features = ["wasm_js"] }

[features]
# Default to a native dev build.
Expand All @@ -40,18 +46,18 @@ dev = [
"bevy/dynamic_linking",
"bevy/bevy_dev_tools",
"bevy/bevy_ui_debug",
"bevy/bevy_debug_stepping",
"bevy/track_location",
"bevy/trace",
"bevy/bevy_remote",
"bevy/reflect_auto_register",
]
dev_native = [
"dev",
# Enable asset hot reloading for native dev builds.
"bevy/file_watcher",
# Enable embedded asset hot reloading for native dev builds.
"bevy/embedded_watcher",
]


[package.metadata.bevy_cli.release]
# Disable dev features for release builds.
default-features = false
Expand Down
11 changes: 11 additions & 0 deletions assets/credits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
https://opengameart.org/content/through-space
https://opengameart.org/content/space-theme
https://opengameart.org/content/background-space-track - My Very Own Dead Ship
https://opengameart.org/content/space-boss-battle-theme - Orbital Colossus
https://opengameart.org/content/space-bass - Space Bass
https://opengameart.org/content/the-last-parsec
https://opengameart.org/content/lunar-harvest
https://opengameart.org/content/overdrive-sex-machine

https://opengameart.org/content/512-sound-effects-8-bit-style
https://opengameart.org/content/gui-sound-effects
Binary file added assets/font.ttf
Binary file not shown.
Binary file added assets/soundtrack/spacetheme.ogg
Binary file not shown.
Binary file added assets/sprites/fonts.aseprite
Binary file not shown.
Binary file added assets/sprites/fonts.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/jodainteractive.aseprite
Binary file not shown.
Binary file added assets/sprites/jodainteractive.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/newgame.aseprite
Binary file not shown.
Binary file added assets/sprites/newgame.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/quit.aseprite
Binary file not shown.
Binary file added assets/sprites/quit.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/settings.aseprite
Binary file not shown.
Binary file added assets/sprites/settings.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/title.aseprite
Binary file not shown.
Binary file added assets/sprites/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions src/audio/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use bevy::{
audio::{PlaybackMode, Volume},
prelude::*,
};

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

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

pub enum Soundtrack {
MainTheme,
BattleTheme,
}

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

fn setup_audio(mut commands: Commands, asset_server: Res<AssetServer>) {
let main_handle = asset_server.load("soundtrack/spacetheme.ogg");
let soundtracks = Soundtracks {
main_theme: main_handle.clone(),
battle_theme: asset_server.load("audio/soundtrack/battle_theme.ogg"),
};

commands.insert_resource(soundtracks);

commands.spawn((
AudioPlayer(main_handle.clone()),
PlaybackSettings {
mode: PlaybackMode::Loop,
volume: Volume::Linear(0.0),
..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,
}

fn fade_in(
mut commands: Commands,
mut audio_sink: Query<(&FadeIn, &mut AudioSink, Entity)>,
time: Res<Time>,
) {
for (fade_in, mut audio, entity) in audio_sink.iter_mut() {
let current_volume = audio.volume();
audio.set_volume(
current_volume.fade_towards(Volume::Linear(1.0), time.delta_secs() / fade_in.duration),
);
if audio.volume().to_linear() >= 1.0 {
audio.set_volume(Volume::Linear(1.0));
commands.entity(entity).remove::<FadeIn>();
}
}
}
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ 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 sundry;

const RES_WIDTH: u32 = 853;
const RES_HEIGHT: u32 = 480;
Expand Down Expand Up @@ -64,13 +72,18 @@ impl Plugin for AppPlugin {

app.add_plugins(InputPlugin);

app.add_plugins(audio::plugin);

app.add_plugins(screens::plugin);

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

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

app.insert_resource(ClearColor(Color::srgb_u8(9, 10, 20)));
app.add_systems(Startup, spawn_camera);
app.add_systems(PreStartup, spawn_camera);
app.add_systems(Update, fit_canvas.run_if(on_message::<WindowResized>));
}
}
Expand Down Expand Up @@ -118,7 +131,6 @@ fn spawn_camera(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
));

commands.spawn((Sprite::from_image(image_handle), Canvas, HIGH_RES_LAYERS));

commands.spawn((Camera2d, Msaa::Off, OuterCamera, HIGH_RES_LAYERS));
}

Expand Down
40 changes: 31 additions & 9 deletions src/screens/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub enum GameState {

pub(super) fn plugin(app: &mut App) {
app.init_state::<GameState>();
app.add_systems(OnEnter(GameState::Play), spawn_game_screen);
app.add_systems(
OnEnter(GameState::Play),
spawn_game_screen.run_if(in_state(Screen::Game)),
);
app.add_systems(OnEnter(GameState::GameOver), spawn_game_over);
app.add_systems(OnExit(GameState::GameOver), despawn_game_screen);
app.configure_sets(Startup, GameSystems::Play);
Expand All @@ -27,12 +30,23 @@ pub(super) fn plugin(app: &mut App) {
update_projectiles,
projectile_asteroid_collision,
)
.in_set(GameSystems::Play),
.in_set(GameSystems::Play)
.run_if(in_state(Screen::Game)),
);

app.add_systems(Update, (pause).in_set(GameSystems::Play));
app.add_systems(
Update,
(pause)
.in_set(GameSystems::Play)
.run_if(in_state(Screen::Game)),
);

app.add_systems(Update, (game_over_input).in_set(GameSystems::GameOver));
app.add_systems(
Update,
(game_over_input)
.in_set(GameSystems::GameOver)
.run_if(in_state(Screen::Game)),
);

app.add_systems(
FixedUpdate,
Expand All @@ -42,7 +56,8 @@ pub(super) fn plugin(app: &mut App) {
collide_with_asteroid_check,
update_stars,
)
.in_set(GameSystems::Environment),
.in_set(GameSystems::Environment)
.run_if(in_state(Screen::Game)),
);

app.insert_resource(AsteroidSpawnTimer(Timer::from_seconds(
Expand Down Expand Up @@ -99,7 +114,8 @@ fn spawn_default_stars(commands: &mut Commands, asset_server: &Res<AssetServer>)
commands.spawn((
Name::new("Star"),
Star {
speed: random_range(0.5..=2.0),
active: true,
speed: random_range(0.5..=1.0),
},
Sprite {
image: asset_server.load(format!("sprites/stars/star{variant}.png")),
Expand Down Expand Up @@ -151,7 +167,8 @@ struct Player {
struct Projectile;

#[derive(Component)]
struct Star {
pub struct Star {
pub active: bool,
pub speed: f32,
}

Expand Down Expand Up @@ -310,7 +327,7 @@ fn update_stars(mut stars: Query<(&mut Transform, &mut Star)>) {
if transform.translation.y < -240.0 {
transform.translation.y = 240.0 + random_range(0.0..20.0);
transform.translation.x = random_range(-400.0..400.0);
star.speed = random_range(0.5..=1.5);
star.speed = random_range(0.5..=1.0);
}
}
}
Expand Down Expand Up @@ -351,7 +368,12 @@ fn collide_with_asteroid_check(
mut time: ResMut<Time<Virtual>>,
mut state: ResMut<NextState<GameState>>,
) {
let player_transform = player.single().unwrap();
let player = player.single();
if player.is_err() {
return;
}
let player_transform = player.unwrap();

let hitbox_size = 8.0;

for asteroid_transform in asteroids.iter() {
Expand Down
6 changes: 4 additions & 2 deletions src/screens/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use bevy::prelude::*;

mod game;
mod splash;
mod title;

pub(super) fn plugin(app: &mut App) {
app.init_state::<Screen>();

app.add_plugins((title::plugin, game::plugin));
app.add_plugins((splash::plugin, title::plugin, game::plugin));
}

#[derive(States, Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
pub enum Screen {
Title,
#[default]
Splash,
Title,
Game,
}
Loading
Loading