Just a really bad terrain generator
This commit is contained in:
parent
d31c73b005
commit
d38e41de29
43
Cargo.lock
generated
43
Cargo.lock
generated
@ -2004,6 +2004,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy",
|
"bevy",
|
||||||
"bevy_ecs_tilemap",
|
"bevy_ecs_tilemap",
|
||||||
|
"rand",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2418,6 +2419,12 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
@ -2458,6 +2465,36 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "17fd96390ed3feda12e1dfe2645ed587e0bea749e319333f104a33ff62f77a0b"
|
checksum = "17fd96390ed3feda12e1dfe2645ed587e0bea749e319333f104a33ff62f77a0b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "range-alloc"
|
name = "range-alloc"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
@ -3009,7 +3046,7 @@ dependencies = [
|
|||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.12.1",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
@ -3035,7 +3072,7 @@ dependencies = [
|
|||||||
"fxhash",
|
"fxhash",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.12.1",
|
||||||
"profiling",
|
"profiling",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@ -3072,7 +3109,7 @@ dependencies = [
|
|||||||
"metal",
|
"metal",
|
||||||
"naga",
|
"naga",
|
||||||
"objc",
|
"objc",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.12.1",
|
||||||
"profiling",
|
"profiling",
|
||||||
"range-alloc",
|
"range-alloc",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
|
@ -9,3 +9,4 @@ license = "AGPL-3.0-or-later"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.8.0"
|
bevy = "0.8.0"
|
||||||
bevy_ecs_tilemap = "0.7.0"
|
bevy_ecs_tilemap = "0.7.0"
|
||||||
|
rand = "0.8.5"
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
108
src/main.rs
108
src/main.rs
@ -2,29 +2,33 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||||
input::mouse::MouseMotion,
|
input::mouse::MouseMotion,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::texture::ImageSettings, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
render::texture::ImageSettings,
|
||||||
};
|
};
|
||||||
use bevy_ecs_tilemap::prelude::*;
|
use bevy_ecs_tilemap::prelude::*;
|
||||||
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn make_ground_layer(
|
||||||
commands.spawn_bundle(Camera2dBundle::default());
|
commands: &mut Commands,
|
||||||
|
tilemap_size: TilemapSize,
|
||||||
let texture_handle = asset_server.load("tileset.png");
|
texture_handle: Handle<Image>,
|
||||||
|
tile_size: TilemapTileSize,
|
||||||
let tilemap_size = TilemapSize { x: 320, y: 320 };
|
) {
|
||||||
let mut tile_storage = TileStorage::empty(tilemap_size);
|
let mut tile_storage = TileStorage::empty(tilemap_size);
|
||||||
let tilemap_entity = commands.spawn().id();
|
let tilemap_entity = commands.spawn().id();
|
||||||
|
let mut random = thread_rng();
|
||||||
|
|
||||||
for x in 0..320u32 {
|
for x in 0..tilemap_size.x {
|
||||||
for y in 0..320u32 {
|
for y in 0..tilemap_size.y {
|
||||||
let tile_pos = TilePos { x, y };
|
let tile_pos = TilePos { x, y };
|
||||||
let tile_entity = commands
|
let tile_entity = commands
|
||||||
.spawn()
|
.spawn()
|
||||||
.insert_bundle(TileBundle {
|
.insert_bundle(TileBundle {
|
||||||
position: tile_pos,
|
position: tile_pos,
|
||||||
tilemap_id: TilemapId(tilemap_entity),
|
tilemap_id: TilemapId(tilemap_entity),
|
||||||
|
texture: TileTexture(random.gen_range(13..=19)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.id();
|
.id();
|
||||||
@ -32,21 +36,90 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let tile_size = TilemapTileSize { x: 32.0, y: 32.0 };
|
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.entity(tilemap_entity)
|
.entity(tilemap_entity)
|
||||||
.insert_bundle(TilemapBundle {
|
.insert_bundle(TilemapBundle {
|
||||||
grid_size: TilemapGridSize { x: 32.0, y: 32.0 },
|
grid_size: tile_size.into(),
|
||||||
size: tilemap_size,
|
size: tilemap_size,
|
||||||
storage: tile_storage,
|
storage: tile_storage,
|
||||||
texture: TilemapTexture(texture_handle),
|
texture: TilemapTexture(texture_handle),
|
||||||
tile_size,
|
tile_size,
|
||||||
transform: bevy_ecs_tilemap::helpers::get_centered_transform_2d(&tilemap_size, &tile_size, 0.0),
|
transform: bevy_ecs_tilemap::helpers::get_centered_transform_2d(
|
||||||
|
&tilemap_size,
|
||||||
|
&tile_size,
|
||||||
|
0.0,
|
||||||
|
),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_wall_layer(
|
||||||
|
commands: &mut Commands,
|
||||||
|
tilemap_size: TilemapSize,
|
||||||
|
texture_handle: Handle<Image>,
|
||||||
|
tile_size: TilemapTileSize,
|
||||||
|
) {
|
||||||
|
let mut tile_storage = TileStorage::empty(tilemap_size);
|
||||||
|
let tilemap_entity = commands.spawn().id();
|
||||||
|
let mut random = thread_rng();
|
||||||
|
|
||||||
|
for x in 0..tilemap_size.x {
|
||||||
|
for y in 0..tilemap_size.y {
|
||||||
|
let tile_pos = TilePos { x, y };
|
||||||
|
if random.gen_bool(0.5) {
|
||||||
|
let tile_entity = commands
|
||||||
|
.spawn()
|
||||||
|
.insert_bundle(TileBundle {
|
||||||
|
position: tile_pos,
|
||||||
|
tilemap_id: TilemapId(tilemap_entity),
|
||||||
|
texture: TileTexture(random.gen_range(0..=12)),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.id();
|
||||||
|
tile_storage.set(&tile_pos, Some(tile_entity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commands
|
||||||
|
.entity(tilemap_entity)
|
||||||
|
.insert_bundle(TilemapBundle {
|
||||||
|
grid_size: tile_size.into(),
|
||||||
|
size: tilemap_size,
|
||||||
|
storage: tile_storage,
|
||||||
|
texture: TilemapTexture(texture_handle),
|
||||||
|
tile_size,
|
||||||
|
transform: bevy_ecs_tilemap::helpers::get_centered_transform_2d(
|
||||||
|
&tilemap_size,
|
||||||
|
&tile_size,
|
||||||
|
1.0,
|
||||||
|
),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
commands.spawn_bundle(Camera2dBundle::default());
|
||||||
|
|
||||||
|
let texture_handle = asset_server.load("tileset.png");
|
||||||
|
|
||||||
|
let tilemap_size = TilemapSize { x: 320, y: 320 };
|
||||||
|
let tile_size = TilemapTileSize { x: 32.0, y: 32.0 };
|
||||||
|
|
||||||
|
make_ground_layer(
|
||||||
|
&mut commands,
|
||||||
|
tilemap_size,
|
||||||
|
texture_handle.clone(),
|
||||||
|
tile_size,
|
||||||
|
);
|
||||||
|
make_wall_layer(
|
||||||
|
&mut commands,
|
||||||
|
tilemap_size,
|
||||||
|
texture_handle,
|
||||||
|
tile_size,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn mouse_motion(
|
fn mouse_motion(
|
||||||
mut motion_evr: EventReader<MouseMotion>,
|
mut motion_evr: EventReader<MouseMotion>,
|
||||||
buttons: Res<Input<MouseButton>>,
|
buttons: Res<Input<MouseButton>>,
|
||||||
@ -79,12 +152,3 @@ fn main() {
|
|||||||
.add_system(mouse_motion)
|
.add_system(mouse_motion)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn test_true()
|
|
||||||
{
|
|
||||||
assert!(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user