codecraft 0.1.2

A minimalist 3D game engine built on parts of Bevy (ECS, color) with wgpu and winit: OpenPBR materials, clustered lighting, a yakui-drawn UI, audio and gamepad haptics; its binary maps any folder, and the symbols of its Rust files, as a 3D wall of boxes
Documentation
//! Two scenes and the UI to move between them: a menu of buttons, and a
//! room you can walk back out of.
//!
//! ```text
//! cargo run --example menu
//! ```
use codecraft::glam::Vec3;
use codecraft::prelude::*;
use codecraft::sceneobjects::lights::default_lights;
use codecraft::ui::yakui::{Alignment, Pivot};
use codecraft::{KeyCode, Light, OrbitCamera, gizmos, primitives, ui};

struct Menu;

impl Scene for Menu {
    fn update(&mut self, app: &mut AppState) {
        ui::screen(|| {
            ui::place(0.5, 0.25, Pivot::CENTER, || {
                ui::text(77.0, "CODECRAFT");
            });
        });
        match ui::menu(&["ENTER THE ROOM", "QUIT"]) {
            Some(0) => app.change_scene(Room),
            Some(1) => std::process::exit(0),
            _ => {}
        }
    }
}

struct Room;

impl Scene for Room {
    fn setup(&mut self, app: &mut AppState) {
        app.spawn(gizmos::grid().fade(8.0, 20.0));

        let [key, rim] = default_lights();
        app.spawn_entity((key, Light::object("Key Light")));
        app.spawn_entity((rim, Light::object("Rim Light")));

        for (i, x) in [-2.0, 0.0, 2.0].into_iter().enumerate() {
            let height = 0.5 + i as f32 * 0.5;
            app.spawn_primitive(
                primitives::Box::new(1.0, height, 1.0)
                    .at(x, height / 2.0, 0.0)
                    .color(Color::srgb(0.55, 0.65, 0.75)),
            );
        }

        app.spawn_entity(OrbitCamera::new(Vec3::new(0.0, 0.5, 0.0), 7.0).touchpad());
    }

    fn update(&mut self, app: &mut AppState) {
        let mut back = false;
        ui::corner(Alignment::TOP_LEFT, || {
            ui::panel(|| {
                back = ui::button("BACK");
            });
        });
        if back || app.keys().just_pressed(KeyCode::Escape) {
            app.change_scene(Menu);
        }
    }
}

fn main() {
    App::new("menu").scene(Menu).run();
}