This commit is contained in:
Gender Shrapnel 2022-11-01 21:06:09 +01:00
parent d38e41de29
commit 1702da5d16
11 changed files with 308 additions and 266 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
.idea/GitLink.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="uk.co.ben_gibson.git.link.SettingsState">
<option name="host" value="e0f86390-1091-4871-8aeb-f534fbc99cf0" />
</component>
</project>

7
.idea/discord.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/monstrous.iml" filepath="$PROJECT_DIR$/.idea/monstrous.iml" />
</modules>
</component>
</project>

11
.idea/monstrous.iml generated Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

430
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,8 @@ license = "AGPL-3.0-or-later"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.8.0"
bevy_ecs_tilemap = "0.7.0"
rand = "0.8.5"
bevy = "0.8.1"
bevy_ecs_tilemap = "0.8.0"
rand = "0.8.5"
ron = "0.8.0"
serde = { version = "1.0.143", features = ["derive"] }

23
assets/surfaces.ron Normal file
View File

@ -0,0 +1,23 @@
[
SurfaceDef {
label: "Mud",
name: "mud",
description: "Soil saturated with water.",
texture_index: 13,
support: 20.0,
},
SurfaceDef {
label: "Grass",
name: "grass",
description: "Green. Try to touch it.",
texture_index: 14,
support: 40.0,
},
SurfaceDef {
label: "Sand",
name: "sand",
description: "Gets everywhere, ruins vanilla sex fantasies.",
texture_index: 15,
support: 20.0,
},
]

12
src/defs.rs Normal file
View File

@ -0,0 +1,12 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct SurfaceDef {
label: String,
name: String,
description: String,
texture_index: u32,
support: f32,
}

View File

@ -10,6 +10,8 @@ use bevy::{
use bevy_ecs_tilemap::prelude::*;
use rand::{thread_rng, Rng};
mod defs;
fn make_ground_layer(
commands: &mut Commands,
tilemap_size: TilemapSize,
@ -41,7 +43,7 @@ fn make_ground_layer(
.insert_bundle(TilemapBundle {
grid_size: tile_size.into(),
size: tilemap_size,
storage: tile_storage,
storage: tile_storage.clone(),
texture: TilemapTexture(texture_handle),
tile_size,
transform: bevy_ecs_tilemap::helpers::get_centered_transform_2d(
@ -53,51 +55,6 @@ fn make_ground_layer(
});
}
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());
@ -107,12 +64,6 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
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,