Merge branch 'master' of https://git.txmn.tk/tuxmain/bevyjam into nixon-main

This commit is contained in:
Nixon 2022-08-27 11:57:40 +08:00
commit 9fd54a5755
9 changed files with 573 additions and 17 deletions

18
Cargo.lock generated
View file

@ -3754,14 +3754,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",
@ -3775,8 +3774,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",
@ -3787,7 +3785,7 @@ dependencies = [
"fxhash",
"log",
"naga",
"parking_lot 0.12.1",
"parking_lot 0.11.2",
"profiling",
"raw-window-handle 0.4.3",
"smallvec",
@ -3800,8 +3798,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",
@ -3824,7 +3821,7 @@ dependencies = [
"metal",
"naga",
"objc",
"parking_lot 0.12.1",
"parking_lot 0.11.2",
"profiling",
"range-alloc",
"raw-window-handle 0.4.3",
@ -3839,8 +3836,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

@ -28,3 +28,6 @@ cpal = { version = "0.14.0", features = ["wasm-bindgen"] }
[profile.dev.package."*"]
opt-level = 3
[patch.crates-io]
wgpu = { git = "https://github.com/mockersf/wgpu/", branch = "unconditional-clear-workaround" }

View file

@ -13,7 +13,7 @@
* more filters
* despawn black characters
* despawn character when too far
* level design
* more levels
* (?) multiplayer
* more audio
* "jumpable" component to avoid jumping on sensors
@ -55,6 +55,8 @@ 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, 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

@ -22,7 +22,9 @@ impl Plugin for EditorPlugin {
SystemSet::on_update(AppState::Editor)
.with_system(move_system)
.with_system(input_control_system)
.with_system(follow_ends_system),
.with_system(follow_ends_system)
.with_system(remove_system)
.with_system(spawn_system),
);
}
}
@ -61,6 +63,12 @@ struct RotatingFilterAngle(f32);
#[derive(Component)]
struct AbsorbingFilterColor(Color);
#[derive(Component)]
struct MeltyPlatformColor(Color);
#[derive(Component)]
struct Removable;
// Bundles
#[derive(Bundle)]
@ -69,6 +77,9 @@ struct PlatformBundle {
mesh: ColorMesh2dBundle,
size: Size,
platform: Platform,
#[bundle]
pickable: PickableBundle,
removable: Removable,
}
#[derive(Bundle)]
@ -89,6 +100,7 @@ struct CharacterBundle {
#[bundle]
pickable: PickableBundle,
draggable: Draggable,
removable: Removable,
}
#[derive(Bundle)]
@ -97,6 +109,9 @@ struct AbsorbingFilterBundle {
mesh: ColorMesh2dBundle,
size: Size,
color: AbsorbingFilterColor,
#[bundle]
pickable: PickableBundle,
removable: Removable,
}
#[derive(Bundle)]
@ -107,6 +122,18 @@ struct RotatingFilterBundle {
#[bundle]
pickable: PickableBundle,
draggable: Draggable,
removable: Removable,
}
#[derive(Bundle)]
struct MeltyPlatformBundle {
#[bundle]
mesh: ColorMesh2dBundle,
color: MeltyPlatformColor,
#[bundle]
pickable: PickableBundle,
draggable: Draggable,
removable: Removable,
}
// Functions
@ -129,6 +156,8 @@ fn spawn_platform(
},
size: Size(size),
platform: Platform,
pickable: PickableBundle::default(),
removable: Removable,
})
.id();
let ends = Ends(
@ -207,6 +236,7 @@ fn spawn_character(
color: CharacterColor(color),
pickable: PickableBundle::default(),
draggable: Draggable,
removable: Removable,
})
.with_children(|c| {
c.spawn_bundle(Text2dBundle {
@ -245,6 +275,8 @@ fn spawn_absorbing_filter(
},
size: Size(size),
color: AbsorbingFilterColor(color),
pickable: PickableBundle::default(),
removable: Removable,
})
.id();
let ends = Ends(
@ -322,6 +354,7 @@ fn spawn_rotating_filter(
angle: RotatingFilterAngle(angle),
pickable: PickableBundle::default(),
draggable: Draggable,
removable: Removable,
})
.with_children(|c| {
c.spawn_bundle(Text2dBundle {
@ -341,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>>,
@ -394,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(
@ -408,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) {
@ -457,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;
}
@ -518,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(
@ -531,6 +640,7 @@ fn input_control_system(
&platform_query,
&absorbing_filter_query,
&rotating_filter_query,
&melty_platform_query,
);
}
}
@ -584,6 +694,96 @@ fn move_system(
}
}
fn remove_system(
mut commands: Commands,
keyboard_input: Res<Input<KeyCode>>,
mut removable_query: Query<(Entity, &Selection, Option<&Ends>), With<Removable>>,
) {
if keyboard_input.just_released(KeyCode::Delete) {
for (entity, selection, ends) in removable_query.iter_mut() {
if selection.selected() {
commands.entity(entity).despawn_recursive();
if let Some(ends) = ends {
commands.entity(ends.0).despawn_recursive();
commands.entity(ends.1).despawn_recursive();
}
}
}
}
}
fn spawn_system(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
asset_server: Res<AssetServer>,
camera_query: Query<&Transform, With<Camera>>,
keyboard_input: Res<Input<KeyCode>>,
mut character_list: ResMut<CharacterList>,
) {
if keyboard_input.pressed(KeyCode::LControl)
|| keyboard_input.pressed(KeyCode::RControl)
|| keyboard_input.pressed(KeyCode::LAlt)
|| keyboard_input.pressed(KeyCode::RAlt)
{
return;
}
let camera_pos = camera_query.single().translation;
if keyboard_input.just_released(KeyCode::P) {
spawn_platform(
&mut commands,
&mut meshes,
&mut materials,
Transform::from_xyz(camera_pos.x, camera_pos.y, 0.),
Vec2 { x: 96., y: 16. },
);
}
if keyboard_input.just_released(KeyCode::C) {
let index = character_list.0.len();
character_list.0.push(spawn_character(
&mut commands,
&mut meshes,
&mut materials,
&asset_server,
Transform::from_xyz(camera_pos.x, camera_pos.y, 0.),
Color::RED,
index,
));
}
if keyboard_input.just_released(KeyCode::A) {
spawn_absorbing_filter(
&mut commands,
&mut meshes,
&mut materials,
Transform::from_xyz(camera_pos.x, camera_pos.y, 0.),
Vec2 { x: 16., y: 96. },
Color::RED,
);
}
if keyboard_input.just_released(KeyCode::R) {
spawn_rotating_filter(
&mut commands,
&mut meshes,
&mut materials,
&asset_server,
Transform::from_xyz(camera_pos.x, camera_pos.y, 0.),
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(
mut meshes: ResMut<Assets<Mesh>>,
mut follower_query: Query<(&mut Transform, &mut Mesh2dHandle, &mut Size, &Ends)>,

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());