Rename crate::events to crate::messages
Bevy 0.17 introduces this idea of "Messages" which mostly replace the previous usage of "Events." The old events still exist, but are meant more for targetted actions -- something happening and immediately triggering a function call on an observer.
This commit is contained in:
10
src/lib.rs
10
src/lib.rs
@@ -3,7 +3,7 @@
|
||||
//! Compile-time configurables can be found in the [`config`] module.
|
||||
|
||||
pub mod config;
|
||||
mod events;
|
||||
mod messages;
|
||||
mod machinery;
|
||||
mod objects;
|
||||
mod physics;
|
||||
@@ -77,10 +77,10 @@ impl Plugin for AsteroidPlugin {
|
||||
)
|
||||
.run_if(in_state(GameState::Playing)),
|
||||
)
|
||||
.add_event::<events::SpawnAsteroid>()
|
||||
.add_event::<events::AsteroidDestroy>()
|
||||
.add_event::<events::ShipDestroy>()
|
||||
.add_event::<events::BulletDestroy>();
|
||||
.add_event::<messages::SpawnAsteroid>()
|
||||
.add_event::<messages::AsteroidDestroy>()
|
||||
.add_event::<messages::ShipDestroy>()
|
||||
.add_event::<messages::BulletDestroy>();
|
||||
app.insert_state(GameState::TitleScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{WorldSize, events::{AsteroidDestroy, SpawnAsteroid}, objects::AsteroidSize, resources::Score};
|
||||
use crate::{WorldSize, messages::{AsteroidDestroy, SpawnAsteroid}, objects::AsteroidSize, resources::Score};
|
||||
|
||||
/// Asteroid spawning parameters and state.
|
||||
///
|
||||
|
||||
@@ -23,7 +23,7 @@ use bevy_rapier2d::prelude::{ActiveCollisionTypes, ActiveEvents, Collider, Senso
|
||||
use crate::{
|
||||
AngularVelocity, GameAssets, GameState, Lives,
|
||||
config::{ASTEROID_LIFETIME, DEBRIS_LIFETIME, SHIP_FIRE_RATE},
|
||||
events::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid},
|
||||
messages::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid},
|
||||
machinery::{Lifetime, Sparkler},
|
||||
physics::{Velocity, Wrapping},
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
//! to detect them for me (so that I don't have to write clipping code).
|
||||
|
||||
use crate::{
|
||||
WorldSize, events,
|
||||
WorldSize, messages,
|
||||
objects::{Asteroid, Bullet, Ship},
|
||||
};
|
||||
|
||||
@@ -90,9 +90,9 @@ pub(crate) fn wrap_entities(
|
||||
/// | Bullet & Ship | Nothing. The player shouldn't be able to shoot themselves (and the Flying Saucer hasn't been impl.'d, so it's bullets don't count) |
|
||||
pub fn collision_listener(
|
||||
mut collisions: EventReader<CollisionEvent>,
|
||||
mut ship_writer: EventWriter<events::ShipDestroy>,
|
||||
mut asteroid_writer: EventWriter<events::AsteroidDestroy>,
|
||||
mut bullet_writer: EventWriter<events::BulletDestroy>,
|
||||
mut ship_writer: EventWriter<messages::ShipDestroy>,
|
||||
mut asteroid_writer: EventWriter<messages::AsteroidDestroy>,
|
||||
mut bullet_writer: EventWriter<messages::BulletDestroy>,
|
||||
player: Single<Entity, With<Ship>>,
|
||||
bullets: Query<&Bullet>,
|
||||
rocks: Query<&Asteroid>,
|
||||
@@ -112,12 +112,12 @@ pub fn collision_listener(
|
||||
if rocks.contains(*two) {
|
||||
// player-asteroid collision
|
||||
dbg!("Writing ShipDestroy event");
|
||||
ship_writer.write(events::ShipDestroy);
|
||||
ship_writer.write(messages::ShipDestroy);
|
||||
} // else, we don't care
|
||||
} else if *two == *player {
|
||||
if rocks.contains(*one) {
|
||||
dbg!("Writing ShipDestroy event");
|
||||
ship_writer.write(events::ShipDestroy);
|
||||
ship_writer.write(messages::ShipDestroy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,14 +125,14 @@ pub fn collision_listener(
|
||||
if bullets.contains(*one) {
|
||||
if rocks.contains(*two) {
|
||||
dbg!("Writing AsteroidDestroy & BulletDestroy events");
|
||||
asteroid_writer.write(events::AsteroidDestroy(*two));
|
||||
bullet_writer.write(events::BulletDestroy(*one));
|
||||
asteroid_writer.write(messages::AsteroidDestroy(*two));
|
||||
bullet_writer.write(messages::BulletDestroy(*one));
|
||||
}
|
||||
} else if rocks.contains(*one) {
|
||||
if bullets.contains(*two) {
|
||||
dbg!("Writing AsteroidDestroy & BulletDestroy events");
|
||||
asteroid_writer.write(events::AsteroidDestroy(*one));
|
||||
bullet_writer.write(events::BulletDestroy(*two));
|
||||
asteroid_writer.write(messages::AsteroidDestroy(*one));
|
||||
bullet_writer.write(messages::BulletDestroy(*two));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user