Try to render characters
This commit is contained in:
parent
8677e05fe1
commit
783021d5f3
@ -6,17 +6,13 @@ use crate::util::*;
|
|||||||
pub fn spawn_player_character(mut commands: Commands) {
|
pub fn spawn_player_character(mut commands: Commands) {
|
||||||
let (hp, _) = roll("1d6 + 3");
|
let (hp, _) = roll("1d6 + 3");
|
||||||
commands.spawn(Creature {
|
commands.spawn(Creature {
|
||||||
health: Health {
|
health: Health {
|
||||||
hp,
|
hp,
|
||||||
max: hp,
|
max: hp,
|
||||||
},
|
},
|
||||||
armor: Armor {
|
armor: Armor {
|
||||||
ac: 10,
|
ac: 10,
|
||||||
},
|
},
|
||||||
position: Position {
|
spatial: Default::default(),
|
||||||
x: 0.0,
|
}).insert(PlayerCharacter);
|
||||||
y: 0.0,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.insert(PlayerCharacter);
|
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,11 @@ pub struct Armor {
|
|||||||
pub ac: u32,
|
pub ac: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct Position {
|
|
||||||
pub x: f32,
|
|
||||||
pub y: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct Creature {
|
pub struct Creature {
|
||||||
pub health: Health,
|
pub health: Health,
|
||||||
pub armor: Armor,
|
pub armor: Armor,
|
||||||
pub position: Position,
|
pub spatial: SpatialBundle,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
36
src/main.rs
36
src/main.rs
@ -5,13 +5,45 @@ pub mod components;
|
|||||||
pub mod systems;
|
pub mod systems;
|
||||||
pub mod characters;
|
pub mod characters;
|
||||||
|
|
||||||
use crate::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()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
// Add systems, whatnot
|
// Add systems, whatnot
|
||||||
.add_systems(Startup, spawn_player_character)
|
.add_systems(Startup, spawn_player_character)
|
||||||
.add_systems(Startup, spawn_player_character)
|
.add_systems(Startup, spawn_player_character)
|
||||||
|
.add_systems(Startup, setup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user