Compare commits
No commits in common. "4fc53c04aae28b5f4daebe565651fa56691f6888" and "f1e88d34606b4374e4ada8b6222bde4fd57d2865" have entirely different histories.
4fc53c04aa
...
f1e88d3460
11 changed files with 63 additions and 763 deletions
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -3754,13 +3754,14 @@ checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
|
|||
[[package]]
|
||||
name = "wgpu"
|
||||
version = "0.13.1"
|
||||
source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "277e967bf8b7820a76852645a6bce8bbd31c32fda2042e82d8e3ea75fda8892d"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"js-sys",
|
||||
"log",
|
||||
"naga",
|
||||
"parking_lot 0.11.2",
|
||||
"parking_lot 0.12.1",
|
||||
"raw-window-handle 0.4.3",
|
||||
"smallvec",
|
||||
"wasm-bindgen",
|
||||
|
@ -3774,7 +3775,8 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "wgpu-core"
|
||||
version = "0.13.2"
|
||||
source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89b92788dec9d0c1bed849a1b83f01b2ee12819bf04a79c90f68e4173f7b5ba2"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bit-vec",
|
||||
|
@ -3785,7 +3787,7 @@ dependencies = [
|
|||
"fxhash",
|
||||
"log",
|
||||
"naga",
|
||||
"parking_lot 0.11.2",
|
||||
"parking_lot 0.12.1",
|
||||
"profiling",
|
||||
"raw-window-handle 0.4.3",
|
||||
"smallvec",
|
||||
|
@ -3798,7 +3800,8 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "wgpu-hal"
|
||||
version = "0.13.2"
|
||||
source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20cbdfc3d0637dba3d5536b93adef3d26023a0b96f0e1ee5ee9560a401d9f646"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"arrayvec",
|
||||
|
@ -3821,7 +3824,7 @@ dependencies = [
|
|||
"metal",
|
||||
"naga",
|
||||
"objc",
|
||||
"parking_lot 0.11.2",
|
||||
"parking_lot 0.12.1",
|
||||
"profiling",
|
||||
"range-alloc",
|
||||
"raw-window-handle 0.4.3",
|
||||
|
@ -3836,7 +3839,8 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "wgpu-types"
|
||||
version = "0.13.2"
|
||||
source = "git+https://github.com/mockersf/wgpu/?branch=unconditional-clear-workaround#a703a78644bc277f8b93870297bb3734e25f2be9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f762cbc08e1a51389859cf9c199c7aef544789cf3510889aab12c607f701604"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
|
|
@ -28,6 +28,3 @@ 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" }
|
||||
|
|
|
@ -13,13 +13,11 @@
|
|||
* more filters
|
||||
* despawn black characters
|
||||
* despawn character when too far
|
||||
* more levels
|
||||
* level design
|
||||
* (?) 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. (also level 4)
|
||||
* redshift warning
|
||||
* itchio test
|
||||
* bug: in level2, move the blue character to win, then reset. The characters are lighter than expected.
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -57,8 +55,6 @@ 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
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
],
|
||||
"absorbing_filters": [],
|
||||
"rotating_filters": [],
|
||||
"melty_platforms": [],
|
||||
"texts": [
|
||||
{
|
||||
"pos": [
|
||||
|
@ -130,7 +129,6 @@
|
|||
],
|
||||
"absorbing_filters": [],
|
||||
"rotating_filters": [],
|
||||
"melty_platforms": [],
|
||||
"texts": [
|
||||
{
|
||||
"pos": [
|
||||
|
@ -147,7 +145,7 @@
|
|||
"characters": [
|
||||
{
|
||||
"pos": [
|
||||
-160.0,
|
||||
-128.0,
|
||||
-192.0
|
||||
],
|
||||
"color": [
|
||||
|
@ -159,7 +157,7 @@
|
|||
},
|
||||
{
|
||||
"pos": [
|
||||
160.0,
|
||||
128.0,
|
||||
-192.0
|
||||
],
|
||||
"color": [
|
||||
|
@ -211,7 +209,6 @@
|
|||
}
|
||||
],
|
||||
"rotating_filters": [],
|
||||
"melty_platforms": [],
|
||||
"texts": [
|
||||
{
|
||||
"pos": [
|
||||
|
@ -219,14 +216,6 @@
|
|||
0.0
|
||||
],
|
||||
"font_size": 32.0,
|
||||
"text": "This filter absorbs light."
|
||||
},
|
||||
{
|
||||
"pos": [
|
||||
0.0,
|
||||
-64.0
|
||||
],
|
||||
"font_size": 32.0,
|
||||
"text": "Press R to reset."
|
||||
}
|
||||
]
|
||||
|
@ -290,10 +279,9 @@
|
|||
0.0,
|
||||
-64.0
|
||||
],
|
||||
"angle": 120.0
|
||||
"angle": 45.0
|
||||
}
|
||||
],
|
||||
"melty_platforms": [],
|
||||
"texts": [
|
||||
{
|
||||
"pos": [
|
||||
|
@ -305,352 +293,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"comment": "Melting platform tutorial",
|
||||
"characters": [
|
||||
{
|
||||
"pos": [
|
||||
-304.0,
|
||||
-208.0
|
||||
],
|
||||
"color": [
|
||||
0.7,
|
||||
0.7,
|
||||
0.7,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"pos": [
|
||||
304.0,
|
||||
-208.0
|
||||
],
|
||||
"color": [
|
||||
0.3,
|
||||
0.3,
|
||||
0.3,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
],
|
||||
"platforms": [
|
||||
{
|
||||
"pos": [
|
||||
-304.0,
|
||||
-256.0
|
||||
],
|
||||
"size": [
|
||||
192.0,
|
||||
16.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"pos": [
|
||||
304.0,
|
||||
-256.0
|
||||
],
|
||||
"size": [
|
||||
192.0,
|
||||
16.0
|
||||
]
|
||||
}
|
||||
],
|
||||
"absorbing_filters": [],
|
||||
"rotating_filters": [],
|
||||
"melty_platforms": [
|
||||
{
|
||||
"pos": [
|
||||
0.0,
|
||||
-256.0
|
||||
],
|
||||
"color": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
],
|
||||
"texts": [
|
||||
{
|
||||
"pos": [
|
||||
0.0,
|
||||
-64.0
|
||||
],
|
||||
"font_size": 32.0,
|
||||
"text": "Too much light\ncause some platforms to melt."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"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": []
|
||||
},
|
||||
{
|
||||
"comment": "Game over",
|
||||
"characters": [
|
||||
|
@ -681,7 +323,6 @@
|
|||
],
|
||||
"absorbing_filters": [],
|
||||
"rotating_filters": [],
|
||||
"melty_platforms": [],
|
||||
"texts": [
|
||||
{
|
||||
"pos": [
|
||||
|
|
BIN
assets/melty.png
BIN
assets/melty.png
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
204
src/editor.rs
204
src/editor.rs
|
@ -22,9 +22,7 @@ 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(remove_system)
|
||||
.with_system(spawn_system),
|
||||
.with_system(follow_ends_system),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -63,12 +61,6 @@ struct RotatingFilterAngle(f32);
|
|||
#[derive(Component)]
|
||||
struct AbsorbingFilterColor(Color);
|
||||
|
||||
#[derive(Component)]
|
||||
struct MeltyPlatformColor(Color);
|
||||
|
||||
#[derive(Component)]
|
||||
struct Removable;
|
||||
|
||||
// Bundles
|
||||
|
||||
#[derive(Bundle)]
|
||||
|
@ -77,9 +69,6 @@ struct PlatformBundle {
|
|||
mesh: ColorMesh2dBundle,
|
||||
size: Size,
|
||||
platform: Platform,
|
||||
#[bundle]
|
||||
pickable: PickableBundle,
|
||||
removable: Removable,
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
|
@ -100,7 +89,6 @@ struct CharacterBundle {
|
|||
#[bundle]
|
||||
pickable: PickableBundle,
|
||||
draggable: Draggable,
|
||||
removable: Removable,
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
|
@ -109,9 +97,6 @@ struct AbsorbingFilterBundle {
|
|||
mesh: ColorMesh2dBundle,
|
||||
size: Size,
|
||||
color: AbsorbingFilterColor,
|
||||
#[bundle]
|
||||
pickable: PickableBundle,
|
||||
removable: Removable,
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
|
@ -122,18 +107,6 @@ 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
|
||||
|
@ -156,8 +129,6 @@ fn spawn_platform(
|
|||
},
|
||||
size: Size(size),
|
||||
platform: Platform,
|
||||
pickable: PickableBundle::default(),
|
||||
removable: Removable,
|
||||
})
|
||||
.id();
|
||||
let ends = Ends(
|
||||
|
@ -236,7 +207,6 @@ fn spawn_character(
|
|||
color: CharacterColor(color),
|
||||
pickable: PickableBundle::default(),
|
||||
draggable: Draggable,
|
||||
removable: Removable,
|
||||
})
|
||||
.with_children(|c| {
|
||||
c.spawn_bundle(Text2dBundle {
|
||||
|
@ -275,8 +245,6 @@ fn spawn_absorbing_filter(
|
|||
},
|
||||
size: Size(size),
|
||||
color: AbsorbingFilterColor(color),
|
||||
pickable: PickableBundle::default(),
|
||||
removable: Removable,
|
||||
})
|
||||
.id();
|
||||
let ends = Ends(
|
||||
|
@ -354,7 +322,6 @@ fn spawn_rotating_filter(
|
|||
angle: RotatingFilterAngle(angle),
|
||||
pickable: PickableBundle::default(),
|
||||
draggable: Draggable,
|
||||
removable: Removable,
|
||||
})
|
||||
.with_children(|c| {
|
||||
c.spawn_bundle(Text2dBundle {
|
||||
|
@ -374,52 +341,6 @@ 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>>,
|
||||
|
@ -473,17 +394,6 @@ 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(
|
||||
|
@ -498,10 +408,6 @@ 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) {
|
||||
|
@ -551,17 +457,6 @@ 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;
|
||||
}
|
||||
|
@ -623,12 +518,8 @@ fn input_control_system(
|
|||
(&Transform, &RotatingFilterAngle),
|
||||
(Without<Platform>, Without<CharacterColor>),
|
||||
>,
|
||||
melty_platform_query: Query<
|
||||
(&Transform, &MeltyPlatformColor),
|
||||
(Without<Platform>, Without<CharacterColor>),
|
||||
>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(KeyCode::S)
|
||||
if keyboard_input.just_released(KeyCode::S)
|
||||
&& (keyboard_input.pressed(KeyCode::LControl) || keyboard_input.pressed(KeyCode::RControl))
|
||||
{
|
||||
save_level(
|
||||
|
@ -640,7 +531,6 @@ fn input_control_system(
|
|||
&platform_query,
|
||||
&absorbing_filter_query,
|
||||
&rotating_filter_query,
|
||||
&melty_platform_query,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -694,96 +584,6 @@ 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)>,
|
||||
|
|
144
src/game.rs
144
src/game.rs
|
@ -13,7 +13,6 @@ use bevy::{
|
|||
};
|
||||
use bevy_rapier2d::prelude::*;
|
||||
use rapier2d::geometry::CollisionEventFlags;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
pub enum AudioMsg {
|
||||
Color([f32; 3]),
|
||||
|
@ -34,7 +33,6 @@ impl Plugin for GamePlugin {
|
|||
app.add_event::<LevelStartupEvent>()
|
||||
.init_resource::<CharacterMeshes>()
|
||||
.insert_resource(CurrentLevel(None))
|
||||
.init_resource::<CharacterList>()
|
||||
.add_system_set(SystemSet::on_enter(AppState::Game).with_system(setup))
|
||||
.add_system_set(SystemSet::on_enter(AppState::Win).with_system(win_setup))
|
||||
.add_system_set(
|
||||
|
@ -54,8 +52,7 @@ impl Plugin for GamePlugin {
|
|||
.with_system(player_movement_system)
|
||||
.with_system(level_keyboard_system)
|
||||
.with_system(move_camera)
|
||||
.with_system(character_particle_effect_system)
|
||||
.with_system(move_win_text_system),
|
||||
.with_system(character_particle_effect_system),
|
||||
)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, collision_event_system);
|
||||
}
|
||||
|
@ -69,9 +66,6 @@ pub struct LevelStartupEvent;
|
|||
|
||||
pub struct CurrentLevel(pub Option<LevelId>);
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CharacterList(pub BTreeSet<Entity>);
|
||||
|
||||
pub struct CharacterMeshes {
|
||||
square: Mesh2dHandle,
|
||||
}
|
||||
|
@ -104,12 +98,6 @@ pub struct Player;
|
|||
#[derive(Component)]
|
||||
pub struct CollisionCount(usize);
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Melty(pub Color);
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct WinText;
|
||||
|
||||
// Systems
|
||||
|
||||
fn setup(
|
||||
|
@ -130,29 +118,19 @@ pub fn spawn_characters<I: IntoIterator<Item = (Transform, Color)>>(
|
|||
character_meshes: &Res<CharacterMeshes>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
character_list: &mut ResMut<CharacterList>,
|
||||
|
||||
characters: I,
|
||||
) {
|
||||
const Z_INCREMENT: f32 = 0.01;
|
||||
let mut curr_z: f32 = Z_INCREMENT;
|
||||
|
||||
for (i, (transform, color)) in characters.into_iter().enumerate() {
|
||||
spawn_character(
|
||||
commands,
|
||||
character_meshes,
|
||||
materials,
|
||||
audio,
|
||||
character_list,
|
||||
{
|
||||
let mut new_transform: Transform = transform;
|
||||
new_transform.translation.z = curr_z;
|
||||
new_transform
|
||||
},
|
||||
transform,
|
||||
color,
|
||||
i == 0,
|
||||
);
|
||||
curr_z += Z_INCREMENT;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +139,6 @@ pub fn spawn_character(
|
|||
character_meshes: &Res<CharacterMeshes>,
|
||||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
character_list: &mut ResMut<CharacterList>,
|
||||
mut transform: Transform,
|
||||
color: Color,
|
||||
is_player: bool,
|
||||
|
@ -201,8 +178,6 @@ pub fn spawn_character(
|
|||
.insert(CollisionCount(0));
|
||||
});
|
||||
|
||||
character_list.0.insert(entity_commands.id());
|
||||
|
||||
if is_player {
|
||||
entity_commands.insert(Player);
|
||||
audio
|
||||
|
@ -242,39 +217,6 @@ 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>,
|
||||
|
@ -287,11 +229,9 @@ 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>>,
|
||||
mut character_list: ResMut<CharacterList>,
|
||||
) {
|
||||
for collision_event in collision_events.iter() {
|
||||
match collision_event {
|
||||
|
@ -302,8 +242,6 @@ fn collision_event_system(
|
|||
Ok((c2_color, c2_transform, _c2_material, c2_player)),
|
||||
) = (character_query.get(*e1), character_query.get(*e2))
|
||||
{
|
||||
character_list.0.remove(e1);
|
||||
character_list.0.remove(e2);
|
||||
commands.entity(*e1).despawn_recursive();
|
||||
commands.entity(*e2).despawn_recursive();
|
||||
|
||||
|
@ -311,7 +249,8 @@ fn collision_event_system(
|
|||
.clamp(Vec4::ZERO, Vec4::ONE);
|
||||
|
||||
// If color approximately white
|
||||
if app_state.current() == &AppState::Game && new_color.min_element() >= 0.9
|
||||
if app_state.current() == &AppState::Game
|
||||
&& 4. - new_color.length_squared() < 0.1
|
||||
{
|
||||
app_state.replace(AppState::Win).ok();
|
||||
}
|
||||
|
@ -322,7 +261,6 @@ fn collision_event_system(
|
|||
&character_meshes,
|
||||
&mut materials,
|
||||
&audio,
|
||||
&mut character_list,
|
||||
if c1_player.is_some() {
|
||||
*c1_transform
|
||||
} else if c2_player.is_some() {
|
||||
|
@ -337,18 +275,6 @@ 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)) = (
|
||||
|
@ -366,7 +292,6 @@ 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)),
|
||||
|
@ -386,7 +311,6 @@ 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),
|
||||
|
@ -426,32 +350,41 @@ fn change_character_system(
|
|||
keyboard_input: Res<Input<KeyCode>>,
|
||||
characters: Query<(Entity, &CharacterColor, Option<&Player>)>,
|
||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
character_list: Res<CharacterList>,
|
||||
) {
|
||||
if !keyboard_input.just_pressed(KeyCode::Tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some((player_entity, _color, _)) = characters
|
||||
.iter()
|
||||
.find(|(_entity, _color, player)| player.is_some())
|
||||
.or_else(|| characters.iter().next())
|
||||
{
|
||||
commands.entity(player_entity).remove::<Player>();
|
||||
if let Some(new_player_entity) = character_list
|
||||
.0
|
||||
.range(player_entity..)
|
||||
.nth(1)
|
||||
.or_else(|| character_list.0.iter().next())
|
||||
{
|
||||
commands.entity(*new_player_entity).insert(Player);
|
||||
if let Ok((_entity, color, _player)) = characters.get(*new_player_entity) {
|
||||
let mut player_idx: usize = 0;
|
||||
let mut player_count: usize = 0;
|
||||
|
||||
// find player idx
|
||||
for (_entity, _color, player) in characters.iter() {
|
||||
if player.is_some() {
|
||||
player_idx = player_count;
|
||||
}
|
||||
player_count += 1;
|
||||
}
|
||||
|
||||
// calculate next player index
|
||||
let next_player_idx = (player_idx + 1) % player_count;
|
||||
player_count = 0;
|
||||
|
||||
// exchange `Player` component from old `player_idx` to new `next_player_idx`
|
||||
for (entity, color, _player) in characters.iter() {
|
||||
if player_count == player_idx {
|
||||
commands.entity(entity).remove::<Player>();
|
||||
}
|
||||
|
||||
if player_count == next_player_idx {
|
||||
commands.entity(entity).insert(Player);
|
||||
audio
|
||||
.send(AudioMsg::Color([color.0.r(), color.0.g(), color.0.b()]))
|
||||
.ok();
|
||||
audio.send(AudioMsg::Switch).ok();
|
||||
}
|
||||
}
|
||||
|
||||
player_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -507,8 +440,7 @@ fn win_setup(
|
|||
transform: Transform::from_xyz(0., 0., 3.),
|
||||
..default()
|
||||
})
|
||||
.insert(Level)
|
||||
.insert(WinText);
|
||||
.insert(Level);
|
||||
commands
|
||||
.spawn_bundle(Text2dBundle {
|
||||
text: Text::from_section(
|
||||
|
@ -523,8 +455,7 @@ fn win_setup(
|
|||
transform: Transform::from_xyz(0., 0., 4.),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(Level)
|
||||
.insert(WinText);
|
||||
.insert(Level);
|
||||
}
|
||||
|
||||
fn move_camera(
|
||||
|
@ -553,24 +484,12 @@ fn move_camera(
|
|||
}
|
||||
}
|
||||
|
||||
fn move_win_text_system(
|
||||
camera_query: Query<&Transform, With<Camera>>,
|
||||
mut win_text_query: Query<&mut Transform, (With<WinText>, Without<Camera>)>,
|
||||
) {
|
||||
let camera_pos = camera_query.single();
|
||||
for mut pos in win_text_query.iter_mut() {
|
||||
pos.translation.x = camera_pos.translation.x;
|
||||
pos.translation.y = camera_pos.translation.y;
|
||||
}
|
||||
}
|
||||
|
||||
fn level_keyboard_system(
|
||||
mut commands: Commands,
|
||||
mut current_level: ResMut<CurrentLevel>,
|
||||
mut level_startup_event: EventWriter<LevelStartupEvent>,
|
||||
mut camera_query: Query<&mut Transform, With<Camera>>,
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut character_list: ResMut<CharacterList>,
|
||||
level_query: Query<Entity, With<Level>>,
|
||||
mut app_state: ResMut<State<AppState>>,
|
||||
) {
|
||||
|
@ -582,7 +501,6 @@ fn level_keyboard_system(
|
|||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::R) {
|
||||
character_list.0.clear();
|
||||
for entity in level_query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
|
|
|
@ -16,12 +16,7 @@ pub fn setup_level(
|
|||
level_startup_event.send(LevelStartupEvent);
|
||||
}
|
||||
|
||||
pub fn despawn_level(
|
||||
mut commands: Commands,
|
||||
mut character_list: ResMut<CharacterList>,
|
||||
level_query: Query<Entity, With<Level>>,
|
||||
) {
|
||||
character_list.0.clear();
|
||||
pub fn despawn_level(mut commands: Commands, level_query: Query<Entity, With<Level>>) {
|
||||
for entity in level_query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
|
@ -37,7 +32,6 @@ pub fn post_setup_level(
|
|||
mut level_startup_event: EventReader<LevelStartupEvent>,
|
||||
asset_server: Res<AssetServer>,
|
||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
mut character_list: ResMut<CharacterList>,
|
||||
stored_levels_assets: Res<Assets<StoredLevels>>,
|
||||
stored_levels_handle: Res<Handle<StoredLevels>>,
|
||||
) {
|
||||
|
@ -56,7 +50,6 @@ pub fn post_setup_level(
|
|||
&mut materials,
|
||||
&asset_server,
|
||||
&audio,
|
||||
&mut character_list,
|
||||
stored_level,
|
||||
);
|
||||
}
|
||||
|
@ -71,7 +64,6 @@ pub fn spawn_stored_level(
|
|||
materials: &mut ResMut<Assets<ColorMaterial>>,
|
||||
asset_server: &Res<AssetServer>,
|
||||
audio: &Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
character_list: &mut ResMut<CharacterList>,
|
||||
|
||||
stored_level: &StoredLevel,
|
||||
) {
|
||||
|
@ -92,7 +84,6 @@ pub fn spawn_stored_level(
|
|||
character_meshes,
|
||||
materials,
|
||||
audio,
|
||||
character_list,
|
||||
stored_level.characters.iter().map(|character| {
|
||||
(
|
||||
Transform::from_xyz(character.pos.x, character.pos.y, 0.),
|
||||
|
@ -118,16 +109,6 @@ 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 {
|
||||
|
@ -164,7 +145,6 @@ 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>,
|
||||
}
|
||||
|
||||
|
@ -197,13 +177,6 @@ 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 {
|
||||
|
|
|
@ -99,10 +99,7 @@ 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")),
|
||||
assets.add(asset_server.load("melty.png")),
|
||||
]);
|
||||
commands.insert_resource(assets.add(asset_server.load::<Image, _>("bevy.png")));
|
||||
commands.insert_resource(assets);
|
||||
|
||||
commands.spawn_bundle(Camera2dBundle::default());
|
||||
|
|
16
src/menu.rs
16
src/menu.rs
|
@ -20,22 +20,6 @@ impl Plugin for MenuPlugin {
|
|||
|
||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
commands
|
||||
.spawn_bundle(Text2dBundle {
|
||||
text: Text::from_section(
|
||||
"Note:\nAudio is NOT available in the WASM build.",
|
||||
TextStyle {
|
||||
font: font.clone(),
|
||||
font_size: 24.0,
|
||||
color: Color::rgba(1., 0.4, 0.4, 1.),
|
||||
},
|
||||
)
|
||||
.with_alignment(TextAlignment::CENTER),
|
||||
transform: Transform::from_xyz(0., -128.0, 0.),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(Menu);
|
||||
commands
|
||||
.spawn_bundle(Text2dBundle {
|
||||
text: Text::from_section(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bevy::{prelude::*, sprite::Mesh2dHandle};
|
||||
use rand::{rngs::ThreadRng, Rng};
|
||||
use rand::Rng;
|
||||
use rand_distr::{Distribution, UnitCircle};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
@ -68,20 +68,15 @@ pub struct ParticleComponent {
|
|||
}
|
||||
|
||||
impl ParticleComponent {
|
||||
pub fn new(rng: &mut ThreadRng) -> Self {
|
||||
pub fn new() -> Self {
|
||||
let mut particle_component: Self = Self::default();
|
||||
particle_component.randomize_velocity(rng, MIN_VELOCITY, MAX_VELOCITY);
|
||||
particle_component.randomize_velocity(MIN_VELOCITY, MAX_VELOCITY);
|
||||
particle_component
|
||||
}
|
||||
|
||||
pub fn randomize_velocity(
|
||||
&mut self,
|
||||
rng: &mut ThreadRng,
|
||||
min_velocity: f32,
|
||||
max_velocity: f32,
|
||||
) {
|
||||
let random_direction: [f32; 2] = UnitCircle.sample(rng);
|
||||
let random_magnitude: f32 = rng.gen_range(min_velocity..max_velocity);
|
||||
pub fn randomize_velocity(&mut self, min_velocity: f32, max_velocity: f32) {
|
||||
let random_direction: [f32; 2] = UnitCircle.sample(&mut rand::thread_rng());
|
||||
let random_magnitude: f32 = rand::thread_rng().gen_range(min_velocity..max_velocity);
|
||||
self.velocity = Vec3::new(random_direction[0], random_direction[1], 0.0) * random_magnitude;
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +87,6 @@ fn particle_effect_startup(
|
|||
particle_mesh: Res<ParticleMesh>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _p in 0..POOL_COUNT {
|
||||
let color_mesh = ColorMesh2dBundle {
|
||||
mesh: particle_mesh.square.clone(),
|
||||
|
@ -103,7 +96,7 @@ fn particle_effect_startup(
|
|||
|
||||
commands
|
||||
.spawn_bundle(color_mesh)
|
||||
.insert(ParticleComponent::new(&mut rng));
|
||||
.insert(ParticleComponent::new());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,8 +110,6 @@ fn particle_effect_system(
|
|||
mut particle_effect: ResMut<ParticleEffectResource>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let delta_seconds: f32 = f32::max(0.001, time.delta_seconds());
|
||||
let delta_position: Vec3 = particle_effect.translation - particle_effect.prev_translation;
|
||||
// let overall_velocity: Vec3 = delta_position / delta_seconds;
|
||||
|
@ -133,7 +124,7 @@ fn particle_effect_system(
|
|||
.distance_squared(particle_effect.translation);
|
||||
if squared_distance > particle_effect.radius_squared {
|
||||
transform.translation = particle_effect.translation;
|
||||
particle_component.randomize_velocity(&mut rng, MIN_VELOCITY, MAX_VELOCITY);
|
||||
particle_component.randomize_velocity(MIN_VELOCITY, MAX_VELOCITY);
|
||||
}
|
||||
|
||||
if let Some(material) = materials.get_mut(color_material) {
|
||||
|
@ -143,6 +134,5 @@ fn particle_effect_system(
|
|||
/ particle_effect.radius_squared,
|
||||
);
|
||||
}
|
||||
transform.translation.z = 0.005;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue