Platform material & filter bundle
This commit is contained in:
parent
12e58b3fc0
commit
297811e882
6 changed files with 93 additions and 21 deletions
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,
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
#![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::{
|
||||||
|
|
|
@ -36,6 +36,7 @@ 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_startup_event: EventReader<LevelStartupEvent>,
|
mut level_startup_event: EventReader<LevelStartupEvent>,
|
||||||
|
@ -47,12 +48,14 @@ pub fn post_setup_level(
|
||||||
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,
|
||||||
&audio,
|
&audio,
|
||||||
),
|
),
|
||||||
1 => level1::setup(
|
1 => level1::setup(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
|
&mut meshes,
|
||||||
&character_meshes,
|
&character_meshes,
|
||||||
&mut materials,
|
&mut materials,
|
||||||
&audio,
|
&audio,
|
||||||
|
|
|
@ -1,19 +1,28 @@
|
||||||
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_character(
|
||||||
|
|
|
@ -1,23 +1,42 @@
|
||||||
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>>,
|
||||||
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_character(
|
||||||
|
@ -47,4 +66,24 @@ pub fn setup(
|
||||||
Color::GREEN,
|
Color::GREEN,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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