import math
from pybevy._pybevy import Health from pybevy.prelude import *
ROTATION_SPEED = 1.0
@component
class Cube(Component):
def setup(
commands: Commands,
meshes: ResMut[Assets[Mesh]],
materials: ResMut[Assets[StandardMaterial]],
) -> None:
commands.spawn(
Mesh3d(meshes.add(Circle(radius=4.0).mesh())),
MeshMaterial3d(materials.add(StandardMaterial.from_color(Color.WHITE))),
Transform.from_rotation(Quat.from_rotation_x(-math.pi / 2)),
)
commands.spawn(
Cube(),
Mesh3d(meshes.add(Cuboid(1.0, 1.0, 1.0).mesh())),
MeshMaterial3d(materials.add(StandardMaterial.from_color(Color.srgb_u8(124, 144, 255)))),
Transform.from_xyz(0.0, 0.5, 0.0),
)
commands.spawn(
PointLight(shadows_enabled=True),
Transform.from_xyz(4.0, 8.0, 4.0),
)
commands.spawn(
Camera3d(),
Transform.from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3.ZERO, Vec3.Y),
)
def rotate_cube(query: Query[Mut[Transform], With[Cube]], time: Res[Time]) -> None:
for transform in query:
transform.rotation *= Quat.from_rotation_y(time.delta_secs() * ROTATION_SPEED)
def apply_damage(query: Query[Mut[Health]], time: Res[Time]) -> None:
for health in query:
health.value -= 5.0 * time.delta_secs()
if health.value < 0.0:
health.value = health.max