Compare commits

...

1 commit

Author SHA1 Message Date
22147c818a
Platform material & filter bundle 2022-08-24 12:21:08 +02:00
6 changed files with 99 additions and 23 deletions

20
src/filters.rs Normal file
View 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,
}

View file

@ -1,6 +1,8 @@
#![allow(clippy::precedence)]
#![allow(clippy::too_many_arguments)]
pub use crate::filters::*;
use crate::AppState;
use bevy::{
@ -322,14 +324,16 @@ fn move_camera(
.iter()
.find(|(character_id, _transform)| *character_id == selected_character_id)
{
let (camera, mut camera_transform) =
camera_query.single_mut();
let (camera, mut camera_transform) = camera_query.single_mut();
let size: Vec2 = camera.logical_viewport_size().unwrap();
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
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;
}
}

View file

@ -39,6 +39,7 @@ pub fn despawn_level(mut commands: Commands, level_query: Query<Entity, With<Lev
pub fn post_setup_level(
mut commands: Commands,
character_meshes: Res<CharacterMeshes>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
current_level: Res<CurrentLevel>,
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
@ -54,6 +55,7 @@ pub fn post_setup_level(
match level_id.0 {
0 => level0::setup(
&mut commands,
&mut meshes,
&character_meshes,
&mut materials,
&mut selected_character_id,
@ -62,6 +64,7 @@ pub fn post_setup_level(
),
1 => level1::setup(
&mut commands,
&mut meshes,
&character_meshes,
&mut materials,
&mut selected_character_id,

View file

@ -1,10 +1,11 @@
use crate::game::*;
use bevy::prelude::*;
use bevy::prelude::{shape::Quad, *};
use bevy_rapier2d::prelude::*;
pub fn setup(
commands: &mut Commands,
meshes: &mut ResMut<Assets<Mesh>>,
character_meshes: &Res<CharacterMeshes>,
materials: &mut ResMut<Assets<ColorMaterial>>,
selected_character_id: &mut Mut<SelectedCharacterId>,
@ -12,8 +13,18 @@ pub fn setup(
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
) {
commands
.spawn_bundle(TransformBundle::from(Transform::from_xyz(0.0, -256.0, 0.0)))
.insert(Collider::cuboid(400., 10.))
.spawn_bundle(ColorMesh2dBundle {
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);
spawn_character(

View file

@ -1,10 +1,11 @@
use crate::game::*;
use bevy::prelude::*;
use bevy::prelude::{shape::Quad, *};
use bevy_rapier2d::prelude::*;
pub fn setup(
commands: &mut Commands,
meshes: &mut ResMut<Assets<Mesh>>,
character_meshes: &Res<CharacterMeshes>,
materials: &mut ResMut<Assets<ColorMaterial>>,
selected_character_id: &mut Mut<SelectedCharacterId>,
@ -12,14 +13,32 @@ pub fn setup(
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
) {
commands
.spawn_bundle(TransformBundle::from(Transform::from_xyz(0.0, -256.0, 0.0)))
.insert(Collider::cuboid(400., 10.))
.spawn_bundle(ColorMesh2dBundle {
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);
commands
.spawn_bundle(TransformBundle::from(Transform::from_xyz(
256.0, -128.0, 0.0,
)))
.insert(Collider::cuboid(200., 10.))
.spawn_bundle(ColorMesh2dBundle {
mesh: meshes
.add(Mesh::from(Quad {
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);
spawn_character(
@ -52,4 +71,24 @@ pub fn setup(
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);
}

View file

@ -1,11 +1,12 @@
#[cfg(not(target_arch = "wasm32"))]
mod audio;
mod filters;
mod game;
mod levels;
mod menu;
mod particle_effect;
use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*};
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
@ -23,15 +24,18 @@ fn main() {
std::thread::spawn(move || audio::setup(audio_event_receiver));
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(audio_event_sender)
.add_state(AppState::Menu)
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins)
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(64.0))
.add_plugin(RapierDebugRenderPlugin::default())
//.add_plugin(RapierDebugRenderPlugin::default())
.add_plugin(menu::MenuPlugin)
.add_plugin(game::GamePlugin)
.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)
.run();
}
@ -43,12 +47,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
commands.insert_resource(font);
commands.spawn_bundle(Camera2dBundle {
camera_2d: Camera2d {
clear_color: ClearColorConfig::Custom(Color::BLACK),
},
..Default::default()
});
commands.spawn_bundle(Camera2dBundle::default());
commands.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 0.6,