From a3e3b9c21537a85946ee85cf0a47c17a670ec679 Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Fri, 25 Mar 2022 09:04:03 +0100 Subject: [PATCH] refactor: refactored launcher ramp --- lib/game/components/launcher_ramp.dart | 57 ++++--------------- .../components/shapes/ellipse_shape_test.dart | 2 - 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/lib/game/components/launcher_ramp.dart b/lib/game/components/launcher_ramp.dart index a8e2d0f5..696435d9 100644 --- a/lib/game/components/launcher_ramp.dart +++ b/lib/game/components/launcher_ramp.dart @@ -9,7 +9,7 @@ import 'package:pinball/flame/blueprint.dart'; import 'package:pinball/game/game.dart'; import 'package:pinball_components/pinball_components.dart'; -/// A [Blueprint] which creates the launcher ramp. +/// A [Blueprint] which creates the [LauncherRamp]. class Launcher extends Forge2DBlueprint { /// Width between walls of the pathway. static const width = 5.0; @@ -28,14 +28,10 @@ class Launcher extends Forge2DBlueprint { RampOpeningBallContactCallback<_LauncherRampOpening>(), ]); - final straightPath = LauncherStraightRamp() + final curvedPath = LauncherRamp() ..initialPosition = position + Vector2(1.7, 0) ..layer = Layer.launcher; - final curvedPath = LauncherCurveRamp() - ..initialPosition = position + Vector2(-12, 59.3) - ..layer = Layer.launcher; - final leftOpening = _LauncherRampOpening(rotation: math.pi / 2) ..initialPosition = position + Vector2(-11.6, 66.3) ..layer = Layer.opening; @@ -44,7 +40,6 @@ class Launcher extends Forge2DBlueprint { ..layer = Layer.opening; addAll([ - straightPath, curvedPath, leftOpening, rightOpening, @@ -52,16 +47,16 @@ class Launcher extends Forge2DBlueprint { } } -/// {@template launcher_straight_ramp} -/// The green left ramp, where the [Ball] goes through when launched from the +/// {@template launcher_ramp} +/// The yellow right ramp, where the [Ball] goes through when launched from the /// [Plunger]. /// {@endtemplate} -class LauncherStraightRamp extends BodyComponent with InitialPosition, Layered { - /// {@macro launcher_straight_ramp} - LauncherStraightRamp() : super(priority: 2) { +class LauncherRamp extends BodyComponent with InitialPosition, Layered { + /// {@macro launcher_ramp} + LauncherRamp() : super(priority: 2) { layer = Layer.launcher; paint = Paint() - ..color = const Color.fromARGB(255, 34, 255, 0) + ..color = const Color.fromARGB(255, 251, 255, 0) ..style = PaintingStyle.stroke; } @@ -90,40 +85,8 @@ class LauncherStraightRamp extends BodyComponent with InitialPosition, Layered { final internalStraightFixtureDef = FixtureDef(internalStraightShape); fixturesDef.add(internalStraightFixtureDef); - return fixturesDef; - } - - @override - Body createBody() { - final bodyDef = BodyDef() - ..userData = this - ..position = initialPosition; - - final body = world.createBody(bodyDef); - _createFixtureDefs().forEach(body.createFixture); - - return body; - } -} - -/// {@template launcher_curve_ramp} -/// The yellow left ramp, where the [Ball] goes through when launched from the -/// [Plunger]. -/// {@endtemplate} -class LauncherCurveRamp extends BodyComponent with InitialPosition, Layered { - /// {@macro launcher_curve_ramp} - LauncherCurveRamp() : super(priority: 2) { - layer = Layer.launcher; - paint = Paint() - ..color = const Color.fromARGB(255, 251, 255, 0) - ..style = PaintingStyle.stroke; - } - - List _createFixtureDefs() { - final fixturesDef = []; - final externalCurveShape = ArcShape( - center: initialPosition, + center: initialPosition + Vector2(-27.5, 119), arcRadius: Launcher.externalRadius, angle: math.pi / 2, rotation: 3 * math.pi / 2, @@ -155,7 +118,7 @@ class LauncherCurveRamp extends BodyComponent with InitialPosition, Layered { /// {@template launcher_ramp_opening} /// [RampOpening] with [Layer.launcher] to filter [Ball]s collisions -/// inside launcher ramp. +/// inside [LauncherRamp]. /// {@endtemplate} class _LauncherRampOpening extends RampOpening { /// {@macro launcher_ramp_opening} diff --git a/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart b/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart index 68d8ea28..e0327c76 100644 --- a/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart +++ b/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart @@ -1,5 +1,3 @@ -import 'dart:math' as math; - import 'package:flame/extensions.dart'; import 'package:flame/game.dart'; import 'package:flutter_test/flutter_test.dart';