cash and enemy spawnpoints

This commit is contained in:
2025-03-04 00:10:57 +01:00
parent 3c78b35a69
commit ded4c5084c
7 changed files with 148 additions and 59 deletions

View File

@@ -844,3 +844,19 @@
( 768 1008 -224 ) ( 768 1008 -223 ) ( 768 1009 -224 ) crate [ 0 1 0 16 ] [ 0 0 -1 0 ] 90 1 1 ( 768 1008 -224 ) ( 768 1008 -223 ) ( 768 1009 -224 ) crate [ 0 1 0 16 ] [ 0 0 -1 0 ] 90 1 1
} }
} }
// entity 3
{
"classname" "enemy_spawn"
"origin" "648 -680 -248"
"angles" "0 -75 0"
}
// entity 4
{
"classname" "cash_spawn"
"origin" "696 1192 8"
}
// entity 5
{
"classname" "enemy_spawn"
"origin" "3256 248 -248"
}

BIN
assets/models/cash.glb Normal file

Binary file not shown.

View File

@@ -1,8 +1,7 @@
use avian3d::prelude::*;
use bevy::prelude::*; use bevy::prelude::*;
use std::time::Duration; use std::time::Duration;
const ASSET_PATH: &str = "models/alien_naked.glb"; pub const ALIEN_ASSET_PATH: &str = "models/alien_naked.glb";
#[derive(Resource)] #[derive(Resource)]
struct Animations { struct Animations {
@@ -22,8 +21,8 @@ fn setup(
) { ) {
// Build the animation graph // Build the animation graph
let (graph, node_indices) = AnimationGraph::from_clips([ let (graph, node_indices) = AnimationGraph::from_clips([
asset_server.load(GltfAssetLabel::Animation(1).from_asset(ASSET_PATH)), asset_server.load(GltfAssetLabel::Animation(1).from_asset(ALIEN_ASSET_PATH)),
asset_server.load(GltfAssetLabel::Animation(0).from_asset(ASSET_PATH)), asset_server.load(GltfAssetLabel::Animation(0).from_asset(ALIEN_ASSET_PATH)),
]); ]);
// Insert a resource with the current scene information // Insert a resource with the current scene information
@@ -32,18 +31,6 @@ fn setup(
animations: node_indices, animations: node_indices,
graph: graph_handle, graph: graph_handle,
}); });
commands
.spawn((
RigidBody::Dynamic,
Collider::capsule(0.2, 1.),
LockedAxes::new().lock_rotation_z().lock_rotation_x(),
Name::from("Alien"),
))
.with_child((
Transform::from_translation(Vec3::new(0., -0.6, 0.)),
SceneRoot(asset_server.load(GltfAssetLabel::Scene(0).from_asset(ASSET_PATH))),
));
} }
fn setup_once_loaded( fn setup_once_loaded(

16
src/cash.rs Normal file
View File

@@ -0,0 +1,16 @@
use bevy::prelude::*;
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform)]
pub struct Cash;
pub fn plugin(app: &mut App) {
app.add_systems(Update, rotate);
}
fn rotate(time: Res<Time>, mut query: Query<&mut Transform, With<Cash>>) {
for mut transform in query.iter_mut() {
transform.rotate(Quat::from_rotation_y(time.delta_secs()));
}
}

View File

@@ -1,28 +1,15 @@
mod alien;
mod cash;
mod tb_entities;
use avian3d::PhysicsPlugins; use avian3d::PhysicsPlugins;
use avian3d::prelude::*; use avian3d::prelude::*;
use bevy::core_pipeline::tonemapping::Tonemapping; use bevy::core_pipeline::tonemapping::Tonemapping;
use bevy::ecs::component::ComponentId;
use bevy::ecs::world::DeferredWorld;
use bevy::math::*;
use bevy::prelude::*; use bevy::prelude::*;
use bevy::render::view::ColorGrading; use bevy::render::view::ColorGrading;
use bevy_flycam::prelude::*; use bevy_flycam::prelude::*;
use bevy_trenchbroom::prelude::*; use bevy_trenchbroom::prelude::*;
mod alien;
#[derive(SolidClass, Component, Reflect)]
#[reflect(Component)]
#[geometry(GeometryProvider::new().convex_collider().smooth_by_default_angle().render())]
pub struct Worldspawn;
#[derive(SolidClass, Component, Reflect, Default)]
#[reflect(Component)]
#[geometry(GeometryProvider::new().convex_collider().smooth_by_default_angle().render())]
pub struct NamedEntity {
pub name: String,
}
#[derive(Resource, Reflect, Debug)] #[derive(Resource, Reflect, Debug)]
#[reflect(Resource)] #[reflect(Resource)]
struct DebugVisuals { struct DebugVisuals {
@@ -32,30 +19,6 @@ struct DebugVisuals {
pub shadows: bool, pub shadows: bool,
} }
#[derive(PointClass, Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform)]
#[component(on_add = Self::on_add)]
#[model({ "path": "models/spawn.glb" })]
pub struct SpawnPoint {}
impl SpawnPoint {
fn on_add(mut world: DeferredWorld, entity: Entity, _id: ComponentId) {
let Some(asset_server) = world.get_resource::<AssetServer>() else {
return;
};
let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/spawn.glb"));
world.commands().entity(entity).insert((
Name::new("spawn"),
SceneRoot(mesh),
RigidBody::Static,
ColliderConstructorHierarchy::new(ColliderConstructor::TrimeshFromMesh),
));
}
}
fn main() { fn main() {
let mut app = App::new(); let mut app = App::new();
@@ -72,12 +35,13 @@ fn main() {
})); }));
app.add_plugins(PhysicsPlugins::default()); app.add_plugins(PhysicsPlugins::default());
app.add_plugins(PhysicsDebugPlugin::default()); // app.add_plugins(PhysicsDebugPlugin::default());
// bevy_flycam setup so we can get a closer look at the scene, mainly for debugging // bevy_flycam setup so we can get a closer look at the scene, mainly for debugging
app.add_plugins(PlayerPlugin); app.add_plugins(PlayerPlugin);
app.add_plugins(alien::plugin); app.add_plugins(alien::plugin);
app.add_plugins(cash::plugin);
app.insert_resource(MovementSettings { app.insert_resource(MovementSettings {
sensitivity: 0.00005, sensitivity: 0.00005,
@@ -119,7 +83,8 @@ fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(( commands.spawn((
SceneRoot( SceneRoot(
asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/angry_demonstrator.glb")), asset_server
.load(GltfAssetLabel::Scene(0).from_asset("models/heads/angry_demonstrator.glb")),
), ),
Transform::from_xyz(0.0, 5.0, 0.0), Transform::from_xyz(0.0, 5.0, 0.0),
)); ));

97
src/tb_entities.rs Normal file
View File

@@ -0,0 +1,97 @@
use avian3d::prelude::*;
use bevy::ecs::{component::ComponentId, world::DeferredWorld};
use bevy::math::*;
use bevy::prelude::*;
use bevy_trenchbroom::prelude::*;
use crate::cash::Cash;
#[derive(PointClass, Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform)]
#[component(on_add = Self::on_add)]
#[model({ "path": "models/spawn.glb" })]
pub struct SpawnPoint {}
impl SpawnPoint {
fn on_add(mut world: DeferredWorld, entity: Entity, _id: ComponentId) {
let Some(asset_server) = world.get_resource::<AssetServer>() else {
return;
};
let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/spawn.glb"));
world.commands().entity(entity).insert((
Name::new("spawn"),
SceneRoot(mesh),
RigidBody::Static,
ColliderConstructorHierarchy::new(ColliderConstructor::TrimeshFromMesh),
));
}
}
#[derive(SolidClass, Component, Reflect)]
#[reflect(Component)]
#[geometry(GeometryProvider::new().convex_collider().smooth_by_default_angle().render())]
pub struct Worldspawn;
#[derive(SolidClass, Component, Reflect, Default)]
#[reflect(Component)]
#[geometry(GeometryProvider::new().convex_collider().smooth_by_default_angle().render())]
pub struct NamedEntity {
pub name: String,
}
#[derive(PointClass, Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform)]
#[component(on_add = Self::on_add)]
#[model({ "path": "models/alien_naked.glb" })]
pub struct EnemySpawn {}
impl EnemySpawn {
fn on_add(mut world: DeferredWorld, entity: Entity, _id: ComponentId) {
let Some(asset_server) = world.get_resource::<AssetServer>() else {
return;
};
let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/alien_naked.glb"));
world
.commands()
.entity(entity)
.insert((
Visibility::default(),
RigidBody::Dynamic,
Collider::capsule(0.2, 1.),
LockedAxes::new().lock_rotation_z().lock_rotation_x(),
Name::from("Enemy"),
))
.with_child((
Transform::from_translation(Vec3::new(0., -0.6, 0.)),
SceneRoot(mesh),
));
}
}
#[derive(PointClass, Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform)]
#[component(on_add = Self::on_add)]
#[model({ "path": "models/cash.glb" })]
pub struct CashSpawn {}
impl CashSpawn {
fn on_add(mut world: DeferredWorld, entity: Entity, _id: ComponentId) {
let Some(asset_server) = world.get_resource::<AssetServer>() else {
return;
};
let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/cash.glb"));
world
.commands()
.entity(entity)
.insert((Name::new("cash"), SceneRoot(mesh), Cash));
}
}

View File

@@ -56,6 +56,14 @@
NOTE: Changing to 2, for example, will cause the bmodel to initially be solid black. Youll need to add minlight or lights with _light_channel_mask 2." NOTE: Changing to 2, for example, will cause the bmodel to initially be solid black. Youll need to add minlight or lights with _light_channel_mask 2."
] ]
@PointClass base(transform) model({ "path": "models/cash.glb" }) = cash_spawn
[
]
@PointClass base(transform) model({ "path": "models/alien_naked.glb" }) = enemy_spawn
[
]
@SolidClass = named_entity @SolidClass = named_entity
[ [
name(string) : "name" : "" : "" name(string) : "name" : "" : ""