From da458ec1231bdf4d6113a7921e1e0ffbe1f49642 Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 28 Mar 2022 20:38:45 +0100 Subject: [PATCH] feat: positioned FlutterForest bumpers --- lib/game/components/board.dart | 7 +---- lib/game/components/flutter_forest.dart | 42 ++++++++++++++++--------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lib/game/components/board.dart b/lib/game/components/board.dart index c771b9d8..34ef4d33 100644 --- a/lib/game/components/board.dart +++ b/lib/game/components/board.dart @@ -19,12 +19,7 @@ class Board extends Component { spacing: 2, ); - final flutterForest = FlutterForest( - position: Vector2( - PinballGame.boardBounds.center.dx + 20, - PinballGame.boardBounds.center.dy + 48, - ), - ); + final flutterForest = FlutterForest(); await addAll([ bottomGroup, diff --git a/lib/game/components/flutter_forest.dart b/lib/game/components/flutter_forest.dart index 51dcd90a..31ea8c2b 100644 --- a/lib/game/components/flutter_forest.dart +++ b/lib/game/components/flutter_forest.dart @@ -1,5 +1,7 @@ // ignore_for_file: avoid_renaming_method_parameters +import 'dart:math' as math; + import 'package:flame/components.dart'; import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; @@ -19,12 +21,6 @@ import 'package:pinball_components/pinball_components.dart'; class FlutterForest extends Component with HasGameRef, BlocComponent { /// {@macro flutter_forest} - FlutterForest({ - required this.position, - }); - - /// The position of the [FlutterForest] on the [Board]. - final Vector2 position; @override bool listenWhen(GameState? previousState, GameState newState) { @@ -36,7 +32,11 @@ class FlutterForest extends Component @override void onNewState(GameState state) { super.onNewState(state); - gameRef.addFromBlueprint(BallBlueprint(position: position)); + gameRef.addFromBlueprint( + BallBlueprint( + position: Vector2(17.2, 52.7), + ), + ); } @override @@ -45,11 +45,11 @@ class FlutterForest extends Component // TODO(alestiago): adjust positioning once sprites are added. final smallLeftNest = SmallDashNestBumper(id: 'small_left_nest') - ..initialPosition = position + Vector2(-4.8, 2.8); + ..initialPosition = Vector2(8.95, 51.95); final smallRightNest = SmallDashNestBumper(id: 'small_right_nest') - ..initialPosition = position + Vector2(0.5, -5.5); + ..initialPosition = Vector2(23.3, 46.75); final bigNest = BigDashNestBumper(id: 'big_nest') - ..initialPosition = position; + ..initialPosition = Vector2(18.55, 59.35); await addAll([ smallLeftNest, @@ -66,7 +66,11 @@ class FlutterForest extends Component abstract class DashNestBumper extends BodyComponent with ScorePoints, InitialPosition { /// {@macro dash_nest_bumper} - DashNestBumper({required this.id}); + DashNestBumper({required this.id}) { + paint = Paint() + ..color = Colors.blue.withOpacity(0.5) + ..style = PaintingStyle.fill; + } /// Unique identifier for this [DashNestBumper]. /// @@ -97,7 +101,11 @@ class BigDashNestBumper extends DashNestBumper { @override Body createBody() { - final shape = CircleShape()..radius = 2.5; + final shape = EllipseShape( + center: Vector2.zero(), + majorRadius: 4.85, + minorRadius: 3.95, + )..rotate(math.pi / 2); final fixtureDef = FixtureDef(shape); final bodyDef = BodyDef() @@ -119,8 +127,14 @@ class SmallDashNestBumper extends DashNestBumper { @override Body createBody() { - final shape = CircleShape()..radius = 1; - final fixtureDef = FixtureDef(shape); + final shape = EllipseShape( + center: Vector2.zero(), + majorRadius: 3, + minorRadius: 2.25, + )..rotate(math.pi / 2); + final fixtureDef = FixtureDef(shape) + ..friction = 0 + ..restitution = 4; final bodyDef = BodyDef() ..position = initialPosition