use nightshade_api::prelude::*;
struct Juice {
gems: Vec<Entity>,
door: Entity,
door_open: bool,
}
fn main() {
run(
|world| {
show_grid(world, false);
set_bloom(world, true);
spawn_floor(world, 12.0);
let mut gems = Vec::new();
for index in 0..9 {
let angle = index as f32 / 9.0 * std::f32::consts::TAU;
let gem = spawn_object(
world,
Object {
shape: Shape::Sphere,
position: vec3(angle.cos() * 5.0, 0.6, angle.sin() * 5.0),
scale: vec3(0.6, 0.6, 0.6),
color: TEAL,
..Object::default()
},
);
gems.push(gem);
}
let door = spawn_object(
world,
Object {
position: vec3(0.0, 1.5, -8.0),
scale: vec3(4.0, 3.0, 0.4),
color: STEEL,
..Object::default()
},
);
emit_fire(world, vec3(0.0, 0.2, 0.0));
point_light(world, vec3(0.0, 1.2, 0.0), [1.0, 0.6, 0.2], 5.0);
spawn_text(
world,
"click a gem, O slides the door, B bursts",
ScreenAnchor::BottomLeft,
);
Juice {
gems,
door,
door_open: false,
}
},
|world, state| {
if let Some(target) = clicked_entity(world)
&& state.gems.contains(&target)
{
animate_scale(
world,
target,
vec3(1.0, 1.0, 1.0),
0.25,
EasingFunction::BackOut,
);
animate_color(world, target, GOLD, 0.25, EasingFunction::QuadOut);
let burst_position = position(world, target);
emit_burst(world, burst_position, GOLD, 80);
shake_camera(world, 0.08, 0.3);
}
if key_pressed(world, KeyCode::KeyO) {
state.door_open = !state.door_open;
let target_height = if state.door_open { 4.6 } else { 1.5 };
animate_position(
world,
state.door,
vec3(0.0, target_height, -8.0),
0.8,
EasingFunction::CubicInOut,
);
}
if key_pressed(world, KeyCode::KeyB) {
let center = camera_position(world) + camera_forward(world) * 6.0;
emit_burst(world, center, PINK, 200);
shake_camera(world, 0.2, 0.5);
}
},
)
.unwrap();
}