nightshade-api 0.43.0

Procedural high level API for the nightshade game engine
Documentation
use nightshade_api::prelude::*;

struct Planet {
    entity: Entity,
    moon: Entity,
    radius: f32,
    speed: f32,
}

fn main() {
    run(
        |world| {
            show_grid(world, false);
            set_background(world, Background::Space);
            set_bloom(world, true);

            let sun = spawn_sphere(world, vec3(0.0, 2.0, 0.0));
            set_scale(world, sun, vec3(2.0, 2.0, 2.0));
            set_emissive(world, sun, [1.0, 0.8, 0.3], 12.0);
            set_unlit(world, sun, true);

            let bodies = [(3.5, 0.9, ORANGE), (5.5, 0.6, BLUE), (8.0, 0.35, GOLD)];

            let orbit_segments = 96;
            let orbit_lines = bodies
                .iter()
                .flat_map(|&(radius, _, color)| {
                    (0..orbit_segments).map(move |segment| {
                        let start_angle =
                            segment as f32 / orbit_segments as f32 * std::f32::consts::TAU;
                        let end_angle =
                            (segment + 1) as f32 / orbit_segments as f32 * std::f32::consts::TAU;
                        Line {
                            start: vec3(
                                start_angle.cos() * radius,
                                2.0,
                                start_angle.sin() * radius,
                            ),
                            end: vec3(end_angle.cos() * radius, 2.0, end_angle.sin() * radius),
                            color: vec4(color[0], color[1], color[2], color[3]),
                        }
                    })
                })
                .collect();
            spawn_lines(world, orbit_lines);

            let planets: Vec<Planet> = bodies
                .into_iter()
                .map(|(radius, speed, color)| {
                    let entity = spawn_sphere(world, vec3(radius, 2.0, 0.0));
                    set_scale(world, entity, vec3(0.6, 0.6, 0.6));
                    set_color(world, entity, color);
                    let moon = spawn_sphere(world, vec3(radius + 1.2, 2.0, 0.0));
                    set_scale(world, moon, vec3(0.2, 0.2, 0.2));
                    set_color(world, moon, GRAY);
                    set_parent(world, moon, Some(entity));
                    Planet {
                        entity,
                        moon,
                        radius,
                        speed,
                    }
                })
                .collect();

            orbit_camera(world, vec3(0.0, 2.0, 0.0), 18.0);
            planets
        },
        |world, planets| {
            let time = elapsed_seconds(world);
            let step = delta_time(world);
            for planet in planets.iter() {
                let angle = time * planet.speed;
                set_position(
                    world,
                    planet.entity,
                    vec3(
                        angle.cos() * planet.radius,
                        2.0,
                        angle.sin() * planet.radius,
                    ),
                );
                rotate(world, planet.entity, Vec3::y(), step * 0.8);
                rotate(world, planet.moon, Vec3::y(), step * 0.5);
            }
        },
    )
    .unwrap();
}