NAME

Physics::Balls::Strike - one shot, as the integers a client sends

VERSION

Version 0.06

SYNOPSIS

my $strike = Physics::Balls::Strike->new(ball => 0, dx => 707107, dy => -707107, power => 640, sx => 0, sy => 300);
my $out = $strike->play($world, \@layout);

# a delivery whose surface changes once it passes y = 32.007 m
my $swept = Physics::Balls::Strike->new(ball => 7, dx => 0, dy => 1_000_000, power => 500, sy => 400,
    adjust => 1, adjust_at => 3200700, adjust_axis => 1, adjust_dir => 1, adjust_mu => 600, adjust_curve => 350);

DESCRIPTION

The direction is dx, dy in plus or minus 1,000,000 (normalised inside the engine with one square root), power 0 to 1000 (the speed is 0.3 + (power/1000)^2 (vmax - 0.3) so low power is fine-grained), and the tip offset sx, sy in thousandths of the radius, clamped to half a radius. Integers, so that a client cannot send a float two encoders would spell differently. validate refuses anything else with a Physics::Balls::Error rather than dying.

The adjust

A shot may say that the surface under the struck ball changes partway down its run: once the ball's centre crosses a line, in one direction, its friction and its curve are multiplied by two factors, once, for the rest of the shot. That is a swept path, a fast strip or a damp patch; the engine does not know which. The crossing is an adjust event in the outcome, and every segment before it is bit-identical to the same delivery with no adjust, which is what lets a game show a delivery, ask a question at the line, and then play the same delivery again with the answer applied.

The release roll

Since 0.04 a shot may say how the ball is rolling when it leaves the hand: spin is the size of its roll velocity in thousandths of its speed, 0 to 1000, and tx, ty the roll's direction in plus or minus 1,000,000. A roll along the line of the shot is what the tip offset sy gives; a roll across it makes the ball slide on a parabola until its slip closes, which is how a bowling ball hooks. With spin 0 the shot is exactly what it was.

my $hook = Physics::Balls::Strike->new(ball => 0, dx => 0, dy => 1_000_000, power => 915,
    tx => -566529, ty => 824042, spin => 485);

ATTRIBUTES

ball

The id struck, default 0.

dx

dy

power

sx

sy

trace

When true the outcome carries the energy after every event.

adjust

True to apply the adjust; default 0, and then the other adjust fields are ignored.

adjust_at

The line, an integer in hundredths of a millimetre.

adjust_axis

0 for a line of constant x, 1 for a line of constant y; default 1.

adjust_dir

1 to fire when the coordinate increases through the line, -1 when it decreases; default 1.

adjust_mu

adjust_curve

The factors in thousandths, default 1000 (unchanged).

tx

ty

spin

The release roll: a direction in plus or minus 1,000,000 and a size in thousandths of the release speed, 0 to 1000. Default 0, no roll beyond the tip offset's.

METHODS

validate

my $err = $strike->validate($world, \@layout);

Undef when the shot and the layout are acceptable, else the error. Two balls may sit touching, and a tenth of a millimetre inside each other, because a tight rack rounded to hundredths does that and the engine treats it as contact; any closer is overlap. The touching distance is the world's reach for the two rows' kinds.

rows

The layout as plain rows, whatever it was given as.

play

my $out = $strike->play($world, \@layout);

A Physics::Balls::Outcome, or the Physics::Balls::Error that refused it.