Add base tilemap layer with specific tile regions
This commit is contained in:
48
src/main.rs
48
src/main.rs
@@ -11,8 +11,10 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
let base_texture_handle: Handle<Image> = asset_server.load("base_field.png");
|
let base_texture_handle: Handle<Image> = asset_server.load("base_field.png");
|
||||||
|
|
||||||
let tilemap_entity = commands.spawn_empty().id();
|
let tilemap_entity = commands.spawn_empty().id();
|
||||||
|
let base_tilemap_entity = commands.spawn_empty().id();
|
||||||
|
|
||||||
let mut tile_storage = TileStorage::empty(MAP_SIZE);
|
let mut tile_storage = TileStorage::empty(MAP_SIZE);
|
||||||
|
let mut base_tile_storage = TileStorage::empty(MAP_SIZE);
|
||||||
|
|
||||||
for x in 0..MAP_SIZE.x {
|
for x in 0..MAP_SIZE.x {
|
||||||
for y in 0..MAP_SIZE.y {
|
for y in 0..MAP_SIZE.y {
|
||||||
@@ -28,6 +30,38 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for x in 0..5 {
|
||||||
|
for y in 10..15 {
|
||||||
|
if x < MAP_SIZE.x && y < MAP_SIZE.y {
|
||||||
|
let tile_pos = TilePos { x, y };
|
||||||
|
let tile_entity = commands
|
||||||
|
.spawn(TileBundle {
|
||||||
|
position: tile_pos,
|
||||||
|
tilemap_id: TilemapId(base_tilemap_entity),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.id();
|
||||||
|
base_tile_storage.set(&tile_pos, tile_entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for x in 45..50 {
|
||||||
|
for y in 10..15 {
|
||||||
|
if x < MAP_SIZE.x && y < MAP_SIZE.y {
|
||||||
|
let tile_pos = TilePos { x, y };
|
||||||
|
let tile_entity = commands
|
||||||
|
.spawn(TileBundle {
|
||||||
|
position: tile_pos,
|
||||||
|
tilemap_id: TilemapId(base_tilemap_entity),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.id();
|
||||||
|
base_tile_storage.set(&tile_pos, tile_entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commands.entity(tilemap_entity).insert(TilemapBundle {
|
commands.entity(tilemap_entity).insert(TilemapBundle {
|
||||||
grid_size: TILE_SIZE.into(),
|
grid_size: TILE_SIZE.into(),
|
||||||
map_type: TilemapType::default(),
|
map_type: TilemapType::default(),
|
||||||
@@ -36,6 +70,19 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
texture: TilemapTexture::Single(dirt_texture_handle),
|
texture: TilemapTexture::Single(dirt_texture_handle),
|
||||||
tile_size: TILE_SIZE,
|
tile_size: TILE_SIZE,
|
||||||
anchor: TilemapAnchor::Center,
|
anchor: TilemapAnchor::Center,
|
||||||
|
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.entity(base_tilemap_entity).insert(TilemapBundle {
|
||||||
|
grid_size: TILE_SIZE.into(),
|
||||||
|
map_type: TilemapType::default(),
|
||||||
|
size: MAP_SIZE,
|
||||||
|
storage: base_tile_storage,
|
||||||
|
texture: TilemapTexture::Single(base_texture_handle),
|
||||||
|
tile_size: TILE_SIZE,
|
||||||
|
anchor: TilemapAnchor::Center,
|
||||||
|
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -57,6 +104,5 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.add_plugins(TilemapPlugin)
|
.add_plugins(TilemapPlugin)
|
||||||
.add_systems(Startup, startup)
|
.add_systems(Startup, startup)
|
||||||
// .add_systems(Update, helpers::camera::movement)
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user