add soul spot resource deposit and fix core placement bug
This commit is contained in:
parent
52da1f8acb
commit
68f4b0d8a0
13 changed files with 171 additions and 27 deletions
15
crates/resource_soul_spot/Cargo.toml
Normal file
15
crates/resource_soul_spot/Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "resource_soul_spot"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
avian3d = {workspace = true }
|
||||
|
||||
state = { path = "../state" }
|
||||
resources = { path = "../resources" }
|
||||
input = { path = "../input" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
82
crates/resource_soul_spot/src/lib.rs
Normal file
82
crates/resource_soul_spot/src/lib.rs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
//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 ResourceSoulSpotPlugin;
|
||||
|
||||
impl Plugin for ResourceSoulSpotPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<PlaceSoulSpot>()
|
||||
.add_systems(Startup, init)
|
||||
.add_systems(FixedUpdate, spawn.in_set(GameSystemSet::PostTick));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct SoulSpot;
|
||||
|
||||
#[derive(Event)]
|
||||
pub struct PlaceSoulSpot(pub Vec3);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct SoulSpotResources {
|
||||
mesh: Handle<Mesh>,
|
||||
material: Handle<StandardMaterial>,
|
||||
}
|
||||
|
||||
const SIZE: Vec3 = Vec3::new(1.5, 0.5, 1.5);
|
||||
|
||||
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(210, 188, 166),
|
||||
metallic: 0.8,
|
||||
perceptual_roughness: 0.2,
|
||||
..default()
|
||||
};
|
||||
let material = materials.add(base_material);
|
||||
|
||||
commands.insert_resource(SoulSpotResources {
|
||||
mesh: mesh,
|
||||
material: material,
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn(
|
||||
mut reader: EventReader<PlaceSoulSpot>,
|
||||
mut commands: Commands,
|
||||
res: Res<SoulSpotResources>,
|
||||
) {
|
||||
for PlaceSoulSpot(dest) in reader.read() {
|
||||
commands.spawn((
|
||||
SoulSpot,
|
||||
Transform::from_translation(*dest),
|
||||
ResourceDeposit {
|
||||
bounty: Quantity { souls: 2, bones: 1 },
|
||||
level: 1,
|
||||
harvest_time: Duration::from_secs(2),
|
||||
max_workers: 1,
|
||||
},
|
||||
Mesh3d(res.mesh.clone()),
|
||||
MeshMaterial3d(res.material.clone()),
|
||||
Sensor,
|
||||
RigidBody::Static,
|
||||
Collider::cuboid(SIZE.x, SIZE.y, SIZE.z),
|
||||
PhysicsPickable,
|
||||
Selectable,
|
||||
Name::new("Soul Spot"),
|
||||
));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue