use player spawn oneshot
This commit is contained in:
parent
1a0100b596
commit
dea1bdcf03
3 changed files with 12 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_rapier2d::prelude::*;
|
||||
use player::player_plugin;
|
||||
use scene::{scene_plugin, PlayerSpawnEvent};
|
||||
use scene::{scene_plugin, PlayerCoords};
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
|
@ -10,9 +10,8 @@ mod scene;
|
|||
mod set;
|
||||
|
||||
pub const WORLD_DEPTH: f32 = 0.5;
|
||||
pub const PLAYER_DEPTH: f32 = 0.5;
|
||||
|
||||
pub fn game_plugin(app: &mut App) {
|
||||
(app)
|
||||
.add_event::<PlayerSpawnEvent>()
|
||||
.add_plugins((player_plugin, scene_plugin));
|
||||
app.add_plugins((player_plugin, scene_plugin));
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ mod animation;
|
|||
struct Player;
|
||||
|
||||
#[derive(Resource)]
|
||||
struct PlayerSpawnOneshot(SystemId);
|
||||
pub struct PlayerSpawnOneshot(pub SystemId);
|
||||
|
||||
impl FromWorld for PlayerSpawnOneshot {
|
||||
fn from_world(world: &mut World) -> Self {
|
||||
|
|
|
@ -11,11 +11,13 @@ use readformat::{readf, readf1};
|
|||
use crate::game::WORLD_DEPTH;
|
||||
use crate::AppState;
|
||||
|
||||
use super::player::PlayerSpawnOneshot;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Block;
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct PlayerSpawnEvent {
|
||||
#[derive(Resource, Default)]
|
||||
pub struct PlayerCoords {
|
||||
x: f32,
|
||||
y: f32,
|
||||
block_size: f32,
|
||||
|
@ -38,6 +40,7 @@ pub(super) fn import_text_world(
|
|||
assets: Res<AssetServer>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
mut player_spawn_oneshot: Res<PlayerSpawnOneshot>,
|
||||
) {
|
||||
let world_string = fs::read_to_string("assets/world.txt").expect("need a world to load");
|
||||
let [info_string, world_string] = &readf("info section\n{}\nworld section\n{}", &world_string)
|
||||
|
@ -84,11 +87,12 @@ pub(super) fn import_text_world(
|
|||
let x = i as f32 * wi.block_size;
|
||||
let y = current_y as f32 * wi.block_size;
|
||||
if tex == "[player]" {
|
||||
commands.trigger(PlayerSpawnEvent {
|
||||
commands.insert_resource(PlayerCoords {
|
||||
x,
|
||||
y,
|
||||
block_size: wi.block_size,
|
||||
})
|
||||
});
|
||||
commands.run_system(player_spawn_oneshot.0);
|
||||
} else {
|
||||
spawn_block(
|
||||
&mut commands,
|
||||
|
|
Loading…
Add table
Reference in a new issue