use crate::movement::YSortable; use crate::prelude::*; #[derive(Component, Debug, Default)] pub struct Statue; #[derive(Bundle, Default)] pub struct StatueBundle { gameobject: Gameobject, statue: Statue, ysort: YSortable, sprite: SpriteBundle, texture: TextureAtlas, } pub fn startup(mut events: EventWriter) { events.send_batch([ SpawnStatueEvent(Vec3::new(50., 50., 0.)), SpawnStatueEvent(Vec3::new(50., 100., 0.)), ]); } #[derive(Event)] pub struct SpawnStatueEvent(Vec3); pub fn spawn_statue( mut events: EventReader, mut commands: Commands, assets: Res, mut layouts: ResMut>, ) { // TODO: rebuilding this layout each spawn is surely not correct? let layout = layouts.add(TextureAtlasLayout::from_grid( UVec2::new(40, 74), 1, 1, None, Some(UVec2::new(443, 20)), )); for ev in events.read() { let bundle = StatueBundle { sprite: SpriteBundle { transform: Transform::from_translation(ev.0), texture: assets.load("img/Props.png"), ..default() }, texture: TextureAtlas { layout: layout.clone(), ..default() }, ..default() }; commands.spawn(bundle); } } pub fn exit(mut commands: Commands, q: Query>) { for id in q.iter() { commands.entity(id).despawn_recursive(); } }