Platform material & filter bundle
This commit is contained in:
parent
ce37ddd0bd
commit
22147c818a
6 changed files with 99 additions and 23 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,
|
||||||
|
}
|
12
src/game.rs
12
src/game.rs
|
@ -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::{
|
||||||
|
@ -322,14 +324,16 @@ fn move_camera(
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(character_id, _transform)| *character_id == selected_character_id)
|
.find(|(character_id, _transform)| *character_id == selected_character_id)
|
||||||
{
|
{
|
||||||
let (camera, mut camera_transform) =
|
let (camera, mut camera_transform) = camera_query.single_mut();
|
||||||
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(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);
|
||||||
camera_transform.translation.z = 999.0;
|
camera_transform.translation.z = 999.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,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_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
||||||
|
@ -54,6 +55,7 @@ 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,
|
||||||
&mut selected_character_id,
|
&mut selected_character_id,
|
||||||
|
@ -62,6 +64,7 @@ pub fn post_setup_level(
|
||||||
),
|
),
|
||||||
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 selected_character_id,
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
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>,
|
selected_character_id: &mut Mut<SelectedCharacterId>,
|
||||||
|
@ -12,8 +13,18 @@ pub fn setup(
|
||||||
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,10 +1,11 @@
|
||||||
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>,
|
selected_character_id: &mut Mut<SelectedCharacterId>,
|
||||||
|
@ -12,14 +13,32 @@ pub fn setup(
|
||||||
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(
|
||||||
|
@ -52,4 +71,24 @@ pub fn setup(
|
||||||
Transform::from_xyz(0., -128., 0.),
|
Transform::from_xyz(0., -128., 0.),
|
||||||
Color::GREEN,
|
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