Compare commits

...

3 Commits

Author SHA1 Message Date
b562abe976
Add a "pawn" that gets "rendered" above the ground layer. 2022-12-23 17:00:57 +01:00
22ed2261f3
Add a terrain def and use it 2022-12-23 12:48:48 +01:00
d4175e0710
Cleanup 2022-12-21 13:18:05 +01:00
10 changed files with 106 additions and 99 deletions

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# 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
View File

@ -1,6 +0,0 @@
<?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
View File

@ -1,7 +0,0 @@
<?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>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="commitMessageIssueKeyValidationOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
<option name="commitMessageValidationEnabledOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
</component>
</project>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?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
View File

@ -1,11 +0,0 @@
<?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
View File

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

View File

@ -1,7 +1,6 @@
{
"recommendations": [
"vadimcn.vscode-lldb",
"ymotongpoo.licenser",
"rust-lang.rust-analyzer"
]
}

View File

@ -1,10 +1,10 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct SurfaceDef {
label: String,
name: String,
description: String,
texture_index: u32,
support: f32,
pub struct SurfaceDef<'a> {
pub label: &'a str,
pub name: &'a str,
pub description: &'a str,
pub texture_index: u32,
pub support: f32,
}

View File

@ -7,10 +7,56 @@ use bevy::{
prelude::*,
};
use bevy_ecs_tilemap::prelude::*;
use rand::{thread_rng, Rng};
use defs::SurfaceDef;
mod defs;
const TERRAINS: [SurfaceDef; 3] = [
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,
},
];
#[derive(Component, Clone)]
struct TileTerrain {
terrain_id: usize,
}
impl TileTerrain {
fn def(&self) -> &SurfaceDef {
&TERRAINS[self.terrain_id]
}
}
#[derive(Bundle, Default)]
struct PawnBundle {
position: TilePos,
sprite: Sprite,
transform: Transform,
global_transform: GlobalTransform,
texture: Handle<Image>,
visibility: Visibility,
computed_visibility: ComputedVisibility,
}
fn make_ground_layer(
commands: &mut Commands,
tilemap_size: TilemapSize,
@ -19,18 +65,22 @@ fn make_ground_layer(
) {
let mut tile_storage = TileStorage::empty(tilemap_size);
let tilemap_entity = commands.spawn_empty().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 };
let tile_terrain = TileTerrain { terrain_id: 1 };
let tile_entity = commands
.spawn(TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
texture_index: TileTextureIndex(random.gen_range(13..=19)),
..Default::default()
})
.spawn((
tile_terrain.clone(),
TileBundle {
position: tile_pos,
tilemap_id: TilemapId(tilemap_entity),
texture_index: TileTextureIndex(tile_terrain.def().texture_index),
..Default::default()
},
))
.id();
tile_storage.set(&tile_pos, tile_entity);
}
@ -39,18 +89,34 @@ fn make_ground_layer(
let grid_size = tile_size.into();
let map_type = TilemapType::default();
commands
.entity(tilemap_entity)
.insert(TilemapBundle {
grid_size,
map_type,
size: tilemap_size,
storage: tile_storage.clone(),
texture: TilemapTexture::Single(texture_handle),
tile_size,
transform: get_tilemap_center_transform(&tilemap_size, &grid_size, &map_type, 0.0),
commands.entity(tilemap_entity).insert(TilemapBundle {
grid_size,
map_type,
size: tilemap_size,
storage: tile_storage.clone(),
texture: TilemapTexture::Single(texture_handle),
tile_size,
transform: get_tilemap_center_transform(&tilemap_size, &grid_size, &map_type, 0.0),
..Default::default()
});
}
fn make_pawn(commands: &mut Commands, texture_handle: Handle<Image>, tile_size: TilemapTileSize) {
commands.spawn(PawnBundle {
transform: Transform::from_xyz(0.0, 0.0, 1.0),
texture: texture_handle,
sprite: Sprite {
rect: Option::Some(Rect::new(
3. * tile_size.x,
4. * tile_size.y,
4. * tile_size.x,
5. * tile_size.y,
)),
..Default::default()
});
},
visibility: Visibility { is_visible: true },
..Default::default()
});
}
fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
@ -64,9 +130,10 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
make_ground_layer(
&mut commands,
tilemap_size,
texture_handle,
texture_handle.clone(),
tile_size,
);
make_pawn(&mut commands, texture_handle, tile_size);
}
fn mouse_motion(
@ -84,19 +151,21 @@ fn mouse_motion(
}
}
fn main() {
App::new()
.add_plugins(DefaultPlugins
.set(WindowPlugin {
window: WindowDescriptor {
width: 1270.0,
height:720.0,
title: String::from("Monstrous"),
..Default::default()
},
..default()
})
.set(ImagePlugin::default_nearest()),
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
window: WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Monstrous"),
..Default::default()
},
..default()
})
.set(ImagePlugin::default_nearest()),
)
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())