refactor: new asset and shape resize

pull/356/head
Allison Ryan 3 years ago
parent 8957b96ae3
commit ce143a6bf7

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

@ -13,12 +13,10 @@ class Slingshots extends Component with ZIndex {
: super( : super(
children: [ children: [
Slingshot( Slingshot(
length: 5.64,
angle: -0.017, angle: -0.017,
spritePath: Assets.images.slingshot.upper.keyName, spritePath: Assets.images.slingshot.upper.keyName,
)..initialPosition = Vector2(22.3, -1.58), )..initialPosition = Vector2(22.7, -0.1),
Slingshot( Slingshot(
length: 3.46,
angle: -0.468, angle: -0.468,
spritePath: Assets.images.slingshot.lower.keyName, spritePath: Assets.images.slingshot.lower.keyName,
)..initialPosition = Vector2(24.7, 6.2), )..initialPosition = Vector2(24.7, 6.2),
@ -34,11 +32,9 @@ class Slingshots extends Component with ZIndex {
class Slingshot extends BodyComponent with InitialPosition { class Slingshot extends BodyComponent with InitialPosition {
/// {@macro slingshot} /// {@macro slingshot}
Slingshot({ Slingshot({
required double length,
required double angle, required double angle,
required String spritePath, required String spritePath,
}) : _length = length, }) : _angle = angle,
_angle = angle,
super( super(
children: [ children: [
_SlinghsotSpriteComponent(spritePath, angle: angle), _SlinghsotSpriteComponent(spritePath, angle: angle),
@ -47,29 +43,28 @@ class Slingshot extends BodyComponent with InitialPosition {
renderBody: false, renderBody: false,
); );
final double _length;
final double _angle; final double _angle;
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
const length = 3.46;
const circleRadius = 1.55; const circleRadius = 1.55;
final topCircleShape = CircleShape()..radius = circleRadius; final topCircleShape = CircleShape()..radius = circleRadius;
topCircleShape.position.setValues(0, -_length / 2); topCircleShape.position.setValues(0, -length / 2);
final bottomCircleShape = CircleShape()..radius = circleRadius; final bottomCircleShape = CircleShape()..radius = circleRadius;
bottomCircleShape.position.setValues(0, _length / 2); bottomCircleShape.position.setValues(0, length / 2);
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 rightEdgeShape = EdgeShape() final rightEdgeShape = EdgeShape()
..set( ..set(
Vector2(-circleRadius, _length / 2), Vector2(-circleRadius, length / 2),
Vector2(-circleRadius, -_length / 2), Vector2(-circleRadius, -length / 2),
); );
return [ return [

Loading…
Cancel
Save