From 8e8cfdef46d481a4133ccad0d09d76aee48819fa Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Mon, 18 Apr 2022 15:26:14 +0200 Subject: [PATCH] fix: fixed merge conflicts on plunger --- lib/game/components/launcher.dart | 4 +- .../lib/src/components/plunger.dart | 70 +++++++++++++++---- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/lib/game/components/launcher.dart b/lib/game/components/launcher.dart index 656dd978..f3238152 100644 --- a/lib/game/components/launcher.dart +++ b/lib/game/components/launcher.dart @@ -16,8 +16,8 @@ class Launcher extends Forge2DBlueprint { @override void build(Forge2DGame gameRef) { - plunger = ControlledPlunger(compressionDistance: 20) //12.3 - ..initialPosition = Vector2(38.5, -20); + plunger = ControlledPlunger(compressionDistance: 12.3) + ..initialPosition = Vector2(40.1, 38); final _rocket = RocketSpriteComponent()..position = Vector2(43, 62); diff --git a/packages/pinball_components/lib/src/components/plunger.dart b/packages/pinball_components/lib/src/components/plunger.dart index f01c007c..04cc71c4 100644 --- a/packages/pinball_components/lib/src/components/plunger.dart +++ b/packages/pinball_components/lib/src/components/plunger.dart @@ -21,18 +21,39 @@ class Plunger extends BodyComponent with InitialPosition, Layered { /// Distance the plunger can lower. final double compressionDistance; + List _createFixtureDefs() { + final fixturesDef = []; + + final leftShapeVertices = [ + Vector2(0, 0), + Vector2(-1.4, 0), + Vector2(-1.4, -1.2), + Vector2(0, -0.3), + ]..map((vector) => vector.rotate(BoardDimensions.perspectiveAngle)) + .toList(); + final leftTriangleShape = PolygonShape()..set(leftShapeVertices); + + final leftTriangleFixtureDef = FixtureDef(leftTriangleShape)..density = 80; + fixturesDef.add(leftTriangleFixtureDef); + + final rightShapeVertices = [ + Vector2(0, 0), + Vector2(1.4, 0), + Vector2(1.4, -1.2), + Vector2(0, -0.3), + ]..map((vector) => vector.rotate(BoardDimensions.perspectiveAngle)) + .toList(); + final rightTriangleShape = PolygonShape()..set(rightShapeVertices); + + final rightTriangleFixtureDef = FixtureDef(rightTriangleShape) + ..density = 80; + fixturesDef.add(rightTriangleFixtureDef); + + return fixturesDef; + } + @override Body createBody() { - final shape = PolygonShape() - ..setAsBox( - 1.35, - 0.5, - Vector2.zero(), - BoardDimensions.perspectiveAngle, - ); - - final fixtureDef = FixtureDef(shape)..density = 80; - final bodyDef = BodyDef( position: initialPosition, userData: this, @@ -40,7 +61,9 @@ class Plunger extends BodyComponent with InitialPosition, Layered { gravityScale: Vector2.zero(), ); - return world.createBody(bodyDef)..createFixture(fixtureDef); + final body = world.createBody(bodyDef); + _createFixtureDefs().forEach(body.createFixture); + return body; } /// Set a constant downward velocity on the [Plunger]. @@ -77,12 +100,35 @@ class Plunger extends BodyComponent with InitialPosition, Layered { Future onLoad() async { await super.onLoad(); await _anchorToJoint(); - renderBody = false; + renderBody = true; await add(_PlungerSpriteComponent()); } } class _PlungerSpriteComponent extends SpriteComponent with HasGameRef { + /* + late final SpriteAnimation _pullAnimation; + + late final SpriteAnimation _releaseAnimation; + + void pull() { + print('PLAYING pullAnimation'); + if (animation != _pullAnimation) { + print('set animation to _pullAnimation'); + animation = _pullAnimation; + } + //playing = true; + } + + void release() { + print('PLAYING releaseAnimation'); + if (animation != _releaseAnimation) { + print('set animation to _releaseAnimation'); + animation = _releaseAnimation; + //playing = true; + } + } + */ @override Future onLoad() async { await super.onLoad();