|
|
@ -1,4 +1,5 @@
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'dart:math' as math;
|
|
|
|
import 'dart:ui';
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame/components.dart';
|
|
|
@ -107,7 +108,8 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
|
|
|
|
unawaited(gameRef.add(effect));
|
|
|
|
unawaited(gameRef.add(effect));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_rescale();
|
|
|
|
_rescaleSize();
|
|
|
|
|
|
|
|
_setPositionalGravity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Applies a boost on this [Ball].
|
|
|
|
/// Applies a boost on this [Ball].
|
|
|
@ -116,19 +118,36 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
|
|
|
|
_boostTimer = _boostDuration;
|
|
|
|
_boostTimer = _boostDuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _rescale() {
|
|
|
|
void _rescaleSize() {
|
|
|
|
final boardHeight = BoardDimensions.bounds.height;
|
|
|
|
final boardHeight = BoardDimensions.bounds.height;
|
|
|
|
const maxShrinkAmount = BoardDimensions.perspectiveShrinkFactor;
|
|
|
|
const maxShrinkValue = BoardDimensions.perspectiveShrinkFactor;
|
|
|
|
|
|
|
|
|
|
|
|
final adjustedYPosition = -body.position.y + (boardHeight / 2);
|
|
|
|
final standardizedYPosition = body.position.y + (boardHeight / 2);
|
|
|
|
|
|
|
|
|
|
|
|
final scaleFactor = ((boardHeight - adjustedYPosition) /
|
|
|
|
final scaleFactor = maxShrinkValue +
|
|
|
|
BoardDimensions.shrinkAdjustedHeight) +
|
|
|
|
((standardizedYPosition / boardHeight) * (1 - maxShrinkValue));
|
|
|
|
maxShrinkAmount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body.fixtures.first.shape.radius = (size.x / 2) * scaleFactor;
|
|
|
|
body.fixtures.first.shape.radius = (size.x / 2) * scaleFactor;
|
|
|
|
_spriteComponent.scale = Vector2.all(scaleFactor);
|
|
|
|
_spriteComponent.scale = Vector2.all(scaleFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _setPositionalGravity() {
|
|
|
|
|
|
|
|
final defaultGravity = gameRef.world.gravity.y;
|
|
|
|
|
|
|
|
final maxXDeviationFromCenter = BoardDimensions.bounds.width / 2;
|
|
|
|
|
|
|
|
const maxXGravityPercentage =
|
|
|
|
|
|
|
|
(1 - BoardDimensions.perspectiveShrinkFactor) / 2;
|
|
|
|
|
|
|
|
final xDeviationFromCenter = body.position.x;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final positionalXForce = ((xDeviationFromCenter / maxXDeviationFromCenter) *
|
|
|
|
|
|
|
|
maxXGravityPercentage) *
|
|
|
|
|
|
|
|
defaultGravity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final positionalYForce = math.sqrt(
|
|
|
|
|
|
|
|
math.pow(defaultGravity, 2) - math.pow(positionalXForce, 2),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body.gravityOverride = Vector2(positionalXForce, positionalYForce);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _BallSpriteComponent extends SpriteComponent with HasGameRef {
|
|
|
|
class _BallSpriteComponent extends SpriteComponent with HasGameRef {
|
|
|
|