From a859d72da33769e0ce1f57cdc045ffe595021ac7 Mon Sep 17 00:00:00 2001 From: tuxmain Date: Fri, 26 Aug 2022 23:54:49 +0200 Subject: [PATCH] melting platform, level 4 --- Cargo.lock | 18 +-- Cargo.toml | 3 + README.md | 2 +- assets/game.levels.json | 285 +++++++++++++++++++++++++++++++++++++++- assets/melty.png | Bin 0 -> 1127 bytes src/editor.rs | 103 ++++++++++++++- src/game.rs | 53 +++++++- src/levels.rs | 18 +++ src/main.rs | 5 +- 9 files changed, 471 insertions(+), 16 deletions(-) create mode 100644 assets/melty.png diff --git a/Cargo.lock b/Cargo.lock index 2e34d56..4a6e782 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3753,14 +3753,13 @@ checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" [[package]] name = "wgpu" version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "277e967bf8b7820a76852645a6bce8bbd31c32fda2042e82d8e3ea75fda8892d" +source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9" dependencies = [ "arrayvec", "js-sys", "log", "naga", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "raw-window-handle 0.4.3", "smallvec", "wasm-bindgen", @@ -3774,8 +3773,7 @@ dependencies = [ [[package]] name = "wgpu-core" version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b92788dec9d0c1bed849a1b83f01b2ee12819bf04a79c90f68e4173f7b5ba2" +source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9" dependencies = [ "arrayvec", "bit-vec", @@ -3786,7 +3784,7 @@ dependencies = [ "fxhash", "log", "naga", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "raw-window-handle 0.4.3", "smallvec", @@ -3799,8 +3797,7 @@ dependencies = [ [[package]] name = "wgpu-hal" version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20cbdfc3d0637dba3d5536b93adef3d26023a0b96f0e1ee5ee9560a401d9f646" +source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9" dependencies = [ "android_system_properties", "arrayvec", @@ -3823,7 +3820,7 @@ dependencies = [ "metal", "naga", "objc", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "range-alloc", "raw-window-handle 0.4.3", @@ -3838,8 +3835,7 @@ dependencies = [ [[package]] name = "wgpu-types" version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f762cbc08e1a51389859cf9c199c7aef544789cf3510889aab12c607f701604" +source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9" dependencies = [ "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index 742804f..3eac3b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,6 @@ ticktock = "0.8.0" [profile.dev.package."*"] opt-level = 3 + +[patch.crates-io] +wgpu = { git = "https://github.com/mockersf/wgpu/", branch = "unconditional-clear-workaround" } diff --git a/README.md b/README.md index ed73763..bcce2c6 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Edit the level `N: u32` with the command `bevyjam e`. * **Select**: left click to select, click in void to deselect, CTRL+click to select many, CTRL+A to select all * **Move selection**: arrows to move one step, Shift+arrows to move continuously * **Delete selection**: delete -* **Add objects**: P=platform, C=character, A=absorbing filter, R=rotating filter +* **Add objects**: P=platform, C=character, A=absorbing filter, R=rotating filter, M=melty platform * **Move camera**: CTRL+arrows * **Save**: CTRL+S diff --git a/assets/game.levels.json b/assets/game.levels.json index bca10de..d52eafa 100644 --- a/assets/game.levels.json +++ b/assets/game.levels.json @@ -54,6 +54,7 @@ ], "absorbing_filters": [], "rotating_filters": [], + "melty_platforms": [], "texts": [ { "pos": [ @@ -129,6 +130,7 @@ ], "absorbing_filters": [], "rotating_filters": [], + "melty_platforms": [], "texts": [ { "pos": [ @@ -209,6 +211,7 @@ } ], "rotating_filters": [], + "melty_platforms": [], "texts": [ { "pos": [ @@ -279,9 +282,10 @@ 0.0, -64.0 ], - "angle": 45.0 + "angle": 120.0 } ], + "melty_platforms": [], "texts": [ { "pos": [ @@ -293,6 +297,284 @@ } ] }, + { + "comment": "First puzzle", + "characters": [ + { + "pos": [ + 184.0, + 168.0 + ], + "color": [ + 0.85, + 0.5, + 0.0, + 1.0 + ] + }, + { + "pos": [ + -184.0, + 168.0 + ], + "color": [ + 0.0, + 0.5, + 0.1, + 1.0 + ] + }, + { + "pos": [ + -1376.0, + -184.0 + ], + "color": [ + 1.0, + 0.0, + 0.0, + 1.0 + ] + }, + { + "pos": [ + -1512.0, + -184.0 + ], + "color": [ + 0.0, + 0.0, + 0.9, + 1.0 + ] + }, + { + "pos": [ + 0.0, + 368.0 + ], + "color": [ + 0.15, + 0.0, + 0.5, + 1.0 + ] + } + ], + "platforms": [ + { + "pos": [ + -12.0, + -264.0 + ], + "size": [ + 456.0, + 16.0 + ] + }, + { + "pos": [ + -148.0, + 120.0 + ], + "size": [ + 200.0, + 16.0 + ] + }, + { + "pos": [ + 148.0, + 120.0 + ], + "size": [ + 200.0, + 16.0 + ] + }, + { + "pos": [ + -1336.0, + -256.0 + ], + "size": [ + 576.0, + 16.0 + ] + }, + { + "pos": [ + -240.0, + 292.0 + ], + "size": [ + 16.0, + 328.0 + ] + }, + { + "pos": [ + 240.0, + 292.0 + ], + "size": [ + 16.0, + 328.0 + ] + }, + { + "pos": [ + 0.0, + 20.0 + ], + "size": [ + 176.0, + 24.0 + ] + }, + { + "pos": [ + -200.0, + 60.0 + ], + "size": [ + 16.0, + 104.0 + ] + }, + { + "pos": [ + 200.0, + 60.0 + ], + "size": [ + 16.0, + 104.0 + ] + }, + { + "pos": [ + 0.0, + 320.0 + ], + "size": [ + 96.0, + 16.0 + ] + } + ], + "absorbing_filters": [ + { + "pos": [ + -1176.0, + -96.0 + ], + "size": [ + 16.0, + 304.0 + ], + "color": [ + 0.0, + 0.5, + 0.5, + 1.0 + ] + }, + { + "pos": [ + -140.0, + 16.0 + ], + "size": [ + 104.0, + 16.0 + ], + "color": [ + 0.6, + 0.0, + 0.0, + 1.0 + ] + }, + { + "pos": [ + 140.0, + 16.0 + ], + "size": [ + 104.0, + 16.0 + ], + "color": [ + 0.0, + 1.0, + 0.0, + 1.0 + ] + } + ], + "rotating_filters": [], + "melty_platforms": [ + { + "pos": [ + 0.0, + 120.0 + ], + "color": [ + 0.7, + 0.7, + 0.0, + 1.0 + ] + }, + { + "pos": [ + -616.0, + -256.0 + ], + "color": [ + 0.45, + 0.0, + 0.0, + 1.0 + ] + }, + { + "pos": [ + -856.0, + -256.0 + ], + "color": [ + 0.0, + 0.0, + 0.5, + 1.0 + ] + }, + { + "pos": [ + -400.0, + -256.0 + ], + "color": [ + 0.0, + 0.0, + 0.6, + 1.0 + ] + } + ], + "texts": [ + { + "pos": [ + 0.0, + -64.0 + ], + "font_size": 32.0, + "text": "Too much light\ncan cause some platforms to melt." + } + ] + }, { "comment": "Game over", "characters": [ @@ -323,6 +605,7 @@ ], "absorbing_filters": [], "rotating_filters": [], + "melty_platforms": [], "texts": [ { "pos": [ diff --git a/assets/melty.png b/assets/melty.png new file mode 100644 index 0000000000000000000000000000000000000000..5d5716fc397b7dee2a0c60996219ecadc6cf89ce GIT binary patch literal 1127 zcmV-t1ep7YP)AHIP0004mX+uL$Nkc;* zaB^>EX>4Tx04R}tkv&MmKpe$iTct%R3U-j$0B8Y^bWHa-`5n`d##c~(3vY`@B5yuo&qkMnP zWrgz=XSG^q?R)YUh6~!tGS_L2AcaLNL4*JqbyQG=g*dGmDJC+spY-rY9luB}nOqex zax9<*6_Voz|AXJ%n#IY4n-oq0y)U-?F$x5CfmXw|zmILZbpiyQfh(=!uQh?0PtqG5 zEp`M9Yy%h99ZlW?E_Z<8CtWfmM+(sN7mL9A8GTb87`g@e*4*CO`#607veZ@j1~@nb z#!8gE?(yzWcW?imY4`U7dX{pk%auSL00007bV*G`2j&PG5Dx-&t#FnA00N6iL_t(o z!?l>dYg17a$3KZ%nt)qT2Z>`yhg8U)Ar4h5U8L2iS-QCti%w2LCl?nd2kV$w=oT9~ z3N8xjA_YN3!D^q&R|w&r``&r?<_l-YkN569=X<{Ae&2&~JWzPhaDMN_7Eq86U0@&B z3H;Up-TZhGM-0?k#`>OYPTy zi@>LZd!NnR>w@>UcwIj=hcRs$-yo2g*Al@L?=SFN?1xW=721jIJiRagX^0)qev zYZ(f*=^&uW{2i&$LTc}+i%&D`yIEJBe*$wd<|6(Vd&6-Scn>PifxHZyOHlh`;4knt zk?3aKq^*N$Cqlq0;FmFqwldk(M&NVkJ~woBEG3Mh-%`SejPN9F6+7l4roacuxXPL# z8ynmAxXiQ8N_&_sO*LEu2 zD`aCmjWZC5lL!f|gj}yELbzE+1sfTjE@Ljj<8op)*3&q#7jA_LwFtCCu&bUuS;pxC tUv7D=Z^*`a8mA``rwIpgU9>F{{sA}vu;HTda^C;|002ovPDHLkV1iPP{(}Gj literal 0 HcmV?d00001 diff --git a/src/editor.rs b/src/editor.rs index 28dd89d..73356e6 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -63,6 +63,9 @@ struct RotatingFilterAngle(f32); #[derive(Component)] struct AbsorbingFilterColor(Color); +#[derive(Component)] +struct MeltyPlatformColor(Color); + #[derive(Component)] struct Removable; @@ -122,6 +125,17 @@ struct RotatingFilterBundle { removable: Removable, } +#[derive(Bundle)] +struct MeltyPlatformBundle { + #[bundle] + mesh: ColorMesh2dBundle, + color: MeltyPlatformColor, + #[bundle] + pickable: PickableBundle, + draggable: Draggable, + removable: Removable, +} + // Functions fn spawn_platform( @@ -360,6 +374,52 @@ fn spawn_rotating_filter( .id() } +fn spawn_melty_platform( + commands: &mut Commands, + meshes: &mut ResMut>, + materials: &mut ResMut>, + asset_server: &Res, + + transform: Transform, + color: Color, +) -> Entity { + let font = asset_server.get_handle("UacariLegacy-Thin.ttf"); + commands + .spawn_bundle(MeltyPlatformBundle { + mesh: ColorMesh2dBundle { + mesh: meshes + .add(Mesh::from(Quad { + size: Vec2 { x: 96., y: 16. }, + flip: false, + })) + .into(), + material: materials.add(ColorMaterial::from(color)), + transform, + ..default() + }, + color: MeltyPlatformColor(color), + pickable: PickableBundle::default(), + draggable: Draggable, + removable: Removable, + }) + .with_children(|c| { + c.spawn_bundle(Text2dBundle { + text: Text::from_section( + "MELTY", + TextStyle { + font: font.clone(), + font_size: 16., + color: Color::BLACK, + }, + ) + .with_alignment(TextAlignment::CENTER), + transform: Transform::from_xyz(0., 0., 1.), + ..Default::default() + }); + }) + .id() +} + fn spawn_stored_level( commands: &mut Commands, meshes: &mut ResMut>, @@ -413,6 +473,17 @@ fn spawn_stored_level( rotating_filter.angle, ); } + + for melty_platform in stored_level.melty_platforms.iter() { + spawn_melty_platform( + commands, + meshes, + materials, + asset_server, + Transform::from_xyz(melty_platform.pos.x, melty_platform.pos.y, 0.), + melty_platform.color.into(), + ); + } } fn save_level( @@ -427,6 +498,10 @@ fn save_level( (&Transform, &RotatingFilterAngle), (Without, Without), >, + melty_platform_query: &Query< + (&Transform, &MeltyPlatformColor), + (Without, Without), + >, ) { let stored_levels = stored_levels_assets.get_mut(stored_levels_handle).unwrap(); if let Some(stored_level) = stored_levels.levels.get_mut(level_id.0 .0 as usize) { @@ -476,6 +551,17 @@ fn save_level( angle: angle.0, }) } + + stored_level.melty_platforms.clear(); + for (transform, color) in melty_platform_query.iter() { + stored_level.melty_platforms.push(StoredMeltyPlatform { + pos: Vec2 { + x: transform.translation.x, + y: transform.translation.y, + }, + color: color.0.into(), + }) + } } else { return; } @@ -537,8 +623,12 @@ fn input_control_system( (&Transform, &RotatingFilterAngle), (Without, Without), >, + melty_platform_query: Query< + (&Transform, &MeltyPlatformColor), + (Without, Without), + >, ) { - if keyboard_input.just_released(KeyCode::S) + if keyboard_input.just_pressed(KeyCode::S) && (keyboard_input.pressed(KeyCode::LControl) || keyboard_input.pressed(KeyCode::RControl)) { save_level( @@ -550,6 +640,7 @@ fn input_control_system( &platform_query, &absorbing_filter_query, &rotating_filter_query, + &melty_platform_query, ); } } @@ -681,6 +772,16 @@ fn spawn_system( 90., ); } + if keyboard_input.just_released(KeyCode::M) { + spawn_melty_platform( + &mut commands, + &mut meshes, + &mut materials, + &asset_server, + Transform::from_xyz(camera_pos.x, camera_pos.y, 0.), + Color::RED, + ); + } } fn follow_ends_system( diff --git a/src/game.rs b/src/game.rs index 32f3bb0..2463d05 100644 --- a/src/game.rs +++ b/src/game.rs @@ -98,6 +98,9 @@ pub struct Player; #[derive(Component)] pub struct CollisionCount(usize); +#[derive(Component)] +pub struct Melty(pub Color); + // Systems fn setup( @@ -217,6 +220,39 @@ pub fn spawn_platform( .insert(Level); } +pub fn spawn_melty_platform( + commands: &mut Commands, + meshes: &mut ResMut>, + materials: &mut ResMut>, + asset_server: &Res, + + transform: Transform, + color: Color, +) { + commands + .spawn_bundle(ColorMesh2dBundle { + mesh: meshes + .add(Mesh::from(Quad { + size: Vec2 { x: 96., y: 16. }, + flip: false, + })) + .into(), + material: materials.add(ColorMaterial::from(color)), + transform, + ..default() + }) + .insert(Collider::cuboid(48., 8.)) + .insert(Melty(color)) + .insert(Level) + .with_children(|c| { + c.spawn_bundle(SpriteBundle { + texture: asset_server.get_handle("melty.png"), + transform: Transform::from_xyz(0., 0., 0.5), + ..default() + }); + }); +} + fn collision_event_system( mut commands: Commands, character_meshes: Res, @@ -229,6 +265,7 @@ fn collision_event_system( Option<&Player>, )>, pass_through_filter_query: Query<&PassThroughFilter>, + melty_query: Query<&Melty>, mut collision_counter_query: Query<&mut CollisionCount>, mut app_state: ResMut>, audio: Res>, @@ -250,7 +287,7 @@ fn collision_event_system( // If color approximately white if app_state.current() == &AppState::Game - && 4. - new_color.length_squared() < 0.1 + && Vec4::from(new_color).min_element() >= 0.9 { app_state.replace(AppState::Win).ok(); } @@ -275,6 +312,18 @@ fn collision_event_system( ); audio.send(AudioMsg::Fusion).ok(); + } else if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) = + (character_query.get_mut(*e1), melty_query.get(*e2)) + { + if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. { + commands.entity(*e2).despawn_recursive(); + } + } else if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) = + (character_query.get_mut(*e2), melty_query.get(*e1)) + { + if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. { + commands.entity(*e1).despawn_recursive(); + } } } else if *flags == CollisionEventFlags::SENSOR { if let (Ok((mut c_color, _c_transform, mut c_material, c_player)), Ok(filter)) = ( @@ -292,6 +341,7 @@ fn collision_event_system( c_color.0.b(), ])) .ok(); + audio.send(AudioMsg::Switch).ok(); } } else if let ( Ok((mut c_color, _c_transform, mut c_material, c_player)), @@ -311,6 +361,7 @@ fn collision_event_system( c_color.0.b(), ])) .ok(); + audio.send(AudioMsg::Switch).ok(); } } else if let (Ok(mut collision_count), Err(_)) = ( collision_counter_query.get_mut(*e1), diff --git a/src/levels.rs b/src/levels.rs index f99b429..240abdb 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -109,6 +109,16 @@ pub fn spawn_stored_level( rotating_filter.angle, ); } + for melty_platform in stored_level.melty_platforms.iter() { + spawn_melty_platform( + commands, + meshes, + materials, + asset_server, + Transform::from_xyz(melty_platform.pos.x, melty_platform.pos.y, 2.), + melty_platform.color.into(), + ); + } for text in stored_level.texts.iter() { commands .spawn_bundle(Text2dBundle { @@ -145,6 +155,7 @@ pub mod stored { pub platforms: Vec, pub absorbing_filters: Vec, pub rotating_filters: Vec, + pub melty_platforms: Vec, pub texts: Vec, } @@ -177,6 +188,13 @@ pub mod stored { pub angle: f32, } + #[derive(Deserialize, Serialize, TypeUuid)] + #[uuid = "cb0773ef-eca6-9b96-dcba-f4240ebdcf40"] + pub struct StoredMeltyPlatform { + pub pos: Vec2, + pub color: Vec4, + } + #[derive(Deserialize, Serialize, TypeUuid)] #[uuid = "72f6321a-f01f-6eea-9b17-3159837a2fd3"] pub struct StoredText { diff --git a/src/main.rs b/src/main.rs index 7976caa..d26e9f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,7 +99,10 @@ fn setup(mut commands: Commands, mut windows: ResMut, asset_server: Res assets.add(asset_server.load::("game.levels.json")), ); commands.insert_resource(assets.add(asset_server.load::("UacariLegacy-Thin.ttf"))); - commands.insert_resource(assets.add(asset_server.load::("bevy.png"))); + commands.insert_resource([ + assets.add(asset_server.load::("bevy.png")), + assets.add(asset_server.load("melty.png")), + ]); commands.insert_resource(assets); commands.spawn_bundle(Camera2dBundle::default());