← hex_walk · API reference · source
hex_walk moves a first-person body through a world of walls. You keep a Place (its walls, door leaves and ladders) and a Body (where it stands and which way it faces), and call walk_step once a frame with how long the frame took and whether the walk goes forward or back. The ground and the floors are yours: a routine answering the height the feet stand at under a point.
use hex_walk::*;
fn ground(_x: float, _y: float, _from: float) -> float { 0.0 }
fn main() {
a wall along y = 2 with a doorway a metre wide, and a door in it hinged at its west side, shut
wall_a = Stretch { sr_ax: -4.0, sr_ay: 2.0, sr_bx: -0.5, sr_by: 2.0, sr_z0: 0.0, sr_z1: 2.5 };
wall_b = Stretch { sr_ax: 0.5, sr_ay: 2.0, sr_bx: 4.0, sr_by: 2.0, sr_z0: 0.0, sr_z1: 2.5 };
pl = place_new([wall_a, wall_b]);
pl.pl_leaves += [leaf_of((-0.5, 2.0, 1.0, 0.0, 1.0, 0.0, 2.2), 0.05, 0)];
a body a little off the doorway, facing north (yaw 0), walking for a second at 60 frames
w = walker_new();
b = body_new(0.36, 0.0, 0.0, 0.0);
for _ in 0..60 {
_moved = walk_step(w, pl, b, 1.0, 1.0 / 60.0, ground);
_swung = leaves_swing(w, pl, b, 1.0 / 60.0, false);
}
it eased into the doorway (from x 0.36 to under 0.3: the doorway's side is at 0.5, the body 0.2 wide), pushed the door open and walked through
assert(b.bd_y > 2.5 && b.bd_x < 0.3, "eased in and through the doorway: {b.bd_x}, {b.bd_y}");
assert(pl.pl_leaves[0].lf_value > 0.0, "the door pushed open: {pl.pl_leaves[0].lf_value}");
println("through at ({b.bd_x:.3}, {b.bd_y:.2}), the door {pl.pl_leaves[0].lf_value:.2} turns open");
}