use nightshade_api::prelude::*;
struct Playground {
counter: Entity,
shots: u32,
}
fn main() {
run(
|world| {
spawn_floor(world, 20.0);
for level in 0..6 {
for column in 0..(6 - level) {
spawn_object(
world,
Object {
position: vec3(
column as f32 + level as f32 * 0.5 - 3.0,
level as f32 + 0.5,
0.0,
),
color: GREEN,
body: Body::Dynamic { mass: 1.0 },
..Object::default()
},
);
}
}
let counter = spawn_text(world, "shots: 0", ScreenAnchor::TopLeft);
spawn_text(
world,
"space fires a ball, click pops a block upward",
ScreenAnchor::BottomLeft,
);
Playground { counter, shots: 0 }
},
|world, state| {
if key_pressed(world, KeyCode::Space) {
let muzzle = camera_position(world);
let ball = spawn_object(
world,
Object {
shape: Shape::Sphere,
position: muzzle,
scale: vec3(0.3, 0.3, 0.3),
color: ORANGE,
body: Body::Dynamic { mass: 3.0 },
},
);
let velocity = camera_forward(world) * 25.0;
set_velocity(world, ball, velocity);
state.shots += 1;
set_text(world, state.counter, &format!("shots: {}", state.shots));
}
if let Some(target) = clicked_entity(world) {
push(world, target, vec3(0.0, 6.0, 0.0));
let pop_position = position(world, target);
emit_burst(world, pop_position, ORANGE, 60);
shake_camera(world, 0.05, 0.2);
}
},
)
.unwrap();
}