Skip to content

Commit

Permalink
Fix map loading
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepryde committed Jul 28, 2024
1 parent e9b398e commit 2f04c7a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "dizzy-ducklings"
authors = ["Steve Pryde <[email protected]>"]
version = "0.3.3"
version = "0.3.4"
edition = "2021"


[dependencies]
bevy = { version = "0.14", features = ["wayland"] }
bevy_ecs_tiled = { version = "=0.3.1", features = ["rapier"] }
bevy_ecs_tiled = { version = "0.3.2", path="../../support/bevy_ecs_tiled", features = ["rapier"] }
bevy_ecs_tilemap = "0.14"
bevy_rapier2d = "0.27"

Expand All @@ -23,7 +23,7 @@ rand = "0.8"

[target.'cfg(target_family = "wasm")'.dependencies]
bevy_rapier2d = {version = "0.27.0", features = ["wasm-bindgen"]}
bevy_ecs_tiled = { version = "0.3.1", features = ["rapier"] }
bevy_ecs_tiled = { version = "0.3.2", path="../../support/bevy_ecs_tiled", features = ["rapier"] }

[features]
default = [
Expand Down
31 changes: 28 additions & 3 deletions src/game/spawn/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(super) fn plugin(app: &mut App) {
app.observe(cleanup_level);
app.observe(on_end_level);
app.observe(on_game_completed);
app.add_systems(Update, on_level_added.run_if(in_state(Screen::Playing)));
app.add_systems(Update, on_fade_completed.run_if(in_state(Screen::Playing)));
app.add_systems(OnExit(Screen::Playing), exit_playing);
}
Expand Down Expand Up @@ -95,6 +96,9 @@ fn start_new_game(_trigger: Trigger<StartNewGame>, mut commands: Commands) {
#[derive(Event, Debug)]
pub struct SpawnLevel;

#[derive(Component, Debug)]
pub struct LevelLoaded;

#[derive(Component)]
pub struct LevelMarker;

Expand Down Expand Up @@ -161,12 +165,33 @@ fn spawn_level(
}
});

commands.trigger(ResetFrameCounter);
commands.trigger(SpawnPlayer);
commands.trigger(SpawnDuckling);
log::warn!("SPAWNED LEVEL");

// commands.trigger(ResetFrameCounter);
commands.trigger(UpdateScore);
}

fn on_level_added(
mut events: EventReader<AssetEvent<TiledMap>>,
mut commands: Commands,
map: Query<(Entity, &Handle<TiledMap>), Without<LevelLoaded>>,
) {
for event in events.read() {
if let AssetEvent::LoadedWithDependencies { id } = event {
for (entity, handle) in map.iter() {
if handle.id() == *id {
log::warn!("MAP LOADED");
commands.entity(entity).insert(LevelLoaded);
commands.trigger(SpawnPlayer);
commands.trigger(SpawnDuckling);
commands.trigger(ResetFrameCounter);
return;
}
}
}
}
}

#[derive(Component, Debug, Clone, Copy, PartialEq, Default, Reflect)]
pub struct PlayerSpawnPoint;

Expand Down

0 comments on commit 2f04c7a

Please sign in to comment.