|
|
@ -29,7 +29,7 @@ class Slingshots extends Component with ZIndex {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template slingshot}
|
|
|
|
/// {@template slingshot}
|
|
|
|
/// Elastic bumper that bounces the [Ball] off of its straight sides.
|
|
|
|
/// Elastic bumper that bounces the [Ball] off of its sides.
|
|
|
|
/// {@endtemplate}
|
|
|
|
/// {@endtemplate}
|
|
|
|
class Slingshot extends BodyComponent with InitialPosition {
|
|
|
|
class Slingshot extends BodyComponent with InitialPosition {
|
|
|
|
/// {@macro slingshot}
|
|
|
|
/// {@macro slingshot}
|
|
|
@ -42,7 +42,7 @@ class Slingshot extends BodyComponent with InitialPosition {
|
|
|
|
super(
|
|
|
|
super(
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
_SlinghsotSpriteComponent(spritePath, angle: angle),
|
|
|
|
_SlinghsotSpriteComponent(spritePath, angle: angle),
|
|
|
|
BumpingBehavior(strength: 10),
|
|
|
|
BumpingBehavior(strength: 20),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
renderBody: false,
|
|
|
|
renderBody: false,
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -56,37 +56,27 @@ class Slingshot extends BodyComponent with InitialPosition {
|
|
|
|
|
|
|
|
|
|
|
|
final topCircleShape = CircleShape()..radius = circleRadius;
|
|
|
|
final topCircleShape = CircleShape()..radius = circleRadius;
|
|
|
|
topCircleShape.position.setValues(0, -_length / 2);
|
|
|
|
topCircleShape.position.setValues(0, -_length / 2);
|
|
|
|
final topCircleFixtureDef = FixtureDef(topCircleShape);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final bottomCircleShape = CircleShape()..radius = circleRadius;
|
|
|
|
final bottomCircleShape = CircleShape()..radius = circleRadius;
|
|
|
|
bottomCircleShape.position.setValues(0, _length / 2);
|
|
|
|
bottomCircleShape.position.setValues(0, _length / 2);
|
|
|
|
final bottomCircleFixtureDef = FixtureDef(bottomCircleShape);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final leftEdgeShape = EdgeShape()
|
|
|
|
final leftEdgeShape = EdgeShape()
|
|
|
|
..set(
|
|
|
|
..set(
|
|
|
|
Vector2(circleRadius, _length / 2),
|
|
|
|
Vector2(circleRadius, _length / 2),
|
|
|
|
Vector2(circleRadius, -_length / 2),
|
|
|
|
Vector2(circleRadius, -_length / 2),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final leftEdgeShapeFixtureDef = FixtureDef(
|
|
|
|
|
|
|
|
leftEdgeShape,
|
|
|
|
|
|
|
|
restitution: 5,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final rightEdgeShape = EdgeShape()
|
|
|
|
final rightEdgeShape = EdgeShape()
|
|
|
|
..set(
|
|
|
|
..set(
|
|
|
|
Vector2(-circleRadius, _length / 2),
|
|
|
|
Vector2(-circleRadius, _length / 2),
|
|
|
|
Vector2(-circleRadius, -_length / 2),
|
|
|
|
Vector2(-circleRadius, -_length / 2),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final rightEdgeShapeFixtureDef = FixtureDef(
|
|
|
|
|
|
|
|
rightEdgeShape,
|
|
|
|
|
|
|
|
restitution: 5,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
topCircleFixtureDef,
|
|
|
|
FixtureDef(topCircleShape),
|
|
|
|
bottomCircleFixtureDef,
|
|
|
|
FixtureDef(bottomCircleShape),
|
|
|
|
leftEdgeShapeFixtureDef,
|
|
|
|
FixtureDef(leftEdgeShape),
|
|
|
|
rightEdgeShapeFixtureDef,
|
|
|
|
FixtureDef(rightEdgeShape),
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|