melting platform, level 4

This commit is contained in:
Pascal Engélibert 2022-08-26 23:54:49 +02:00
parent 585b74bf72
commit a859d72da3
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
9 changed files with 471 additions and 16 deletions

18
Cargo.lock generated
View file

@ -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",
]

View file

@ -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" }

View file

@ -56,7 +56,7 @@ Edit the level `N: u32` with the command `bevyjam <N> 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

View file

@ -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": [

BIN
assets/melty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -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<Assets<Mesh>>,
materials: &mut ResMut<Assets<ColorMaterial>>,
asset_server: &Res<AssetServer>,
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<Assets<Mesh>>,
@ -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<Platform>, Without<CharacterColor>),
>,
melty_platform_query: &Query<
(&Transform, &MeltyPlatformColor),
(Without<Platform>, Without<CharacterColor>),
>,
) {
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<Platform>, Without<CharacterColor>),
>,
melty_platform_query: Query<
(&Transform, &MeltyPlatformColor),
(Without<Platform>, Without<CharacterColor>),
>,
) {
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(

View file

@ -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<Assets<Mesh>>,
materials: &mut ResMut<Assets<ColorMaterial>>,
asset_server: &Res<AssetServer>,
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<CharacterMeshes>,
@ -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<State<AppState>>,
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
@ -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),

View file

@ -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<StoredPlatform>,
pub absorbing_filters: Vec<StoredAbsorbingFilter>,
pub rotating_filters: Vec<StoredRotatingFilter>,
pub melty_platforms: Vec<StoredMeltyPlatform>,
pub texts: Vec<StoredText>,
}
@ -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 {

View file

@ -99,7 +99,10 @@ fn setup(mut commands: Commands, mut windows: ResMut<Windows>, asset_server: Res
assets.add(asset_server.load::<levels::StoredLevels, _>("game.levels.json")),
);
commands.insert_resource(assets.add(asset_server.load::<Font, _>("UacariLegacy-Thin.ttf")));
commands.insert_resource(assets.add(asset_server.load::<Image, _>("bevy.png")));
commands.insert_resource([
assets.add(asset_server.load::<Image, _>("bevy.png")),
assets.add(asset_server.load("melty.png")),
]);
commands.insert_resource(assets);
commands.spawn_bundle(Camera2dBundle::default());