From 5883f3eb42d98828be456067a0b42bf61c158f57 Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 14 Mar 2022 11:07:08 +0000 Subject: [PATCH] feat: removed friction from SlingShot --- lib/game/components/sling_shot.dart | 7 +++++-- test/game/components/sling_shot_test.dart | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/game/components/sling_shot.dart b/lib/game/components/sling_shot.dart index cca72622..2e77b69a 100644 --- a/lib/game/components/sling_shot.dart +++ b/lib/game/components/sling_shot.dart @@ -49,7 +49,8 @@ class SlingShot extends BodyComponent { } final triangle = PolygonShape()..set(triangleVertices); - fixtures.add(FixtureDef(triangle)); + final triangleFixture = FixtureDef(triangle)..friction = 0; + fixtures.add(triangleFixture); final kicker = EdgeShape() ..set( @@ -57,7 +58,9 @@ class SlingShot extends BodyComponent { triangleVertices.last, ); // TODO(alestiago): Play with restitution value once game is bundled. - final kickerFixtureDef = FixtureDef(kicker)..restitution = 20.0; + final kickerFixtureDef = FixtureDef(kicker) + ..restitution = 20.0 + ..friction = 0; fixtures.add(kickerFixtureDef); return fixtures; diff --git a/test/game/components/sling_shot_test.dart b/test/game/components/sling_shot_test.dart index 1df704b4..d617b3e2 100644 --- a/test/game/components/sling_shot_test.dart +++ b/test/game/components/sling_shot_test.dart @@ -66,6 +66,17 @@ void main() { expect((fixture.shape as PolygonShape).vertices.length, equals(3)); }, ); + + flameTester.test( + 'has no friction', + (game) async { + final slingShot = SlingShot(position: Vector2.zero()); + await game.ensureAdd(slingShot); + + final fixture = slingShot.body.fixtures[0]; + expect(fixture.friction, equals(0)); + }, + ); }); group('second fixture', () { @@ -100,6 +111,17 @@ void main() { expect(fixture.restitution, greaterThan(0)); }, ); + + flameTester.test( + 'has no friction', + (game) async { + final slingShot = SlingShot(position: Vector2.zero()); + await game.ensureAdd(slingShot); + + final fixture = slingShot.body.fixtures[1]; + expect(fixture.friction, equals(0)); + }, + ); }); }); }