game is now independent of hexodsp/cpal
This commit is contained in:
parent
7d28ccfb88
commit
5b22e84952
17 changed files with 79 additions and 200 deletions
39
src/game.rs
39
src/game.rs
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
pub use crate::filters::*;
|
||||
|
||||
use crate::AppState;
|
||||
use crate::{AppState, audio_system};
|
||||
|
||||
use bevy::{
|
||||
ecs::system::EntityCommands,
|
||||
|
|
@ -15,13 +15,6 @@ use bevy_rapier2d::prelude::*;
|
|||
use rapier2d::geometry::CollisionEventFlags;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
pub enum AudioMsg {
|
||||
Color([f32; 3]),
|
||||
Fusion,
|
||||
Jump,
|
||||
Switch,
|
||||
}
|
||||
|
||||
pub struct FirstLevel(pub LevelId);
|
||||
|
||||
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
||||
|
|
@ -156,7 +149,6 @@ pub fn spawn_characters<I: IntoIterator<Item = (Transform, Color)>>(
|
|||
commands: &mut Commands,
|
||||
character_meshes: &Res<CharacterMeshes>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
character_list: &mut ResMut<CharacterList>,
|
||||
|
||||
characters: I,
|
||||
|
|
@ -166,7 +158,6 @@ pub fn spawn_characters<I: IntoIterator<Item = (Transform, Color)>>(
|
|||
commands,
|
||||
character_meshes,
|
||||
materials,
|
||||
audio,
|
||||
character_list,
|
||||
transform,
|
||||
color,
|
||||
|
|
@ -179,7 +170,6 @@ pub fn spawn_character(
|
|||
commands: &mut Commands,
|
||||
character_meshes: &Res<CharacterMeshes>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
character_list: &mut ResMut<CharacterList>,
|
||||
mut transform: Transform,
|
||||
color: Color,
|
||||
|
|
@ -224,9 +214,6 @@ pub fn spawn_character(
|
|||
|
||||
if is_player {
|
||||
entity_commands.insert(Player);
|
||||
audio
|
||||
.send(AudioMsg::Color([color.r(), color.g(), color.b()]))
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -305,8 +292,9 @@ fn char_char_collision_event_system(
|
|||
mut character_list: ResMut<CharacterList>,
|
||||
mut app_state: ResMut<State<AppState>>,
|
||||
character_meshes: Res<CharacterMeshes>,
|
||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
audio_assets: Res<audio_system::AudioAssets>,
|
||||
audio: Res<Audio>,
|
||||
) {
|
||||
for collision_event in collision_events.iter() {
|
||||
if let CollisionEvent::Started(e1, e2, _flags) = collision_event {
|
||||
|
|
@ -333,7 +321,6 @@ fn char_char_collision_event_system(
|
|||
&mut commands,
|
||||
&character_meshes,
|
||||
&mut materials,
|
||||
&audio,
|
||||
&mut character_list,
|
||||
if c1_player.is_some() {
|
||||
*c1_transform
|
||||
|
|
@ -348,7 +335,7 @@ fn char_char_collision_event_system(
|
|||
c1_player.is_some() || c2_player.is_some(),
|
||||
);
|
||||
|
||||
audio.send(AudioMsg::Fusion).ok();
|
||||
audio_system::play_audio(&audio_assets.warp_notes, &audio, new_color.into(), 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -405,7 +392,6 @@ fn collision_event_system(
|
|||
)>,
|
||||
pass_through_filter_query: Query<&PassThroughFilter>,
|
||||
melty_query: Query<&Melty>,
|
||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
) {
|
||||
for collision_event in collision_events.iter() {
|
||||
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
|
||||
|
|
@ -472,8 +458,9 @@ fn change_character_system(
|
|||
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
characters: Query<(Entity, &CharacterColor, Option<&Player>)>,
|
||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
character_list: Res<CharacterList>,
|
||||
audio_assets: Res<audio_system::AudioAssets>,
|
||||
audio: Res<Audio>,
|
||||
) {
|
||||
if !keyboard_input.just_pressed(KeyCode::Tab) {
|
||||
return;
|
||||
|
|
@ -493,10 +480,7 @@ fn change_character_system(
|
|||
{
|
||||
commands.entity(*new_player_entity).insert(Player);
|
||||
if let Ok((_entity, color, _player)) = characters.get(*new_player_entity) {
|
||||
audio
|
||||
.send(AudioMsg::Color([color.0.r(), color.0.g(), color.0.b()]))
|
||||
.ok();
|
||||
audio.send(AudioMsg::Switch).ok();
|
||||
audio_system::play_audio(&audio_assets.reverb_notes, &audio, color.0.into(), 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -504,22 +488,23 @@ fn change_character_system(
|
|||
|
||||
fn player_movement_system(
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut characters: Query<(&mut Velocity, &Children), With<Player>>,
|
||||
mut characters: Query<(&mut Velocity, &Children, &CharacterColor), With<Player>>,
|
||||
mut platform_count_query: Query<&mut PlatformCount>,
|
||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
audio_assets: Res<audio_system::AudioAssets>,
|
||||
audio: Res<Audio>,
|
||||
) {
|
||||
let right_pressed: bool =
|
||||
keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D);
|
||||
let left_pressed: bool =
|
||||
keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
|
||||
|
||||
for (mut velocity, children) in characters.iter_mut() {
|
||||
for (mut velocity, children, color) in characters.iter_mut() {
|
||||
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
||||
|
||||
let mut platform_count: Mut<PlatformCount> =
|
||||
platform_count_query.get_mut(children[0]).unwrap();
|
||||
if keyboard_input.just_pressed(KeyCode::Space) && platform_count.is_landed() {
|
||||
audio.send(AudioMsg::Jump).ok();
|
||||
audio_system::play_audio(&audio_assets.notes, &audio, color.0.into(), 0.5);
|
||||
velocity.linvel.y = 700.;
|
||||
platform_count.reset();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue