Make characters visible
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
use bevy::prelude::Commands;
|
||||
|
||||
use crate::components::*;
|
||||
use crate::util::*;
|
||||
|
||||
pub fn spawn_player_character(mut commands: Commands) {
|
||||
let (hp, _) = roll("1d6 + 3");
|
||||
commands.spawn(Creature {
|
||||
health: Health {
|
||||
hp,
|
||||
max: hp,
|
||||
},
|
||||
armor: Armor {
|
||||
ac: 10,
|
||||
},
|
||||
spatial: Default::default(),
|
||||
}).insert(PlayerCharacter);
|
||||
}
|
||||
77
src/main.rs
77
src/main.rs
@@ -3,47 +3,54 @@ use bevy::prelude::*;
|
||||
pub mod util;
|
||||
pub mod components;
|
||||
pub mod systems;
|
||||
pub mod characters;
|
||||
|
||||
use components::*;
|
||||
use characters::*;
|
||||
|
||||
fn setup(
|
||||
query: Query<&Transform, With<PlayerCharacter>>,
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
for transform in query.iter() {
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Capsule{
|
||||
radius: 1.0,
|
||||
rings: 32,
|
||||
depth: 2.0,
|
||||
..Default::default()
|
||||
})),
|
||||
material: materials.add(StandardMaterial {
|
||||
unlit: true,
|
||||
..Default::default()
|
||||
}),
|
||||
transform: Transform::clone(transform),
|
||||
..Default::default()
|
||||
});
|
||||
commands.spawn(DirectionalLightBundle::default());
|
||||
commands.spawn(Camera3dBundle{
|
||||
transform: Transform::from_xyz(0.0, 10.0, 0.0).looking_at(Vec3::default(), Vec3::Y),
|
||||
projection: OrthographicProjection::default().into(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
use util::roll;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
// Add systems, whatnot
|
||||
.add_systems(Startup, spawn_player_character)
|
||||
.add_systems(Startup, spawn_player_character)
|
||||
.add_systems(Startup, setup)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
for i in 0..2 {
|
||||
let (hp, _) = roll("1d6 + 3");
|
||||
commands.spawn(Creature {
|
||||
health: Health {
|
||||
hp,
|
||||
max: hp,
|
||||
},
|
||||
armor: Armor {
|
||||
ac: 10,
|
||||
},
|
||||
spatial: SpatialBundle {
|
||||
transform: Transform::from_xyz(i as f32 * 2.0, 0.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
})
|
||||
.insert(PlayerCharacter)
|
||||
.with_children(|parent| {
|
||||
parent.spawn(PbrBundle {
|
||||
mesh: meshes.add(shape::Capsule::default().into()),
|
||||
material: materials.add(Color::WHITE.into()),
|
||||
..default()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
commands.spawn(DirectionalLightBundle {
|
||||
transform: Transform::default().looking_at(Vec3::new(3.0, -50.0, 1.0), Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
commands.spawn(Camera3dBundle{
|
||||
transform: Transform::from_xyz(1.0, 15.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user