diff --git a/Cargo.lock b/Cargo.lock index 4f2cb35..5dabe05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -644,6 +644,16 @@ dependencies = [ "syn", ] +[[package]] +name = "bevy_ecs_tilemap" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7176ff40586face39666fab2c3692c62bd5de67987164e6d8b316bc19e27d7" +dependencies = [ + "bevy", + "log", +] + [[package]] name = "bevy_encase_derive" version = "0.17.2" @@ -4556,6 +4566,7 @@ name = "war-in-tunnels" version = "0.1.0" dependencies = [ "bevy", + "bevy_ecs_tilemap", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 38738e9..b746b02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] bevy = "0.17.2" +bevy_ecs_tilemap = "0.17.0" [profile.dev] opt-level = 1 diff --git a/assets/.gitkeep b/assets/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/assets/base_field.png b/assets/base_field.png new file mode 100644 index 0000000..c626e9f Binary files /dev/null and b/assets/base_field.png differ diff --git a/assets/dirt_field.png b/assets/dirt_field.png new file mode 100644 index 0000000..7b45977 Binary files /dev/null and b/assets/dirt_field.png differ diff --git a/src/main.rs b/src/main.rs index e7a11a9..33151bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,62 @@ -fn main() { - println!("Hello, world!"); +use bevy::{prelude::*, window::WindowResolution}; +use bevy_ecs_tilemap::prelude::*; + +const MAP_SIZE: TilemapSize = TilemapSize { x: 50, y: 25 }; +const TILE_SIZE: TilemapTileSize = TilemapTileSize { x: 25.0, y: 25.0 }; + +fn startup(mut commands: Commands, asset_server: Res) { + commands.spawn(Camera2d); + + let dirt_texture_handle: Handle = asset_server.load("dirt_field.png"); + let base_texture_handle: Handle = asset_server.load("base_field.png"); + + let tilemap_entity = commands.spawn_empty().id(); + + let mut tile_storage = TileStorage::empty(MAP_SIZE); + + for x in 0..MAP_SIZE.x { + for y in 0..MAP_SIZE.y { + 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); + } + } + + commands.entity(tilemap_entity).insert(TilemapBundle { + grid_size: TILE_SIZE.into(), + map_type: TilemapType::default(), + size: MAP_SIZE, + storage: tile_storage, + texture: TilemapTexture::Single(dirt_texture_handle), + tile_size: TILE_SIZE, + anchor: TilemapAnchor::Center, + ..Default::default() + }); +} + +fn main() { + App::new() + .add_plugins( + DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: String::from("War in Tunnels"), + resolution: WindowResolution::new(1250, 625) + .with_scale_factor_override(1.0), + ..Default::default() + }), + ..default() + }) + .set(ImagePlugin::default_nearest()), + ) + .add_plugins(TilemapPlugin) + .add_systems(Startup, startup) + // .add_systems(Update, helpers::camera::movement) + .run(); }