Compare commits
4 Commits
update-fla
...
make_basic
| Author | SHA1 | Date | |
|---|---|---|---|
| d6b2a93eac | |||
| ef257f43e6 | |||
| ec3185f386 | |||
| fa4798910d |
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -644,6 +644,16 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "bevy_encase_derive"
|
name = "bevy_encase_derive"
|
||||||
version = "0.17.2"
|
version = "0.17.2"
|
||||||
@@ -4556,6 +4566,7 @@ name = "war-in-tunnels"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy",
|
"bevy",
|
||||||
|
"bevy_ecs_tilemap",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.17.2"
|
bevy = "0.17.2"
|
||||||
|
bevy_ecs_tilemap = "0.17.0"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
|
|||||||
BIN
assets/base_field.png
Normal file
BIN
assets/base_field.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
BIN
assets/dirt_field.png
Normal file
BIN
assets/dirt_field.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
124
src/main.rs
124
src/main.rs
@@ -1,3 +1,123 @@
|
|||||||
fn main() {
|
use bevy::{prelude::*, window::WindowResolution};
|
||||||
println!("Hello, world!");
|
use bevy_ecs_tilemap::prelude::*;
|
||||||
|
|
||||||
|
const TILEMAP_WIDTH: u32 = 50;
|
||||||
|
const TILEMAP_HEIGHT: u32 = 25;
|
||||||
|
|
||||||
|
const TILE_WIDTH: f32 = 25.0;
|
||||||
|
const TILE_HEIGHT: f32 = 25.0;
|
||||||
|
|
||||||
|
const MAP_SIZE: TilemapSize = TilemapSize {
|
||||||
|
x: TILEMAP_WIDTH,
|
||||||
|
y: TILEMAP_HEIGHT,
|
||||||
|
};
|
||||||
|
const TILE_SIZE: TilemapTileSize = TilemapTileSize {
|
||||||
|
x: TILE_WIDTH,
|
||||||
|
y: TILE_HEIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
commands.spawn(Camera2d);
|
||||||
|
|
||||||
|
let dirt_texture_handle: Handle<Image> = asset_server.load("dirt_field.png");
|
||||||
|
let base_texture_handle: Handle<Image> = asset_server.load("base_field.png");
|
||||||
|
|
||||||
|
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 base_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for x in 0..3 {
|
||||||
|
for y in 11..14 {
|
||||||
|
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 47..50 {
|
||||||
|
for y in 11..14 {
|
||||||
|
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 {
|
||||||
|
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,
|
||||||
|
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()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
.add_plugins(
|
||||||
|
DefaultPlugins
|
||||||
|
.set(WindowPlugin {
|
||||||
|
primary_window: Some(Window {
|
||||||
|
title: String::from("War in Tunnels"),
|
||||||
|
resolution: WindowResolution::new(
|
||||||
|
TILEMAP_WIDTH * TILE_WIDTH as u32,
|
||||||
|
TILEMAP_HEIGHT * TILE_HEIGHT as u32,
|
||||||
|
)
|
||||||
|
.with_scale_factor_override(1.0),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..default()
|
||||||
|
})
|
||||||
|
.set(ImagePlugin::default_nearest()),
|
||||||
|
)
|
||||||
|
.add_plugins(TilemapPlugin)
|
||||||
|
.add_systems(Startup, startup)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user