bounceOffWall method
Returns the direction to bounce off a wall.
If vertical
is true
, the wall is vertical; otherwise, the wall is
horizontal.
Implementation
LavaDirection bounceOffWall(bool vertical) {
final double newAngle =
vertical ? (180.0 - degrees) % 360 : (-degrees) % 360;
final LavaDirection newDirection = LavaDirection.values.firstWhere(
(dir) => dir.degrees == newAngle,
orElse: () => opposite,
);
if (_chooseChaos) return newDirection._neighbor;
return newDirection;
}