use nightshade_api::prelude::*;
struct World3d {
hint: Entity,
terrain_on: bool,
grass_on: bool,
snow: f32,
}
fn main() {
run(setup, update).unwrap();
}
fn setup(world: &mut World) -> World3d {
set_window_title(world, "Terrain Walk");
set_background(world, Background::Sky);
show_grid(world, false);
set_bloom(world, true);
enable_terrain(world, 1337);
set_terrain_height_range(world, 0.0, 40.0);
set_terrain_snow_height(world, 26.0);
enable_grass(world);
first_person(world, vec3(0.0, 6.0, 0.0));
let hint = spawn_text(
world,
"WASD walk T terrain G grass [ ] snow line",
ScreenAnchor::BottomLeft,
);
World3d {
hint,
terrain_on: true,
grass_on: true,
snow: 26.0,
}
}
fn update(world: &mut World, state: &mut World3d) {
if key_pressed(world, KeyCode::KeyT) {
state.terrain_on = !state.terrain_on;
if state.terrain_on {
enable_terrain(world, 1337);
} else {
disable_terrain(world);
}
}
if key_pressed(world, KeyCode::KeyG) {
state.grass_on = !state.grass_on;
if state.grass_on {
enable_grass(world);
} else {
disable_grass(world);
}
}
if key_pressed(world, KeyCode::BracketLeft) {
state.snow = (state.snow - 2.0).max(0.0);
set_terrain_snow_height(world, state.snow);
}
if key_pressed(world, KeyCode::BracketRight) {
state.snow = (state.snow + 2.0).min(40.0);
set_terrain_snow_height(world, state.snow);
}
set_text(
world,
state.hint,
&format!(
"terrain {} grass {} snow {:.0}",
state.terrain_on, state.grass_on, state.snow
),
);
}