o-centored-attack 0.1.0

Deterministic vertical-strike geometry and impulse resolution for 2D games
Documentation
  • Coverage
  • 100%
    44 out of 44 items documented1 out of 32 items with examples
  • Size
  • Source code size: 18.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 468.8 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hidenoriuehara-art

o-centored-attack

o-centored-attack is a dependency-free 2D game-physics library for resolving attacks constrained to a vertical axis.

The vertical-strike principle

This crate gives a concrete meaning to 垂直に叩く理:

Keep the strike impulse vertical, let horizontal offset decide centeredness, and transfer the greatest force only when the attack is centered.

Resolution distinguishes horizontal misses, targets on the wrong side, and targets beyond reach. All geometry and force calculations use checked integer arithmetic.

Example

use o_centored_attack::{
    AttackOutcome, AxisPoint, TargetBox, VerticalAttack, VerticalDirection,
};

let attack = VerticalAttack::new(
    AxisPoint::new(0, 100),
    VerticalDirection::Down,
    100,
    10,
    1_000,
)?;
let target = TargetBox::new(AxisPoint::new(0, 20), 10, 10);

let AttackOutcome::Hit(impact) = attack.resolve(&target)? else {
    panic!("expected a hit");
};

assert_eq!(impact.centering_basis_points(), 10_000);
assert_eq!(impact.transmitted_force(), 1_000);
assert_eq!(impact.impulse_x(), 0);
assert_eq!(impact.impulse_y(), -1_000);

# Ok::<(), o_centored_attack::AttackError>(())

Coordinates are unit-agnostic. Positive Y is up, so downward impulses are negative and upward impulses are positive.

This crate provides game geometry only; it does not apply damage or mutate game entities.

License

MIT