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::new),
Some(1) => std::process::exit(0),
_ => {}
}
}
}
struct Room;
impl Room {
fn new(app: &mut AppState) -> Self {
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_entity(
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());
Room
}
}
impl Scene for Room {
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();
}