Tutorial levels

This commit is contained in:
Pascal Engélibert 2022-08-25 15:39:16 +02:00
parent f117b2750a
commit 445f3850ca
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
9 changed files with 201 additions and 28 deletions

View file

@ -17,6 +17,7 @@
* (?) multiplayer
* more audio
* "jumpable" component to avoid jumping on sensors
* bug: in level2, move the blue character to win, then reset. The characters are lighter than expected.
## Build

View file

@ -281,6 +281,25 @@ fn collision_event_system(
c_color.0 = filter.apply(c_color.0);
*c_material = materials.add(ColorMaterial::from(c_color.0));
if c_player.is_some() {
audio
.send(AudioMsg::Color([
c_color.0.r(),
c_color.0.g(),
c_color.0.b(),
]))
.ok();
}
} else if let (
Ok((mut c_color, _c_transform, mut c_material, c_player)),
Ok(filter),
) = (
character_query.get_mut(*e2),
pass_through_filter_query.get(*e1),
) {
c_color.0 = filter.apply(c_color.0);
*c_material = materials.add(ColorMaterial::from(c_color.0));
if c_player.is_some() {
audio
.send(AudioMsg::Color([
@ -425,7 +444,7 @@ fn win_setup(
"Press ENTER to level up",
TextStyle {
font,
font_size: 32.0,
font_size: 36.0,
color: Color::WHITE,
},
)

View file

@ -3,6 +3,8 @@
mod game_over;
mod level0;
mod level1;
mod level2;
mod level3;
use crate::game::*;
@ -53,6 +55,22 @@ pub fn post_setup_level(
&audio,
&asset_server,
),
2 => level2::setup(
&mut commands,
&mut meshes,
&character_meshes,
&mut materials,
&audio,
&asset_server,
),
3 => level3::setup(
&mut commands,
&mut meshes,
&character_meshes,
&mut materials,
&audio,
&asset_server,
),
_ => game_over::setup(
&mut commands,
&mut meshes,

View file

@ -54,7 +54,7 @@ pub fn setup(
character_meshes,
materials,
audio,
Transform::from_xyz(-128., -64., 0.),
Transform::from_xyz(0., -64., 0.),
Color::RED,
true,
);

View file

@ -1,3 +1,5 @@
// Movement tutorial
use crate::game::*;
use bevy::prelude::*;
@ -14,7 +16,7 @@ pub fn setup(
commands
.spawn_bundle(Text2dBundle {
text: Text::from_section(
"Combine the colors to synthetize a white light.\nTab to switch; Arrows to move.",
"Combine the colors to synthetize a white light.\nUse arrows to move.",
TextStyle {
font,
font_size: 32.0,
@ -40,9 +42,9 @@ pub fn setup(
materials,
audio,
[
(Transform::from_xyz(-128., -64., 0.), Color::RED),
(Transform::from_xyz(0., -64., 0.), Color::GREEN),
(Transform::from_xyz(128., -64., 0.), Color::BLUE),
(Transform::from_xyz(0., -192., 0.), Color::RED),
(Transform::from_xyz(-128., -192., 0.), Color::GREEN),
(Transform::from_xyz(128., -192., 0.), Color::BLUE),
],
);
}

View file

@ -1,3 +1,5 @@
// Switch tutorial
use crate::game::*;
use bevy::prelude::*;
@ -10,6 +12,22 @@ pub fn setup(
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
asset_server: &Res<AssetServer>,
) {
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
commands
.spawn_bundle(Text2dBundle {
text: Text::from_section(
"Press Tab to switch.",
TextStyle {
font,
font_size: 32.0,
color: Color::WHITE,
},
)
.with_alignment(TextAlignment::CENTER),
..Default::default()
})
.insert(Level);
spawn_platforms(
commands,
meshes,
@ -20,8 +38,8 @@ pub fn setup(
Vec2 { x: 800.0, y: 16.0 },
),
(
Transform::from_xyz(256.0, -128.0, 0.0),
Vec2 { x: 400.0, y: 16.0 },
Transform::from_xyz(128.0, 256.0, 0.0),
Vec2 { x: 96.0, y: 16.0 },
),
],
);
@ -32,25 +50,9 @@ pub fn setup(
materials,
audio,
[
(Transform::from_xyz(128., 64., 0.), Color::BLUE),
(Transform::from_xyz(-128., -128., 0.), Color::RED),
(Transform::from_xyz(0., -128., 0.), Color::GREEN),
(Transform::from_xyz(0., -192., 0.), Color::GREEN),
(Transform::from_xyz(-128., -192., 0.), Color::RED),
(Transform::from_xyz(128., 320., 0.), Color::BLUE),
],
);
spawn_absorbing_filter(
commands,
meshes,
materials,
Transform::from_xyz(0., 0., 2.),
Vec2 { x: 128.0, y: 16.0 },
Color::RED,
);
spawn_rotating_filter(
commands,
asset_server,
Transform::from_xyz(256., -224., 2.),
45.,
);
}

72
src/levels/level2.rs Normal file
View file

@ -0,0 +1,72 @@
// Absorbing filter tutorial
use crate::game::*;
use bevy::prelude::*;
pub fn setup(
commands: &mut Commands,
meshes: &mut ResMut<Assets<Mesh>>,
character_meshes: &Res<CharacterMeshes>,
materials: &mut ResMut<Assets<ColorMaterial>>,
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
asset_server: &Res<AssetServer>,
) {
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
commands
.spawn_bundle(Text2dBundle {
text: Text::from_section(
"Press R to reset.",
TextStyle {
font,
font_size: 32.0,
color: Color::WHITE,
},
)
.with_alignment(TextAlignment::CENTER),
..Default::default()
})
.insert(Level);
spawn_platforms(
commands,
meshes,
materials,
[
(
Transform::from_xyz(0.0, -256.0, 0.0),
Vec2 { x: 800.0, y: 16.0 },
),
(
Transform::from_xyz(0.0, -128.0, 0.0),
Vec2 { x: 800.0, y: 16.0 },
),
],
);
spawn_characters(
commands,
character_meshes,
materials,
audio,
[
(
Transform::from_xyz(-128., -192., 0.),
Color::rgba(1., 0.64, 0., 1.),
),
(
Transform::from_xyz(128., -192., 0.),
Color::rgba(0., 0.37, 1., 1.),
),
],
);
spawn_absorbing_filter(
commands,
meshes,
materials,
Transform::from_xyz(0., -192., 2.),
Vec2 { x: 16.0, y: 112.0 },
Color::RED,
);
}

59
src/levels/level3.rs Normal file
View file

@ -0,0 +1,59 @@
// Rotating filter tutorial
use crate::game::*;
use bevy::prelude::*;
pub fn setup(
commands: &mut Commands,
meshes: &mut ResMut<Assets<Mesh>>,
character_meshes: &Res<CharacterMeshes>,
materials: &mut ResMut<Assets<ColorMaterial>>,
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
asset_server: &Res<AssetServer>,
) {
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
commands
.spawn_bundle(Text2dBundle {
text: Text::from_section(
"Let's rotate the hue!",
TextStyle {
font,
font_size: 32.0,
color: Color::WHITE,
},
)
.with_alignment(TextAlignment::CENTER),
..Default::default()
})
.insert(Level);
spawn_platforms(
commands,
meshes,
materials,
[(
Transform::from_xyz(0.0, -256.0, 0.0),
Vec2 { x: 800.0, y: 16.0 },
)],
);
spawn_characters(
commands,
character_meshes,
materials,
audio,
[
(Transform::from_xyz(0., -192., 0.), Color::RED),
(Transform::from_xyz(-128., -192., 0.), Color::RED),
(Transform::from_xyz(128., -192., 0.), Color::RED),
],
);
spawn_rotating_filter(
commands,
asset_server,
Transform::from_xyz(0., -64., 2.),
45.,
);
}

View file

@ -26,7 +26,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
"BEVYJAM",
TextStyle {
font: font.clone(),
font_size: 48.0,
font_size: 96.0,
color: Color::WHITE,
},
)