From 445f3850cad3e881d417533977ad21bf5c3d1828 Mon Sep 17 00:00:00 2001 From: tuxmain Date: Thu, 25 Aug 2022 15:39:16 +0200 Subject: [PATCH] Tutorial levels --- README.md | 1 + src/game.rs | 21 +++++++++++- src/levels.rs | 18 +++++++++++ src/levels/game_over.rs | 2 +- src/levels/level0.rs | 10 +++--- src/levels/level1.rs | 44 +++++++++++++------------ src/levels/level2.rs | 72 +++++++++++++++++++++++++++++++++++++++++ src/levels/level3.rs | 59 +++++++++++++++++++++++++++++++++ src/menu.rs | 2 +- 9 files changed, 201 insertions(+), 28 deletions(-) create mode 100644 src/levels/level2.rs create mode 100644 src/levels/level3.rs diff --git a/README.md b/README.md index 65737f5..17112e6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/game.rs b/src/game.rs index 6cdd7cd..c335c75 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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, }, ) diff --git a/src/levels.rs b/src/levels.rs index ef9557f..ad217e1 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -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, diff --git a/src/levels/game_over.rs b/src/levels/game_over.rs index 5fa3372..d513383 100644 --- a/src/levels/game_over.rs +++ b/src/levels/game_over.rs @@ -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, ); diff --git a/src/levels/level0.rs b/src/levels/level0.rs index 3679121..d6789d8 100644 --- a/src/levels/level0.rs +++ b/src/levels/level0.rs @@ -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), ], ); } diff --git a/src/levels/level1.rs b/src/levels/level1.rs index ce3906b..1d92187 100644 --- a/src/levels/level1.rs +++ b/src/levels/level1.rs @@ -1,3 +1,5 @@ +// Switch tutorial + use crate::game::*; use bevy::prelude::*; @@ -10,6 +12,22 @@ pub fn setup( audio: &Res>, asset_server: &Res, ) { + 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., - ); } diff --git a/src/levels/level2.rs b/src/levels/level2.rs new file mode 100644 index 0000000..91606d5 --- /dev/null +++ b/src/levels/level2.rs @@ -0,0 +1,72 @@ +// Absorbing filter tutorial + +use crate::game::*; + +use bevy::prelude::*; + +pub fn setup( + commands: &mut Commands, + meshes: &mut ResMut>, + character_meshes: &Res, + materials: &mut ResMut>, + audio: &Res>, + asset_server: &Res, +) { + 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, + ); +} diff --git a/src/levels/level3.rs b/src/levels/level3.rs new file mode 100644 index 0000000..5fa2607 --- /dev/null +++ b/src/levels/level3.rs @@ -0,0 +1,59 @@ +// Rotating filter tutorial + +use crate::game::*; + +use bevy::prelude::*; + +pub fn setup( + commands: &mut Commands, + meshes: &mut ResMut>, + character_meshes: &Res, + materials: &mut ResMut>, + audio: &Res>, + asset_server: &Res, +) { + 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., + ); +} diff --git a/src/menu.rs b/src/menu.rs index 52bcdb9..fff9778 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -26,7 +26,7 @@ fn setup(mut commands: Commands, asset_server: Res) { "BEVYJAM", TextStyle { font: font.clone(), - font_size: 48.0, + font_size: 96.0, color: Color::WHITE, }, )