use codecraft::glam::Vec3;
use codecraft::prelude::*;
use codecraft::sceneobjects::lights::default_lights;
use codecraft::{KeyCode, Light, OrbitCamera, gizmos, primitives};
struct Menu;
impl Scene for Menu {
fn setup(&mut self, app: &mut AppState) {
app.spawn(Heading::text("CODECRAFT").y_ratio(0.25));
let scenes = app.scenes();
app.spawn(
Panel::new("Menu")
.add(Button::new("ENTER THE ROOM", move || scenes.change(Room)))
.add(Button::new("QUIT", || 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::item("Key Light")));
app.spawn_entity((rim, Light::item("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());
let scenes = app.scenes();
app.spawn(
Panel::new("Room")
.anchor(Anchor::TopLeft)
.add(Button::new("BACK", move || scenes.change(Menu))),
);
}
fn update(&mut self, app: &mut AppState) {
if app.keys().just_pressed(KeyCode::Escape) {
app.change_scene(Menu);
}
}
}
fn main() {
App::new("menu").scene(Menu).run();
}