Compare commits
7 commits
22147c818a
...
b42a032cfd
Author | SHA1 | Date | |
---|---|---|---|
b42a032cfd | |||
ec7d04c8c8 | |||
297811e882 | |||
12e58b3fc0 | |||
be96747d6a | |||
3f79054ed7 | |||
e86ca82bc3 |
9 changed files with 272 additions and 227 deletions
|
@ -44,7 +44,7 @@ The synthetizer matrix can be edited using [HexoSynth](https://github.com/WeirdC
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
GNU AGPL v3, CopyLeft 2022 Pascal Engélibert
|
GNU AGPL v3, CopyLeft 2022 Pascal Engélibert, Nixon Cheng
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||||
|
|
File diff suppressed because one or more lines are too long
16
src/audio.rs
16
src/audio.rs
|
@ -33,9 +33,18 @@ pub fn setup(event_channel: Receiver<AudioMsg>) {
|
||||||
let color_mix_b_gain = color_mix.inp_param("gain3").unwrap();
|
let color_mix_b_gain = color_mix.inp_param("gain3").unwrap();
|
||||||
let jump_ad = NodeId::Ad(0);
|
let jump_ad = NodeId::Ad(0);
|
||||||
let jump_ad_trig = jump_ad.inp_param("trig").unwrap();
|
let jump_ad_trig = jump_ad.inp_param("trig").unwrap();
|
||||||
|
let switch_ad = NodeId::Ad(1);
|
||||||
|
let switch_ad_trig = switch_ad.inp_param("trig").unwrap();
|
||||||
|
let fusion_ad = NodeId::Ad(2);
|
||||||
|
let fusion_ad_trig = fusion_ad.inp_param("trig").unwrap();
|
||||||
|
let fusion_ad2 = NodeId::Ad(3);
|
||||||
|
let fusion_ad2_trig = fusion_ad2.inp_param("trig").unwrap();
|
||||||
|
|
||||||
for (_tick, _now) in Clock::framerate(10.0).iter() {
|
for (_tick, _now) in Clock::framerate(20.0).iter() {
|
||||||
matrix.set_param(jump_ad_trig, (0.0).into());
|
matrix.set_param(jump_ad_trig, (0.0).into());
|
||||||
|
matrix.set_param(switch_ad_trig, (0.0).into());
|
||||||
|
matrix.set_param(fusion_ad_trig, (0.0).into());
|
||||||
|
matrix.set_param(fusion_ad2_trig, (0.0).into());
|
||||||
|
|
||||||
if let Ok(msg) = event_channel.try_recv() {
|
if let Ok(msg) = event_channel.try_recv() {
|
||||||
match msg {
|
match msg {
|
||||||
|
@ -44,7 +53,12 @@ pub fn setup(event_channel: Receiver<AudioMsg>) {
|
||||||
matrix.set_param(color_mix_g_gain, g.into());
|
matrix.set_param(color_mix_g_gain, g.into());
|
||||||
matrix.set_param(color_mix_b_gain, b.into());
|
matrix.set_param(color_mix_b_gain, b.into());
|
||||||
}
|
}
|
||||||
|
AudioMsg::Fusion => {
|
||||||
|
matrix.set_param(fusion_ad_trig, (1.0).into());
|
||||||
|
matrix.set_param(fusion_ad2_trig, (1.0).into());
|
||||||
|
}
|
||||||
AudioMsg::Jump => matrix.set_param(jump_ad_trig, (1.0).into()),
|
AudioMsg::Jump => matrix.set_param(jump_ad_trig, (1.0).into()),
|
||||||
|
AudioMsg::Switch => matrix.set_param(switch_ad_trig, (1.0).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
20
src/filters.rs
Normal file
20
src/filters.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component, Default)]
|
||||||
|
pub struct FilterColor(pub Color);
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub enum PassThroughFilter {
|
||||||
|
Absorbing,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Bundle)]
|
||||||
|
pub struct AbsorbingFilter {
|
||||||
|
pub color: FilterColor,
|
||||||
|
#[bundle]
|
||||||
|
pub mesh: ColorMesh2dBundle,
|
||||||
|
pub collider: Collider,
|
||||||
|
pub sensor: Sensor,
|
||||||
|
pub filter_type: PassThroughFilter,
|
||||||
|
}
|
206
src/game.rs
206
src/game.rs
|
@ -1,19 +1,23 @@
|
||||||
#![allow(clippy::precedence)]
|
#![allow(clippy::precedence)]
|
||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
|
pub use crate::filters::*;
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
ecs::system::EntityCommands,
|
||||||
input::{keyboard::KeyCode, Input},
|
input::{keyboard::KeyCode, Input},
|
||||||
prelude::{shape::Quad, *},
|
prelude::{shape::Quad, *},
|
||||||
sprite::Mesh2dHandle,
|
sprite::Mesh2dHandle,
|
||||||
};
|
};
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
use std::collections::BTreeSet;
|
|
||||||
|
|
||||||
pub enum AudioMsg {
|
pub enum AudioMsg {
|
||||||
Color([f32; 3]),
|
Color([f32; 3]),
|
||||||
|
Fusion,
|
||||||
Jump,
|
Jump,
|
||||||
|
Switch,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
||||||
|
@ -34,13 +38,14 @@ impl Plugin for GamePlugin {
|
||||||
.add_system_set(
|
.add_system_set(
|
||||||
SystemSet::on_update(AppState::Game)
|
SystemSet::on_update(AppState::Game)
|
||||||
.with_system(crate::levels::post_setup_level)
|
.with_system(crate::levels::post_setup_level)
|
||||||
.with_system(keyboard_input_system)
|
.with_system(change_character_system)
|
||||||
|
.with_system(player_movement_system)
|
||||||
.with_system(move_camera)
|
.with_system(move_camera)
|
||||||
.with_system(character_particle_effect_system),
|
.with_system(character_particle_effect_system),
|
||||||
)
|
)
|
||||||
.add_system_set(
|
.add_system_set(
|
||||||
SystemSet::on_update(AppState::Win)
|
SystemSet::on_update(AppState::Win)
|
||||||
.with_system(keyboard_input_system)
|
.with_system(player_movement_system)
|
||||||
.with_system(move_camera)
|
.with_system(move_camera)
|
||||||
.with_system(character_particle_effect_system),
|
.with_system(character_particle_effect_system),
|
||||||
)
|
)
|
||||||
|
@ -79,18 +84,12 @@ impl FromWorld for CharacterMeshes {
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Level;
|
pub struct Level;
|
||||||
|
|
||||||
#[derive(Clone, Component, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
||||||
pub struct CharacterId(pub u32);
|
|
||||||
|
|
||||||
#[derive(Clone, Component, Copy, Eq, Hash, PartialEq)]
|
|
||||||
pub struct SelectedCharacterId(pub Option<CharacterId>);
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct CharacterIdList(pub BTreeSet<CharacterId>);
|
|
||||||
|
|
||||||
#[derive(Clone, Component, PartialEq)]
|
#[derive(Clone, Component, PartialEq)]
|
||||||
pub struct CharacterColor(pub Color);
|
pub struct CharacterColor(pub Color);
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Player;
|
||||||
|
|
||||||
// Systems
|
// Systems
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
|
@ -109,36 +108,49 @@ fn setup(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>>,
|
||||||
|
|
||||||
|
characters: I,
|
||||||
|
) {
|
||||||
|
for (i, (transform, color)) in characters.into_iter().enumerate() {
|
||||||
|
spawn_character(
|
||||||
|
commands,
|
||||||
|
character_meshes,
|
||||||
|
materials,
|
||||||
|
audio,
|
||||||
|
transform,
|
||||||
|
color,
|
||||||
|
i == 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn spawn_character(
|
pub fn spawn_character(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
character_meshes: &Res<CharacterMeshes>,
|
character_meshes: &Res<CharacterMeshes>,
|
||||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||||
selected_character_id: &mut Mut<SelectedCharacterId>,
|
|
||||||
character_id_list: &mut Mut<CharacterIdList>,
|
|
||||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
mut transform: Transform,
|
mut transform: Transform,
|
||||||
color: Color,
|
color: Color,
|
||||||
|
is_player: bool,
|
||||||
) {
|
) {
|
||||||
transform.translation.z = transform.translation.z.max(1.0);
|
transform.translation.z = transform.translation.z.max(1.0);
|
||||||
|
|
||||||
let character_id = CharacterId(
|
let color_mesh_2d_bundle: ColorMesh2dBundle = ColorMesh2dBundle {
|
||||||
character_id_list
|
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.last()
|
|
||||||
.map_or(0, |last_character_id| last_character_id.0 + 1),
|
|
||||||
);
|
|
||||||
character_id_list.0.insert(character_id);
|
|
||||||
|
|
||||||
commands
|
|
||||||
.spawn_bundle(ColorMesh2dBundle {
|
|
||||||
mesh: character_meshes.square.clone(),
|
mesh: character_meshes.square.clone(),
|
||||||
material: materials.add(ColorMaterial::from(color)),
|
material: materials.add(ColorMaterial::from(color)),
|
||||||
transform,
|
transform,
|
||||||
..default()
|
..default()
|
||||||
})
|
};
|
||||||
|
|
||||||
|
let mut entity_commands: EntityCommands = commands.spawn_bundle(color_mesh_2d_bundle);
|
||||||
|
|
||||||
|
entity_commands
|
||||||
.insert(Level)
|
.insert(Level)
|
||||||
.insert(character_id)
|
|
||||||
.insert(CharacterColor(color))
|
.insert(CharacterColor(color))
|
||||||
.insert(RigidBody::Dynamic)
|
.insert(RigidBody::Dynamic)
|
||||||
.insert(Collider::cuboid(32., 32.))
|
.insert(Collider::cuboid(32., 32.))
|
||||||
|
@ -154,9 +166,8 @@ pub fn spawn_character(
|
||||||
.insert(ExternalImpulse::default())
|
.insert(ExternalImpulse::default())
|
||||||
.insert(ActiveEvents::COLLISION_EVENTS);
|
.insert(ActiveEvents::COLLISION_EVENTS);
|
||||||
|
|
||||||
// If no character is selected, then select this one
|
if is_player {
|
||||||
if selected_character_id.0.is_none() {
|
entity_commands.insert(Player);
|
||||||
selected_character_id.0 = Some(character_id);
|
|
||||||
audio
|
audio
|
||||||
.send(AudioMsg::Color([color.r(), color.g(), color.b()]))
|
.send(AudioMsg::Color([color.r(), color.g(), color.b()]))
|
||||||
.ok();
|
.ok();
|
||||||
|
@ -168,24 +179,18 @@ fn collision_event_system(
|
||||||
character_meshes: Res<CharacterMeshes>,
|
character_meshes: Res<CharacterMeshes>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
mut collision_events: EventReader<CollisionEvent>,
|
mut collision_events: EventReader<CollisionEvent>,
|
||||||
character_query: Query<(&CharacterId, &CharacterColor, &Transform)>,
|
character_query: Query<(&CharacterColor, &Transform, Option<&Player>)>,
|
||||||
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
|
||||||
mut app_state: ResMut<State<AppState>>,
|
mut app_state: ResMut<State<AppState>>,
|
||||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
) {
|
) {
|
||||||
for collision_event in collision_events.iter() {
|
for collision_event in collision_events.iter() {
|
||||||
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
|
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
|
||||||
if flags.is_empty() {
|
if flags.is_empty() {
|
||||||
if let (Ok((c1_id, c1_color, c1_transform)), Ok((c2_id, c2_color, _c2_transform))) =
|
if let (
|
||||||
(character_query.get(*e1), character_query.get(*e2))
|
Ok((c1_color, c1_transform, c1_player)),
|
||||||
|
Ok((c2_color, c2_transform, c2_player)),
|
||||||
|
) = (character_query.get(*e1), character_query.get(*e2))
|
||||||
{
|
{
|
||||||
let (mut selected_character_id, mut character_id_list) =
|
|
||||||
level_query.single_mut();
|
|
||||||
character_id_list.0.remove(c1_id);
|
|
||||||
character_id_list.0.remove(c2_id);
|
|
||||||
selected_character_id.0 = None;
|
|
||||||
|
|
||||||
// TODO completely remove particles
|
|
||||||
commands.entity(*e1).despawn_recursive();
|
commands.entity(*e1).despawn_recursive();
|
||||||
commands.entity(*e2).despawn_recursive();
|
commands.entity(*e2).despawn_recursive();
|
||||||
|
|
||||||
|
@ -199,63 +204,88 @@ fn collision_event_system(
|
||||||
app_state.replace(AppState::Win).ok();
|
app_state.replace(AppState::Win).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// position character based on current player location
|
||||||
spawn_character(
|
spawn_character(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&character_meshes,
|
&character_meshes,
|
||||||
&mut materials,
|
&mut materials,
|
||||||
&mut selected_character_id,
|
|
||||||
&mut character_id_list,
|
|
||||||
&audio,
|
&audio,
|
||||||
*c1_transform,
|
if c1_player.is_some() {
|
||||||
|
*c1_transform
|
||||||
|
} else if c2_player.is_some() {
|
||||||
|
*c2_transform
|
||||||
|
} else {
|
||||||
|
Transform::identity().with_translation(
|
||||||
|
(c1_transform.translation + c2_transform.translation) / 2.,
|
||||||
|
)
|
||||||
|
},
|
||||||
new_color.into(),
|
new_color.into(),
|
||||||
|
c1_player.is_some() || c2_player.is_some(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
audio.send(AudioMsg::Fusion).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_input_system(
|
fn change_character_system(
|
||||||
|
mut commands: Commands,
|
||||||
|
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
mut characters: Query<(&CharacterId, &mut Velocity, &CharacterColor)>,
|
characters: Query<(Entity, &CharacterColor, Option<&Player>)>,
|
||||||
mut level_query: Query<(&mut SelectedCharacterId, &CharacterIdList)>,
|
|
||||||
mut app_state: ResMut<State<AppState>>,
|
|
||||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
) {
|
) {
|
||||||
if let Ok((mut selected_character_id, character_id_list)) = level_query.get_single_mut() {
|
if !keyboard_input.just_pressed(KeyCode::Tab) {
|
||||||
if keyboard_input.just_pressed(KeyCode::Tab) {
|
return;
|
||||||
let selected = if let Some(selected_character_id) = &mut selected_character_id.0 {
|
}
|
||||||
*selected_character_id = *character_id_list
|
|
||||||
.0
|
|
||||||
.range(*selected_character_id..)
|
|
||||||
.nth(1)
|
|
||||||
.unwrap_or_else(|| character_id_list.0.iter().next().unwrap());
|
|
||||||
*selected_character_id
|
|
||||||
} else {
|
|
||||||
selected_character_id.0 = Some(CharacterId(0));
|
|
||||||
CharacterId(0)
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some((_character_id, _velocity, color)) = characters
|
let mut player_idx: usize = 0;
|
||||||
.iter_mut()
|
let mut player_count: usize = 0;
|
||||||
.find(|(character_id, _velocity, _color)| **character_id == selected)
|
|
||||||
{
|
// find player idx
|
||||||
|
for (_entity, _color, player) in characters.iter() {
|
||||||
|
if player.is_some() {
|
||||||
|
player_idx = player_count;
|
||||||
|
}
|
||||||
|
player_count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate next player index
|
||||||
|
let next_player_idx = (player_idx + 1) % player_count;
|
||||||
|
player_count = 0;
|
||||||
|
|
||||||
|
// exchange `Player` component from old `player_idx` to new `next_player_idx`
|
||||||
|
for (entity, color, _player) in characters.iter() {
|
||||||
|
if player_count == player_idx {
|
||||||
|
commands.entity(entity).remove::<Player>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if player_count == next_player_idx {
|
||||||
|
commands.entity(entity).insert(Player);
|
||||||
audio
|
audio
|
||||||
.send(AudioMsg::Color([color.0.r(), color.0.g(), color.0.b()]))
|
.send(AudioMsg::Color([color.0.r(), color.0.g(), color.0.b()]))
|
||||||
.ok();
|
.ok();
|
||||||
|
audio.send(AudioMsg::Switch).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
player_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn player_movement_system(
|
||||||
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
|
mut characters: Query<&mut Velocity, With<Player>>,
|
||||||
|
mut app_state: ResMut<State<AppState>>,
|
||||||
|
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
|
) {
|
||||||
let right_pressed: bool =
|
let right_pressed: bool =
|
||||||
keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D);
|
keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D);
|
||||||
let left_pressed: bool =
|
let left_pressed: bool =
|
||||||
keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
|
keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
|
||||||
|
|
||||||
if let Some(selected_character_id) = &selected_character_id.0 {
|
for mut velocity in characters.iter_mut() {
|
||||||
if let Some((_character_id, mut velocity, _color)) = characters
|
|
||||||
.iter_mut()
|
|
||||||
.find(|(character_id, _velocity, _color)| *character_id == selected_character_id)
|
|
||||||
{
|
|
||||||
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
||||||
|
|
||||||
if keyboard_input.just_pressed(KeyCode::Space) {
|
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||||
|
@ -263,8 +293,6 @@ fn keyboard_input_system(
|
||||||
velocity.linvel.y = 500.;
|
velocity.linvel.y = 500.;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if app_state.current() == &AppState::Win && keyboard_input.just_pressed(KeyCode::Return) {
|
if app_state.current() == &AppState::Win && keyboard_input.just_pressed(KeyCode::Return) {
|
||||||
app_state.replace(AppState::Game).unwrap();
|
app_state.replace(AppState::Game).unwrap();
|
||||||
|
@ -272,22 +300,14 @@ fn keyboard_input_system(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn character_particle_effect_system(
|
fn character_particle_effect_system(
|
||||||
mut characters: Query<(&CharacterId, &Transform, &CharacterColor)>,
|
characters: Query<(&Transform, &CharacterColor), With<Player>>,
|
||||||
mut particle_effect: ResMut<crate::particle_effect::ParticleEffectResource>,
|
mut particle_effect: ResMut<crate::particle_effect::ParticleEffectResource>,
|
||||||
mut level_query: Query<&SelectedCharacterId>,
|
|
||||||
) {
|
) {
|
||||||
if let Ok(selected_character_id) = level_query.get_single_mut() {
|
for (transform, color) in characters.iter() {
|
||||||
if let Some(selected_character_id) = &selected_character_id.0 {
|
|
||||||
if let Some((_character_id, transform, color)) = characters
|
|
||||||
.iter_mut()
|
|
||||||
.find(|(character_id, _transform, _color)| *character_id == selected_character_id)
|
|
||||||
{
|
|
||||||
particle_effect.translation = transform.translation;
|
particle_effect.translation = transform.translation;
|
||||||
particle_effect.color = color.0;
|
particle_effect.color = color.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
||||||
|
@ -309,29 +329,25 @@ fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
|
||||||
fn move_camera(
|
fn move_camera(
|
||||||
mut camera_query: Query<(&Camera, &mut Transform)>,
|
mut camera_query: Query<(&Camera, &mut Transform)>,
|
||||||
characters: Query<(&CharacterId, &Transform), Without<Camera>>,
|
characters: Query<&Transform, (Without<Camera>, With<Player>)>,
|
||||||
level_query: Query<&SelectedCharacterId>,
|
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
const MARGIN: f32 = 300.0;
|
const MARGIN: f32 = 300.0;
|
||||||
const FOLLOW_SPEED: f32 = std::f32::consts::PI;
|
const FOLLOW_SPEED: f32 = std::f32::consts::PI;
|
||||||
|
|
||||||
if let Ok(selected_character_id) = level_query.get_single() {
|
for character_transform in characters.iter() {
|
||||||
if let Some(selected_character_id) = &selected_character_id.0 {
|
let (camera, mut camera_transform) = camera_query.single_mut();
|
||||||
if let Some((_character_id, transform)) = characters
|
|
||||||
.iter()
|
|
||||||
.find(|(character_id, _transform)| *character_id == selected_character_id)
|
|
||||||
{
|
|
||||||
let (camera, mut camera_transform) =
|
|
||||||
camera_query.single_mut();
|
|
||||||
|
|
||||||
let size: Vec2 = camera.logical_viewport_size().unwrap();
|
let size: Vec2 = camera.logical_viewport_size().unwrap();
|
||||||
let half_height: f32 = size.y * 0.5;
|
let half_height: f32 = size.y * 0.5;
|
||||||
camera_transform.translation = camera_transform.translation.lerp(transform.translation, time.delta_seconds() * FOLLOW_SPEED);
|
camera_transform.translation = camera_transform.translation.lerp(
|
||||||
|
character_transform.translation,
|
||||||
|
time.delta_seconds() * FOLLOW_SPEED,
|
||||||
|
);
|
||||||
|
|
||||||
// prevent camera from going too low
|
// prevent camera from going too low
|
||||||
camera_transform.translation.y = camera_transform.translation.y.max(half_height - MARGIN);
|
camera_transform.translation.y = camera_transform.translation.y.max(half_height - MARGIN);
|
||||||
|
// always make sure that camera is away from the object in order to render them
|
||||||
camera_transform.translation.z = 999.0;
|
camera_transform.translation.z = 999.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ mod level1;
|
||||||
use crate::game::*;
|
use crate::game::*;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use std::collections::BTreeSet;
|
|
||||||
|
|
||||||
pub fn setup_level(
|
pub fn setup_level(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
|
@ -16,12 +15,7 @@ pub fn setup_level(
|
||||||
camera_query: &mut Query<&mut Transform, With<Camera>>,
|
camera_query: &mut Query<&mut Transform, With<Camera>>,
|
||||||
level_id: LevelId,
|
level_id: LevelId,
|
||||||
) {
|
) {
|
||||||
let level_entity = commands
|
let level_entity = commands.spawn().insert(Level).id();
|
||||||
.spawn()
|
|
||||||
.insert(Level)
|
|
||||||
.insert(SelectedCharacterId(None))
|
|
||||||
.insert(CharacterIdList(BTreeSet::new()))
|
|
||||||
.id();
|
|
||||||
current_level.0 = Some(level_id);
|
current_level.0 = Some(level_id);
|
||||||
|
|
||||||
camera_query.single_mut().translation = Default::default();
|
camera_query.single_mut().translation = Default::default();
|
||||||
|
@ -39,33 +33,28 @@ pub fn despawn_level(mut commands: Commands, level_query: Query<Entity, With<Lev
|
||||||
pub fn post_setup_level(
|
pub fn post_setup_level(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
character_meshes: Res<CharacterMeshes>,
|
character_meshes: Res<CharacterMeshes>,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
current_level: Res<CurrentLevel>,
|
current_level: Res<CurrentLevel>,
|
||||||
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
|
||||||
mut level_startup_event: EventReader<LevelStartupEvent>,
|
mut level_startup_event: EventReader<LevelStartupEvent>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
) {
|
) {
|
||||||
for LevelStartupEvent(level_entity) in level_startup_event.iter() {
|
for LevelStartupEvent(_level_entity) in level_startup_event.iter() {
|
||||||
if let Ok((mut selected_character_id, mut character_id_list)) =
|
|
||||||
level_query.get_mut(*level_entity)
|
|
||||||
{
|
|
||||||
if let Some(level_id) = current_level.0 {
|
if let Some(level_id) = current_level.0 {
|
||||||
match level_id.0 {
|
match level_id.0 {
|
||||||
0 => level0::setup(
|
0 => level0::setup(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
|
&mut meshes,
|
||||||
&character_meshes,
|
&character_meshes,
|
||||||
&mut materials,
|
&mut materials,
|
||||||
&mut selected_character_id,
|
|
||||||
&mut character_id_list,
|
|
||||||
&audio,
|
&audio,
|
||||||
),
|
),
|
||||||
1 => level1::setup(
|
1 => level1::setup(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
|
&mut meshes,
|
||||||
&character_meshes,
|
&character_meshes,
|
||||||
&mut materials,
|
&mut materials,
|
||||||
&mut selected_character_id,
|
|
||||||
&mut character_id_list,
|
|
||||||
&audio,
|
&audio,
|
||||||
),
|
),
|
||||||
_ => game_over::setup(&mut commands, &asset_server),
|
_ => game_over::setup(&mut commands, &asset_server),
|
||||||
|
@ -73,4 +62,3 @@ pub fn post_setup_level(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,49 +1,39 @@
|
||||||
use crate::game::*;
|
use crate::game::*;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::{shape::Quad, *};
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
pub fn setup(
|
pub fn setup(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
|
meshes: &mut ResMut<Assets<Mesh>>,
|
||||||
character_meshes: &Res<CharacterMeshes>,
|
character_meshes: &Res<CharacterMeshes>,
|
||||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||||
selected_character_id: &mut Mut<SelectedCharacterId>,
|
|
||||||
character_id_list: &mut Mut<CharacterIdList>,
|
|
||||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(TransformBundle::from(Transform::from_xyz(0.0, -256.0, 0.0)))
|
.spawn_bundle(ColorMesh2dBundle {
|
||||||
.insert(Collider::cuboid(400., 10.))
|
mesh: meshes
|
||||||
|
.add(Mesh::from(Quad {
|
||||||
|
size: Vec2 { x: 800.0, y: 16.0 },
|
||||||
|
flip: false,
|
||||||
|
}))
|
||||||
|
.into(),
|
||||||
|
material: materials.add(ColorMaterial::from(Color::GRAY)),
|
||||||
|
transform: Transform::from_xyz(0.0, -256.0, 0.0),
|
||||||
|
..default()
|
||||||
|
})
|
||||||
|
.insert(Collider::cuboid(400., 8.))
|
||||||
.insert(Level);
|
.insert(Level);
|
||||||
|
|
||||||
spawn_character(
|
spawn_characters(
|
||||||
commands,
|
commands,
|
||||||
character_meshes,
|
character_meshes,
|
||||||
materials,
|
materials,
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
audio,
|
audio,
|
||||||
Transform::from_xyz(-128., -64., 0.),
|
[
|
||||||
Color::RED,
|
(Transform::from_xyz(-128., -64., 0.), Color::RED),
|
||||||
);
|
(Transform::from_xyz(0., -64., 0.), Color::GREEN),
|
||||||
spawn_character(
|
(Transform::from_xyz(128., -64., 0.), Color::BLUE),
|
||||||
commands,
|
],
|
||||||
character_meshes,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
audio,
|
|
||||||
Transform::from_xyz(0., -64., 0.),
|
|
||||||
Color::GREEN,
|
|
||||||
);
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
audio,
|
|
||||||
Transform::from_xyz(128., -64., 0.),
|
|
||||||
Color::BLUE,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +1,73 @@
|
||||||
use crate::game::*;
|
use crate::game::*;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::{shape::Quad, *};
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
pub fn setup(
|
pub fn setup(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
|
meshes: &mut ResMut<Assets<Mesh>>,
|
||||||
character_meshes: &Res<CharacterMeshes>,
|
character_meshes: &Res<CharacterMeshes>,
|
||||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||||
selected_character_id: &mut Mut<SelectedCharacterId>,
|
|
||||||
character_id_list: &mut Mut<CharacterIdList>,
|
|
||||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(TransformBundle::from(Transform::from_xyz(0.0, -256.0, 0.0)))
|
.spawn_bundle(ColorMesh2dBundle {
|
||||||
.insert(Collider::cuboid(400., 10.))
|
mesh: meshes
|
||||||
|
.add(Mesh::from(Quad {
|
||||||
|
size: Vec2 { x: 800.0, y: 16.0 },
|
||||||
|
flip: false,
|
||||||
|
}))
|
||||||
|
.into(),
|
||||||
|
material: materials.add(ColorMaterial::from(Color::GRAY)),
|
||||||
|
transform: Transform::from_xyz(0.0, -256.0, 0.0),
|
||||||
|
..default()
|
||||||
|
})
|
||||||
|
.insert(Collider::cuboid(400., 8.))
|
||||||
.insert(Level);
|
.insert(Level);
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(TransformBundle::from(Transform::from_xyz(
|
.spawn_bundle(ColorMesh2dBundle {
|
||||||
256.0, -128.0, 0.0,
|
mesh: meshes
|
||||||
)))
|
.add(Mesh::from(Quad {
|
||||||
.insert(Collider::cuboid(200., 10.))
|
size: Vec2 { x: 400.0, y: 16.0 },
|
||||||
|
flip: false,
|
||||||
|
}))
|
||||||
|
.into(),
|
||||||
|
material: materials.add(ColorMaterial::from(Color::GRAY)),
|
||||||
|
transform: Transform::from_xyz(256.0, -128.0, 0.0),
|
||||||
|
..default()
|
||||||
|
})
|
||||||
|
.insert(Collider::cuboid(200., 8.))
|
||||||
.insert(Level);
|
.insert(Level);
|
||||||
|
|
||||||
spawn_character(
|
spawn_characters(
|
||||||
commands,
|
commands,
|
||||||
character_meshes,
|
character_meshes,
|
||||||
materials,
|
materials,
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
audio,
|
audio,
|
||||||
Transform::from_xyz(128., 64., 0.),
|
[
|
||||||
Color::BLUE,
|
(Transform::from_xyz(128., 64., 0.), Color::BLUE),
|
||||||
);
|
(Transform::from_xyz(-128., -128., 0.), Color::RED),
|
||||||
spawn_character(
|
(Transform::from_xyz(0., -128., 0.), Color::GREEN),
|
||||||
commands,
|
],
|
||||||
character_meshes,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
audio,
|
|
||||||
Transform::from_xyz(-128., -128., 0.),
|
|
||||||
Color::RED,
|
|
||||||
);
|
|
||||||
spawn_character(
|
|
||||||
commands,
|
|
||||||
character_meshes,
|
|
||||||
materials,
|
|
||||||
selected_character_id,
|
|
||||||
character_id_list,
|
|
||||||
audio,
|
|
||||||
Transform::from_xyz(0., -128., 0.),
|
|
||||||
Color::GREEN,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
commands
|
||||||
|
.spawn_bundle(AbsorbingFilter {
|
||||||
|
color: FilterColor(Color::RED),
|
||||||
|
mesh: ColorMesh2dBundle {
|
||||||
|
mesh: meshes
|
||||||
|
.add(Mesh::from(Quad {
|
||||||
|
size: Vec2 { x: 128.0, y: 16.0 },
|
||||||
|
flip: false,
|
||||||
|
}))
|
||||||
|
.into(),
|
||||||
|
material: materials.add(Color::rgba(1., 0., 0., 0.5).into()),
|
||||||
|
transform: Transform::from_xyz(0., 0., 2.),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
collider: Collider::cuboid(64., 8.),
|
||||||
|
sensor: Sensor,
|
||||||
|
filter_type: PassThroughFilter::Absorbing,
|
||||||
|
})
|
||||||
|
.insert(Level);
|
||||||
}
|
}
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,11 +1,12 @@
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod audio;
|
mod audio;
|
||||||
|
mod filters;
|
||||||
mod game;
|
mod game;
|
||||||
mod levels;
|
mod levels;
|
||||||
mod menu;
|
mod menu;
|
||||||
mod particle_effect;
|
mod particle_effect;
|
||||||
|
|
||||||
use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*};
|
use bevy::prelude::*;
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
@ -23,15 +24,18 @@ fn main() {
|
||||||
std::thread::spawn(move || audio::setup(audio_event_receiver));
|
std::thread::spawn(move || audio::setup(audio_event_receiver));
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
|
.insert_resource(Msaa { samples: 4 })
|
||||||
.insert_resource(audio_event_sender)
|
.insert_resource(audio_event_sender)
|
||||||
.add_state(AppState::Menu)
|
.add_state(AppState::Menu)
|
||||||
|
.insert_resource(ClearColor(Color::BLACK))
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(64.0))
|
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(64.0))
|
||||||
.add_plugin(RapierDebugRenderPlugin::default())
|
//.add_plugin(RapierDebugRenderPlugin::default())
|
||||||
.add_plugin(menu::MenuPlugin)
|
.add_plugin(menu::MenuPlugin)
|
||||||
.add_plugin(game::GamePlugin)
|
.add_plugin(game::GamePlugin)
|
||||||
.add_plugin(particle_effect::ParticleEffectPlugin)
|
.add_plugin(particle_effect::ParticleEffectPlugin)
|
||||||
.add_plugin(bevy_inspector_egui::WorldInspectorPlugin::new())
|
//.add_plugin(bevy_inspector_egui::WorldInspectorPlugin::new())
|
||||||
|
.add_system(bevy::window::close_on_esc)
|
||||||
.add_startup_system(setup)
|
.add_startup_system(setup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -43,12 +47,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
|
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
|
||||||
commands.insert_resource(font);
|
commands.insert_resource(font);
|
||||||
|
|
||||||
commands.spawn_bundle(Camera2dBundle {
|
commands.spawn_bundle(Camera2dBundle::default());
|
||||||
camera_2d: Camera2d {
|
|
||||||
clear_color: ClearColorConfig::Custom(Color::BLACK),
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
commands.insert_resource(AmbientLight {
|
commands.insert_resource(AmbientLight {
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
brightness: 0.6,
|
brightness: 0.6,
|
||||||
|
|
Loading…
Reference in a new issue