diff --git a/assets/images/components/background.png b/assets/images/components/background.png new file mode 100644 index 00000000..8b8fdf77 Binary files /dev/null and b/assets/images/components/background.png differ diff --git a/lib/game/components/board.dart b/lib/game/components/board.dart index 85d56f08..1f96120e 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(); // TODO(alestiago): adjust positioning to real design. final dino = ChromeDino() 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 diff --git a/lib/game/game_assets.dart b/lib/game/game_assets.dart index fdc1f332..648532cf 100644 --- a/lib/game/game_assets.dart +++ b/lib/game/game_assets.dart @@ -9,6 +9,7 @@ extension PinballGameAssetsX on PinballGame { await Future.wait([ images.load(components.Assets.images.ball.keyName), images.load(Assets.images.components.flipper.path), + images.load(Assets.images.components.background.path), images.load(Assets.images.components.spaceship.androidTop.path), images.load(Assets.images.components.spaceship.androidBottom.path), images.load(Assets.images.components.spaceship.lower.path), diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 2a8ddd42..89063a27 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -2,13 +2,15 @@ import 'dart:async'; import 'dart:math' as math; +import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame/input.dart'; import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/flame/blueprint.dart'; import 'package:pinball/game/game.dart'; -import 'package:pinball_theme/pinball_theme.dart'; +import 'package:pinball/gen/assets.gen.dart'; +import 'package:pinball_theme/pinball_theme.dart' hide Assets; class PinballGame extends Forge2DGame with FlameBloc, HasKeyboardHandlerComponents { @@ -48,7 +50,7 @@ class PinballGame extends Forge2DGame // Fix camera on the center of the board. camera - ..followVector2(Vector2.zero()) + ..followVector2(Vector2(0, -7.8)) ..zoom = size.y / 16; } @@ -93,6 +95,29 @@ class PinballGame extends Forge2DGame class DebugPinballGame extends PinballGame with TapDetector { DebugPinballGame({required PinballTheme theme}) : super(theme: theme); + @override + Future onLoad() async { + await super.onLoad(); + await _loadBackground(); + } + + // TODO(alestiago): Move to PinballGame once we have the real background + // component. + Future _loadBackground() async { + final sprite = await loadSprite( + Assets.images.components.background.path, + ); + final spriteComponent = SpriteComponent( + sprite: sprite, + size: Vector2(120, 160), + anchor: Anchor.center, + ) + ..position = Vector2(0, -7.8) + ..priority = -1; + + await add(spriteComponent); + } + @override void onTapUp(TapUpInfo info) { addFromBlueprint(BallBlueprint(position: info.eventPosition.game)); diff --git a/lib/gen/assets.gen.dart b/lib/gen/assets.gen.dart index 6e81fe77..8c228e16 100644 --- a/lib/gen/assets.gen.dart +++ b/lib/gen/assets.gen.dart @@ -3,6 +3,8 @@ /// FlutterGen /// ***************************************************** +// ignore_for_file: directives_ordering,unnecessary_import + import 'package:flutter/widgets.dart'; class $AssetsImagesGen { @@ -15,8 +17,14 @@ class $AssetsImagesGen { class $AssetsImagesComponentsGen { const $AssetsImagesComponentsGen(); + /// File path: assets/images/components/background.png + AssetGenImage get background => + const AssetGenImage('assets/images/components/background.png'); + + /// File path: assets/images/components/flipper.png AssetGenImage get flipper => const AssetGenImage('assets/images/components/flipper.png'); + $AssetsImagesComponentsSpaceshipGen get spaceship => const $AssetsImagesComponentsSpaceshipGen(); } @@ -24,14 +32,23 @@ class $AssetsImagesComponentsGen { class $AssetsImagesComponentsSpaceshipGen { const $AssetsImagesComponentsSpaceshipGen(); + /// File path: assets/images/components/spaceship/android-bottom.png AssetGenImage get androidBottom => const AssetGenImage( 'assets/images/components/spaceship/android-bottom.png'); + + /// File path: assets/images/components/spaceship/android-top.png AssetGenImage get androidTop => const AssetGenImage('assets/images/components/spaceship/android-top.png'); + + /// File path: assets/images/components/spaceship/lower.png AssetGenImage get lower => const AssetGenImage('assets/images/components/spaceship/lower.png'); + + /// File path: assets/images/components/spaceship/saucer.png AssetGenImage get saucer => const AssetGenImage('assets/images/components/spaceship/saucer.png'); + + /// File path: assets/images/components/spaceship/upper.png AssetGenImage get upper => const AssetGenImage('assets/images/components/spaceship/upper.png'); } diff --git a/test/game/components/flutter_forest_test.dart b/test/game/components/flutter_forest_test.dart index f960796c..0dd9212d 100644 --- a/test/game/components/flutter_forest_test.dart +++ b/test/game/components/flutter_forest_test.dart @@ -1,7 +1,6 @@ // ignore_for_file: cascade_invocations import 'package:bloc_test/bloc_test.dart'; -import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; @@ -19,7 +18,7 @@ void main() { 'loads correctly', (game) async { await game.ready(); - final flutterForest = FlutterForest(position: Vector2(0, 0)); + final flutterForest = FlutterForest(); await game.ensureAdd(flutterForest); expect(game.contains(flutterForest), isTrue); @@ -29,7 +28,7 @@ void main() { flameTester.test( 'onNewState adds a new ball', (game) async { - final flutterForest = FlutterForest(position: Vector2(0, 0)); + final flutterForest = FlutterForest(); await game.ready(); await game.ensureAdd(flutterForest);