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::prelude::*;
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
use player::player_plugin;
|
use player::player_plugin;
|
||||||
use scene::{scene_plugin, PlayerSpawnEvent};
|
use scene::{scene_plugin, PlayerCoords};
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
|
@ -10,9 +10,8 @@ mod scene;
|
||||||
mod set;
|
mod set;
|
||||||
|
|
||||||
pub const WORLD_DEPTH: f32 = 0.5;
|
pub const WORLD_DEPTH: f32 = 0.5;
|
||||||
|
pub const PLAYER_DEPTH: f32 = 0.5;
|
||||||
|
|
||||||
pub fn game_plugin(app: &mut App) {
|
pub fn game_plugin(app: &mut App) {
|
||||||
(app)
|
app.add_plugins((player_plugin, scene_plugin));
|
||||||
.add_event::<PlayerSpawnEvent>()
|
|
||||||
.add_plugins((player_plugin, scene_plugin));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ mod animation;
|
||||||
struct Player;
|
struct Player;
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct PlayerSpawnOneshot(SystemId);
|
pub struct PlayerSpawnOneshot(pub SystemId);
|
||||||
|
|
||||||
impl FromWorld for PlayerSpawnOneshot {
|
impl FromWorld for PlayerSpawnOneshot {
|
||||||
fn from_world(world: &mut World) -> Self {
|
fn from_world(world: &mut World) -> Self {
|
||||||
|
|
|
@ -11,11 +11,13 @@ use readformat::{readf, readf1};
|
||||||
use crate::game::WORLD_DEPTH;
|
use crate::game::WORLD_DEPTH;
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
|
use super::player::PlayerSpawnOneshot;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Block;
|
struct Block;
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Resource, Default)]
|
||||||
pub struct PlayerSpawnEvent {
|
pub struct PlayerCoords {
|
||||||
x: f32,
|
x: f32,
|
||||||
y: f32,
|
y: f32,
|
||||||
block_size: f32,
|
block_size: f32,
|
||||||
|
@ -38,6 +40,7 @@ pub(super) fn import_text_world(
|
||||||
assets: Res<AssetServer>,
|
assets: Res<AssetServer>,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
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 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)
|
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 x = i as f32 * wi.block_size;
|
||||||
let y = current_y as f32 * wi.block_size;
|
let y = current_y as f32 * wi.block_size;
|
||||||
if tex == "[player]" {
|
if tex == "[player]" {
|
||||||
commands.trigger(PlayerSpawnEvent {
|
commands.insert_resource(PlayerCoords {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
block_size: wi.block_size,
|
block_size: wi.block_size,
|
||||||
})
|
});
|
||||||
|
commands.run_system(player_spawn_oneshot.0);
|
||||||
} else {
|
} else {
|
||||||
spawn_block(
|
spawn_block(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
|
|
Loading…
Add table
Reference in a new issue