generated from tipragot/rust
Adding a map creation plugin #57
|
@ -11,7 +11,7 @@ pub struct MapGenerationPlugin;
|
||||||
|
|
||||||
impl Plugin for MapGenerationPlugin {
|
impl Plugin for MapGenerationPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_event::<MapGeneration>()
|
app.add_event::<StartMapGeneration>()
|
||||||
.add_event::<EndMapGeneration>()
|
.add_event::<EndMapGeneration>()
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
|
@ -23,7 +23,7 @@ impl Plugin for MapGenerationPlugin {
|
||||||
|
|
||||||
/// An event to trigger the generation of the map.
|
/// An event to trigger the generation of the map.
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
pub struct MapGeneration {
|
pub struct StartMapGeneration {
|
||||||
/// The seed used to generate the map.
|
/// The seed used to generate the map.
|
||||||
pub seed: u32,
|
pub seed: u32,
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ pub struct EndMapGeneration;
|
||||||
|
|
||||||
/// Spawns the tiles if the event is received.
|
/// Spawns the tiles if the event is received.
|
||||||
fn generate_map(
|
fn generate_map(
|
||||||
mut event: EventReader<MapGeneration>,
|
mut event: EventReader<StartMapGeneration>,
|
||||||
mut end_map_event: EventWriter<EndMapGeneration>,
|
mut end_map_event: EventWriter<EndMapGeneration>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut noise: Local<Option<Perlin>>,
|
mut noise: Local<Option<Perlin>>,
|
||||||
|
@ -75,7 +75,7 @@ fn get_type_tile(position: (f32, f32), noise: &Perlin) -> Tile {
|
||||||
fn delete_map(
|
fn delete_map(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
query: Query<Entity, With<Tile>>,
|
query: Query<Entity, With<Tile>>,
|
||||||
mut event: EventReader<MapGeneration>,
|
mut event: EventReader<StartMapGeneration>,
|
||||||
) {
|
) {
|
||||||
for _ in event.read() {
|
for _ in event.read() {
|
||||||
for entity in query.iter() {
|
for entity in query.iter() {
|
||||||
|
|
Loading…
Reference in a new issue