resource production via graveyard, workers, and selectable buildlings
This commit is contained in:
parent
87fcc35a49
commit
921947c131
20 changed files with 364 additions and 24 deletions
81
crates/resource_graveyard/src/lib.rs
Normal file
81
crates/resource_graveyard/src/lib.rs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//bevy system signatures often violate these rules
|
||||
#![allow(clippy::type_complexity)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use avian3d::prelude::{Collider, PhysicsPickable, RigidBody, Sensor};
|
||||
use bevy::prelude::*;
|
||||
use input::Selectable;
|
||||
use resources::{Quantity, ResourceDeposit};
|
||||
use state::GameSystemSet;
|
||||
|
||||
pub struct ResourceGraveyardPlugin;
|
||||
|
||||
impl Plugin for ResourceGraveyardPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<PlaceGraveyard>()
|
||||
.add_systems(Startup, init)
|
||||
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Graveyard;
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct PlaceGraveyard(pub Vec3);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct GraveyardResources {
|
||||
mesh: Handle<Mesh>,
|
||||
material: Handle<StandardMaterial>,
|
||||
}
|
||||
|
||||
const SIZE: Vec3 = Vec3::new(2.0, 0.5, 2.0);
|
||||
|
||||
fn init(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let mesh = meshes.add(Cuboid::from_size(SIZE));
|
||||
let base_material = StandardMaterial {
|
||||
base_color: Color::srgb_u8(0xff, 0xe2, 0xe2),
|
||||
metallic: 0.2,
|
||||
perceptual_roughness: 0.8,
|
||||
..default()
|
||||
};
|
||||
let material = materials.add(base_material);
|
||||
|
||||
commands.insert_resource(GraveyardResources {
|
||||
mesh: mesh,
|
||||
material: material,
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn(
|
||||
mut reader: EventReader<PlaceGraveyard>,
|
||||
mut commands: Commands,
|
||||
res: Res<GraveyardResources>,
|
||||
) {
|
||||
for PlaceGraveyard(dest) in reader.read() {
|
||||
commands.spawn((
|
||||
Graveyard,
|
||||
Transform::from_translation(*dest),
|
||||
ResourceDeposit {
|
||||
bounty: Quantity { souls: 0, bones: 5 },
|
||||
level: 0,
|
||||
harvest_time: Duration::from_secs(5),
|
||||
},
|
||||
Mesh3d(res.mesh.clone()),
|
||||
MeshMaterial3d(res.material.clone()),
|
||||
Sensor,
|
||||
RigidBody::Static,
|
||||
Collider::cuboid(SIZE.x, SIZE.y, SIZE.z),
|
||||
PhysicsPickable,
|
||||
Selectable,
|
||||
Name::new("Graveyard"),
|
||||
));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue