use bevy::prelude::*;
mod common;
use common::body::{self, Blow, Chunk};
use common::recorder::Recorder;
use common::{arg, light_and_floor};
const WIDTH: u32 = 720;
const HEIGHT: u32 = 540;
const DT: f32 = 1.0 / 30.0 * 0.55;
const GRANULARITY: usize = 3;
const SOFTEN: f32 = 0.5;
const SCRIPT: [(u32, Blow, Vec3); 5] = [
(18, Blow::Projectile, Vec3::new(-0.30, 0.16, 0.0)),
(48, Blow::Projectile, Vec3::new(0.00, 0.48, 0.0)),
(80, Blow::Slash, Vec3::new(0.30, 0.16, 0.0)),
(112, Blow::SweptBlade, Vec3::new(0.00, -0.30, 0.0)),
(144, Blow::Blast, Vec3::new(0.00, 0.00, 0.0)),
];
const TAIL: u32 = 34;
fn main() {
let out = arg("--out").unwrap_or_else(|| "frames-sever".to_string());
let camera = Transform::from_xyz(2.25, 1.35, 2.95).looking_at(Vec3::new(0.0, 0.76, 0.0), Vec3::Y);
let Some(mut rec) = Recorder::new(WIDTH, HEIGHT, camera, &out) else { return };
light_and_floor(rec.world());
let baked = body::Baked::bake(rec.world(), SOFTEN, &[], &[GRANULARITY]);
let materials = body::BodyMaterials::new(rec.world());
let damage = body::Damage::fresh(&baked, GRANULARITY);
rec.world().insert_resource(baked);
rec.world().insert_resource(materials);
rec.world().insert_resource(damage);
body::stand(rec.world(), GRANULARITY);
rec.warm_up(4);
rec.app().main.add_systems(Update, integrate);
let last = SCRIPT.last().map(|(f, _, _)| *f).unwrap_or(0);
for frame in 0..last + TAIL {
for (at_frame, blow, at) in SCRIPT {
if frame == at_frame {
body::strike(rec.world(), blow, at);
}
}
rec.shoot();
}
let n = rec.finish();
info!("capture_sever: wrote {n} frames to {out}");
}
fn integrate(mut chunks: Query<(&mut Chunk, &mut Transform)>) {
for (mut chunk, mut transform) in &mut chunks {
body::integrate(&mut chunk, &mut transform, DT);
}
}