Compare commits
2 commits
91d24e3bf4
...
6809a30faa
Author | SHA1 | Date | |
---|---|---|---|
6809a30faa | |||
15960e7f80 |
4 changed files with 52 additions and 48 deletions
|
@ -7,7 +7,6 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.8.0"
|
bevy = "0.8.0"
|
||||||
# bevy_hanabi = "0.3.1"
|
|
||||||
bevy-inspector-egui = "0.12.1"
|
bevy-inspector-egui = "0.12.1"
|
||||||
bevy_rapier2d = "0.16.2"
|
bevy_rapier2d = "0.16.2"
|
||||||
cpal = "0.14.0"
|
cpal = "0.14.0"
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
* level design
|
* level design
|
||||||
* (?) can jump only from a surface (no mid-air jump)
|
* (?) can jump only from a surface (no mid-air jump)
|
||||||
* (?) multiplayer
|
* (?) multiplayer
|
||||||
* make WASM build work again (replace hanabi)
|
|
||||||
* level reset
|
* level reset
|
||||||
* more audio
|
* more audio
|
||||||
|
|
||||||
|
@ -25,8 +24,6 @@ cargo build --release
|
||||||
|
|
||||||
### WASM
|
### WASM
|
||||||
|
|
||||||
Currently `bevy_hanabi` does not compile for WASM, and audio does not work on WASM.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
rustup target add wasm32-unknown-unknown
|
rustup target add wasm32-unknown-unknown
|
||||||
cargo install wasm-bindgen-cli
|
cargo install wasm-bindgen-cli
|
||||||
|
|
20
src/game.rs
20
src/game.rs
|
@ -32,13 +32,14 @@ impl Plugin for GamePlugin {
|
||||||
SystemSet::on_update(AppState::Game)
|
SystemSet::on_update(AppState::Game)
|
||||||
.with_system(crate::levels::post_setup_level)
|
.with_system(crate::levels::post_setup_level)
|
||||||
.with_system(keyboard_input_system)
|
.with_system(keyboard_input_system)
|
||||||
.with_system(character_particle_effect_system)
|
.with_system(move_camera)
|
||||||
.with_system(move_camera),
|
.with_system(character_particle_effect_system),
|
||||||
)
|
)
|
||||||
.add_system_set(
|
.add_system_set(
|
||||||
SystemSet::on_update(AppState::Win)
|
SystemSet::on_update(AppState::Win)
|
||||||
.with_system(keyboard_input_system)
|
.with_system(keyboard_input_system)
|
||||||
.with_system(move_camera),
|
.with_system(move_camera)
|
||||||
|
.with_system(character_particle_effect_system),
|
||||||
)
|
)
|
||||||
.add_system_to_stage(CoreStage::PostUpdate, collision_event_system);
|
.add_system_to_stage(CoreStage::PostUpdate, collision_event_system);
|
||||||
}
|
}
|
||||||
|
@ -219,7 +220,6 @@ fn keyboard_input_system(
|
||||||
if let Ok((mut selected_character_id, character_id_list)) = level_query.get_single_mut() {
|
if let Ok((mut selected_character_id, character_id_list)) = level_query.get_single_mut() {
|
||||||
if keyboard_input.just_pressed(KeyCode::Tab) {
|
if keyboard_input.just_pressed(KeyCode::Tab) {
|
||||||
let selected = if let Some(selected_character_id) = &mut selected_character_id.0 {
|
let selected = if let Some(selected_character_id) = &mut selected_character_id.0 {
|
||||||
|
|
||||||
*selected_character_id = *character_id_list
|
*selected_character_id = *character_id_list
|
||||||
.0
|
.0
|
||||||
.range(*selected_character_id..)
|
.range(*selected_character_id..)
|
||||||
|
@ -249,9 +249,8 @@ fn keyboard_input_system(
|
||||||
if let Some(selected_character_id) = &selected_character_id.0 {
|
if let Some(selected_character_id) = &selected_character_id.0 {
|
||||||
if let Some((_character_id, mut velocity, _color)) = characters
|
if let Some((_character_id, mut velocity, _color)) = characters
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|(character_id, _velocity, _color)| {
|
.find(|(character_id, _velocity, _color)| *character_id == selected_character_id)
|
||||||
*character_id == selected_character_id
|
{
|
||||||
}) {
|
|
||||||
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
||||||
|
|
||||||
if keyboard_input.just_pressed(KeyCode::Space) {
|
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||||
|
@ -270,15 +269,14 @@ fn keyboard_input_system(
|
||||||
fn character_particle_effect_system(
|
fn character_particle_effect_system(
|
||||||
mut characters: Query<(&CharacterId, &Transform, &CharacterColor)>,
|
mut characters: Query<(&CharacterId, &Transform, &CharacterColor)>,
|
||||||
mut particle_effect: ResMut<crate::particle_effect::ParticleEffectResource>,
|
mut particle_effect: ResMut<crate::particle_effect::ParticleEffectResource>,
|
||||||
mut level_query: Query<(&SelectedCharacterId)>,
|
mut level_query: Query<&SelectedCharacterId>,
|
||||||
) {
|
) {
|
||||||
if let Ok(selected_character_id) = level_query.get_single_mut() {
|
if let Ok(selected_character_id) = level_query.get_single_mut() {
|
||||||
if let Some(selected_character_id) = &selected_character_id.0 {
|
if let Some(selected_character_id) = &selected_character_id.0 {
|
||||||
if let Some((_character_id, transform, color)) = characters
|
if let Some((_character_id, transform, color)) = characters
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|(character_id, _transform, _color)| {
|
.find(|(character_id, _transform, _color)| *character_id == selected_character_id)
|
||||||
*character_id == selected_character_id
|
{
|
||||||
}) {
|
|
||||||
particle_effect.translation = transform.translation;
|
particle_effect.translation = transform.translation;
|
||||||
particle_effect.color = color.0;
|
particle_effect.color = color.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
use bevy::{prelude::*, sprite::Mesh2dHandle};
|
use bevy::{prelude::*, sprite::Mesh2dHandle};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand_distr::{UnitCircle, Distribution};
|
use rand_distr::{Distribution, UnitCircle};
|
||||||
|
|
||||||
pub const POOL_COUNT: usize = 100;
|
pub const POOL_COUNT: usize = 100;
|
||||||
|
|
||||||
pub const MIN_VELOCITY: f32 = 10.0;
|
pub const MIN_VELOCITY: f32 = 10.0;
|
||||||
pub const MAX_VELOCITY: f32 = 100.0;
|
pub const MAX_VELOCITY: f32 = 100.0;
|
||||||
pub const VELOCITY_SCALE: f32 = 0.1;
|
pub const _VELOCITY_SCALE: f32 = 0.1;
|
||||||
pub const PARTICLE_EFFECT_RADIUS: f32 = 70.0;
|
pub const PARTICLE_EFFECT_RADIUS: f32 = 70.0;
|
||||||
|
|
||||||
pub struct ParticleEffectPlugin;
|
pub struct ParticleEffectPlugin;
|
||||||
|
|
||||||
impl Plugin for ParticleEffectPlugin {
|
impl Plugin for ParticleEffectPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app
|
app.init_resource::<ParticleMesh>()
|
||||||
.init_resource::<ParticleMesh>()
|
.insert_resource(ParticleEffectResource::new(Vec3::new(
|
||||||
.insert_resource(ParticleEffectResource::new(Vec3::new(10000.0, 10000.0, 0.0)))
|
10000.0, 10000.0, 0.0,
|
||||||
|
)))
|
||||||
.add_startup_system(particle_effect_startup)
|
.add_startup_system(particle_effect_startup)
|
||||||
.add_system(particle_effect_system);
|
.add_system(particle_effect_system);
|
||||||
}
|
}
|
||||||
|
@ -68,12 +69,12 @@ impl ParticleComponent {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut particle_component: Self = Self::default();
|
let mut particle_component: Self = Self::default();
|
||||||
particle_component.randomize_velocity(MIN_VELOCITY, MAX_VELOCITY);
|
particle_component.randomize_velocity(MIN_VELOCITY, MAX_VELOCITY);
|
||||||
return particle_component;
|
particle_component
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn randomize_velocity(&mut self, min_velocity: f32, max_velocity: f32) {
|
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_direction: [f32; 2] = UnitCircle.sample(&mut rand::thread_rng());
|
||||||
let random_magnitude: f32 = rand::thread_rng().gen_range(min_velocity .. max_velocity);
|
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;
|
self.velocity = Vec3::new(random_direction[0], random_direction[1], 0.0) * random_magnitude;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ fn particle_effect_startup(
|
||||||
particle_mesh: Res<ParticleMesh>,
|
particle_mesh: Res<ParticleMesh>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
) {
|
) {
|
||||||
for _p in 0 .. POOL_COUNT {
|
for _p in 0..POOL_COUNT {
|
||||||
let color_mesh = ColorMesh2dBundle {
|
let color_mesh = ColorMesh2dBundle {
|
||||||
mesh: particle_mesh.square.clone(),
|
mesh: particle_mesh.square.clone(),
|
||||||
material: materials.add(ColorMaterial::from(Color::WHITE)),
|
material: materials.add(ColorMaterial::from(Color::WHITE)),
|
||||||
|
@ -99,7 +100,11 @@ fn particle_effect_startup(
|
||||||
|
|
||||||
fn particle_effect_system(
|
fn particle_effect_system(
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
mut query: Query<(&mut Transform, &mut ParticleComponent, &Handle<ColorMaterial>)>,
|
mut query: Query<(
|
||||||
|
&mut Transform,
|
||||||
|
&mut ParticleComponent,
|
||||||
|
&Handle<ColorMaterial>,
|
||||||
|
)>,
|
||||||
mut particle_effect: ResMut<ParticleEffectResource>,
|
mut particle_effect: ResMut<ParticleEffectResource>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
|
@ -112,7 +117,9 @@ fn particle_effect_system(
|
||||||
// particle_component.velocity -= overall_velocity * VELOCITY_SCALE;
|
// particle_component.velocity -= overall_velocity * VELOCITY_SCALE;
|
||||||
transform.translation += particle_component.velocity * delta_seconds + delta_position;
|
transform.translation += particle_component.velocity * delta_seconds + delta_position;
|
||||||
|
|
||||||
let squared_distance: f32 = transform.translation.distance_squared(particle_effect.translation);
|
let squared_distance: f32 = transform
|
||||||
|
.translation
|
||||||
|
.distance_squared(particle_effect.translation);
|
||||||
if squared_distance > particle_effect.radius_squared {
|
if squared_distance > particle_effect.radius_squared {
|
||||||
transform.translation = particle_effect.translation;
|
transform.translation = particle_effect.translation;
|
||||||
particle_component.randomize_velocity(MIN_VELOCITY, MAX_VELOCITY);
|
particle_component.randomize_velocity(MIN_VELOCITY, MAX_VELOCITY);
|
||||||
|
@ -120,7 +127,10 @@ fn particle_effect_system(
|
||||||
|
|
||||||
if let Some(material) = materials.get_mut(color_material) {
|
if let Some(material) = materials.get_mut(color_material) {
|
||||||
material.color = particle_effect.color;
|
material.color = particle_effect.color;
|
||||||
material.color.set_a((particle_effect.radius_squared - squared_distance) / particle_effect.radius_squared);
|
material.color.set_a(
|
||||||
|
(particle_effect.radius_squared - squared_distance)
|
||||||
|
/ particle_effect.radius_squared,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue