added health, level, xp, and inventory
This commit is contained in:
parent
34079860bf
commit
9c06791a1c
19
src/components/entity.rs
Normal file
19
src/components/entity.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Level(pub u32);
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Xp(pub u32);
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Health{
|
||||
pub current: u32,
|
||||
pub max: u32,
|
||||
}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Inventory{
|
||||
pub items: Vec<Entity>,
|
||||
pub max_size: u32,
|
||||
}
|
||||
1
src/components/mod.rs
Normal file
1
src/components/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod entity;
|
||||
@ -1,12 +1,13 @@
|
||||
use bevy::prelude::*;
|
||||
pub mod shape;
|
||||
pub mod components;
|
||||
pub mod systems;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(ClearColor(Color::srgb(1.0, 1.0, 1.0)))
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, shape::display_shape)
|
||||
.add_systems(Startup, (setup, systems::player::spawn_player))
|
||||
.add_systems(Update, systems::debug::debug_player_components)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
||||
11
src/shape.rs
11
src/shape.rs
@ -1,11 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
|
||||
pub fn display_shape(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>) {
|
||||
let shape = meshes.add(Capsule2d::new(25.0, 50.0));
|
||||
let color = Color::hsl(360. * 5 as f32 / 10 as f32, 0.95, 0.7);
|
||||
commands.spawn((
|
||||
Mesh2d(shape),
|
||||
MeshMaterial2d(materials.add(color)),
|
||||
Transform::from_xyz(100.0, 0.0, 0.0)));
|
||||
}
|
||||
14
src/systems/debug.rs
Normal file
14
src/systems/debug.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use bevy::prelude::*;
|
||||
use crate::components::entity::{Level, Xp, Health, Inventory};
|
||||
|
||||
pub fn debug_player_components(
|
||||
query: Query<(Entity, &Level, &Xp, &Health, &Inventory)>,
|
||||
) {
|
||||
for (entity, level, xp, health, inv) in query.iter() {
|
||||
println!("-- Debug Entity {:?} --", entity);
|
||||
println!(" Level: {:?}", level);
|
||||
println!(" XP: {:?}", xp);
|
||||
println!(" Health: {:?}", health);
|
||||
println!(" Inventory contains {} items: {:?}", inv.items.len(), inv.items);
|
||||
}
|
||||
}
|
||||
2
src/systems/mod.rs
Normal file
2
src/systems/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod player;
|
||||
pub mod debug;
|
||||
15
src/systems/player.rs
Normal file
15
src/systems/player.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use bevy::prelude::*;
|
||||
use crate::components::entity::{Level, Xp, Health, Inventory};
|
||||
|
||||
pub fn spawn_player(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>) {
|
||||
let player_mesh = meshes.add(Capsule2d::new(25.0, 50.0));
|
||||
let color = Color::hsl(360. * 5 as f32 / 10 as f32, 0.95, 0.7);
|
||||
commands.spawn( (
|
||||
Mesh2d(player_mesh),
|
||||
MeshMaterial2d(materials.add(color)),
|
||||
Transform::from_xyz(100.0, 0.0, 0.0),
|
||||
Level(1),
|
||||
Xp(0),
|
||||
Health{current: 10, max: 10},
|
||||
Inventory {items: Vec::new(), max_size: 10},));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user