use bevy::prelude::*; use bevy_ecs_tilemap::prelude::*; use rand::{thread_rng, Rng}; mod helpers; fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); let texture_handle: Handle = asset_server.load("tiles.png"); let map_size = TilemapSize { x: 32, y: 32 }; let mut tile_storage = TileStorage::empty(map_size); let tilemap_entity = commands.spawn_empty().id(); for x in 0..32u32 { for y in 0..32u32 { let tile_pos = TilePos { x, y }; let tile_entity = commands .spawn(TileBundle { position: tile_pos, tilemap_id: TilemapId(tilemap_entity), ..Default::default() }) .id(); tile_storage.set(&tile_pos, tile_entity); } } let tile_size = TilemapTileSize { x: 16.0, y: 16.0 }; let grid_size = tile_size.into(); let map_type = TilemapType::default(); commands.entity(tilemap_entity).insert(( TilemapBundle { grid_size, map_type, size: map_size, storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, LastUpdate::default(), )); } #[derive(Default, Component)] struct LastUpdate { value: f64, } fn remove_tiles( mut commands: Commands, time: Res