diff --git a/assets/images/components/dino-land-bottom.png b/assets/images/components/dino-land-bottom.png new file mode 100644 index 00000000..1839dda3 Binary files /dev/null and b/assets/images/components/dino-land-bottom.png differ diff --git a/lib/game/components/components.dart b/lib/game/components/components.dart index e19c607c..766a9d42 100644 --- a/lib/game/components/components.dart +++ b/lib/game/components/components.dart @@ -2,6 +2,7 @@ export 'board.dart'; export 'bonus_word.dart'; export 'chrome_dino.dart'; export 'controlled_ball.dart'; +export 'dino_wall.dart'; export 'flipper_controller.dart'; export 'flutter_forest.dart'; export 'jetpack_ramp.dart'; diff --git a/lib/game/components/dino_wall.dart b/lib/game/components/dino_wall.dart new file mode 100644 index 00000000..c44dc789 --- /dev/null +++ b/lib/game/components/dino_wall.dart @@ -0,0 +1,214 @@ +// ignore_for_file: avoid_renaming_method_parameters + +import 'package:flame/components.dart'; +import 'package:flame_forge2d/flame_forge2d.dart'; +import 'package:pinball/gen/assets.gen.dart'; +import 'package:pinball_components/pinball_components.dart' hide Assets; + +/// {@template dino_top_wall} +/// Wall located above dino, at the right of the board. +/// {@endtemplate} +class DinoTopWall extends BodyComponent with InitialPosition { + ///{@macro dino_top_wall} + DinoTopWall() : super(priority: 2); + + List _createFixtureDefs() { + final fixturesDef = []; + + final topStraightControlPoints = [ + Vector2(29.5, 35.1), + Vector2(28.4, 35.1), + ]; + final topStraightShape = EdgeShape() + ..set( + topStraightControlPoints.first, + topStraightControlPoints.last, + ); + final topStraightFixtureDef = FixtureDef(topStraightShape); + fixturesDef.add(topStraightFixtureDef); + + final topCurveControlPoints = [ + topStraightControlPoints.last, + Vector2(17.4, 26.38), + Vector2(25.5, 20.7), + ]; + final topCurveShape = BezierCurveShape( + controlPoints: topCurveControlPoints, + ); + fixturesDef.add(FixtureDef(topCurveShape)); + + final middleCurveControlPoints = [ + topCurveControlPoints.last, + Vector2(27.8, 20.1), + Vector2(26.8, 19.5), + ]; + final middleCurveShape = BezierCurveShape( + controlPoints: middleCurveControlPoints, + ); + fixturesDef.add(FixtureDef(middleCurveShape)); + + final bottomCurveControlPoints = [ + middleCurveControlPoints.last, + Vector2(21.15, 16), + Vector2(25.6, 15.2), + ]; + final bottomCurveShape = BezierCurveShape( + controlPoints: bottomCurveControlPoints, + ); + fixturesDef.add(FixtureDef(bottomCurveShape)); + + final bottomStraightControlPoints = [ + bottomCurveControlPoints.last, + Vector2(31, 14.5), + ]; + final bottomStraightShape = EdgeShape() + ..set( + bottomStraightControlPoints.first, + bottomStraightControlPoints.last, + ); + final bottomStraightFixtureDef = FixtureDef(bottomStraightShape); + fixturesDef.add(bottomStraightFixtureDef); + + return fixturesDef; + } + + @override + Body createBody() { + renderBody = false; + + final bodyDef = BodyDef() + ..userData = this + ..position = initialPosition + ..type = BodyType.static; + + final body = world.createBody(bodyDef); + _createFixtureDefs().forEach( + (fixture) => body.createFixture( + fixture + ..restitution = 0.1 + ..friction = 0, + ), + ); + + return body; + } + + @override + Future onLoad() async { + await super.onLoad(); + await _loadBackground(); + } + + Future _loadBackground() async { + final sprite = await gameRef.loadSprite( + Assets.images.components.dinoLandTop.path, + ); + final spriteComponent = SpriteComponent( + sprite: sprite, + size: Vector2(10.6, 27.7), + anchor: Anchor.center, + )..position = Vector2(27, -28.2); + + await add(spriteComponent); + } +} + +/// {@template dino_bottom_wall} +/// Wall located below dino, at the right of the board. +/// {@endtemplate} +class DinoBottomWall extends BodyComponent with InitialPosition { + ///{@macro dino_top_wall} + DinoBottomWall() : super(priority: 2); + + List _createFixtureDefs() { + final fixturesDef = []; + + final topStraightControlPoints = [ + Vector2(32.4, 8.3), + Vector2(25, 7.7), + ]; + final topStraightShape = EdgeShape() + ..set( + topStraightControlPoints.first, + topStraightControlPoints.last, + ); + final topStraightFixtureDef = FixtureDef(topStraightShape); + fixturesDef.add(topStraightFixtureDef); + + final topLeftCurveControlPoints = [ + topStraightControlPoints.last, + Vector2(21.8, 7), + Vector2(29.5, -13.8), + ]; + final topLeftCurveShape = BezierCurveShape( + controlPoints: topLeftCurveControlPoints, + ); + fixturesDef.add(FixtureDef(topLeftCurveShape)); + + final bottomLeftStraightControlPoints = [ + topLeftCurveControlPoints.last, + Vector2(31.8, -44.1), + ]; + final bottomLeftStraightShape = EdgeShape() + ..set( + bottomLeftStraightControlPoints.first, + bottomLeftStraightControlPoints.last, + ); + final bottomLeftStraightFixtureDef = FixtureDef(bottomLeftStraightShape); + fixturesDef.add(bottomLeftStraightFixtureDef); + + final bottomStraightControlPoints = [ + bottomLeftStraightControlPoints.last, + Vector2(37.8, -44.1), + ]; + final bottomStraightShape = EdgeShape() + ..set( + bottomStraightControlPoints.first, + bottomStraightControlPoints.last, + ); + final bottomStraightFixtureDef = FixtureDef(bottomStraightShape); + fixturesDef.add(bottomStraightFixtureDef); + + return fixturesDef; + } + + @override + Body createBody() { + renderBody = false; + + final bodyDef = BodyDef() + ..userData = this + ..position = initialPosition + ..type = BodyType.static; + + final body = world.createBody(bodyDef); + _createFixtureDefs().forEach( + (fixture) => body.createFixture( + fixture + ..restitution = 0.1 + ..friction = 0, + ), + ); + + return body; + } + + @override + Future onLoad() async { + await super.onLoad(); + await _loadBackground(); + } + + Future _loadBackground() async { + final sprite = await gameRef.loadSprite( + Assets.images.components.dinoLandBottom.path, + ); + final spriteComponent = SpriteComponent( + sprite: sprite, + size: Vector2(15.6, 54.8), + anchor: Anchor.center, + )..position = Vector2(31.7, 18); + + await add(spriteComponent); + } +} diff --git a/lib/game/components/wall.dart b/lib/game/components/wall.dart index 6f19ca56..030edc50 100644 --- a/lib/game/components/wall.dart +++ b/lib/game/components/wall.dart @@ -1,12 +1,8 @@ // ignore_for_file: avoid_renaming_method_parameters -import 'dart:math' as math; -import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; -import 'package:flutter/material.dart'; import 'package:pinball/game/game.dart'; -import 'package:pinball/gen/assets.gen.dart'; import 'package:pinball_components/pinball_components.dart' hide Assets; /// {@template wall} @@ -84,111 +80,3 @@ class BottomWallBallContactCallback extends ContactCallback { ball.children.whereType().first.lost(); } } - -/// {@template dino_top_wall} -/// Wall located above dino, at the right of the board. -/// {@endtemplate} -class DinoTopWall extends BodyComponent with InitialPosition { - ///{@macro dino_top_wall} - DinoTopWall() : super(priority: 2); - - List _createFixtureDefs() { - final fixturesDef = []; - - final topStraightControlPoints = [ - Vector2(29.5, 35.1), - Vector2(28.4, 35.1), - ]; - final topStraightShape = EdgeShape() - ..set( - topStraightControlPoints.first, - topStraightControlPoints.last, - ); - final topStraightFixtureDef = FixtureDef(topStraightShape); - fixturesDef.add(topStraightFixtureDef); - - final topCurveControlPoints = [ - topStraightControlPoints.last, - Vector2(17.4, 26.38), - Vector2(25.5, 20.7), - ]; - final topCurveShape = BezierCurveShape( - controlPoints: topCurveControlPoints, - ); - fixturesDef.add(FixtureDef(topCurveShape)); - - final middleCurveControlPoints = [ - topCurveControlPoints.last, - Vector2(27.8, 20.1), - Vector2(26.8, 19.5), - ]; - final middleCurveShape = BezierCurveShape( - controlPoints: middleCurveControlPoints, - ); - fixturesDef.add(FixtureDef(middleCurveShape)); - - final bottomCurveControlPoints = [ - middleCurveControlPoints.last, - Vector2(21.15, 16), - Vector2(25.6, 15.2), - ]; - final bottomCurveShape = BezierCurveShape( - controlPoints: bottomCurveControlPoints, - ); - fixturesDef.add(FixtureDef(bottomCurveShape)); - - final bottomStraightControlPoints = [ - bottomCurveControlPoints.last, - Vector2(31, 14.5), - ]; - final bottomStraightShape = EdgeShape() - ..set( - bottomStraightControlPoints.first, - bottomStraightControlPoints.last, - ); - final bottomStraightFixtureDef = FixtureDef(bottomStraightShape); - fixturesDef.add(bottomStraightFixtureDef); - - return fixturesDef; - } - - @override - Body createBody() { - renderBody = false; - - final bodyDef = BodyDef() - ..userData = this - ..position = initialPosition - ..type = BodyType.static; - - final body = world.createBody(bodyDef); - _createFixtureDefs().forEach( - (fixture) => body.createFixture( - fixture - ..restitution = 0.1 - ..friction = 0, - ), - ); - - return body; - } - - @override - Future onLoad() async { - await super.onLoad(); - await _loadBackground(); - } - - Future _loadBackground() async { - final sprite = await gameRef.loadSprite( - Assets.images.components.dinoLandTop.path, - ); - final spriteComponent = SpriteComponent( - sprite: sprite, - size: Vector2(10.6, 27.7), - anchor: Anchor.center, - )..position = Vector2(27, -28.2); - - await add(spriteComponent); - } -} diff --git a/lib/game/game_assets.dart b/lib/game/game_assets.dart index ee7b7900..f89a999c 100644 --- a/lib/game/game_assets.dart +++ b/lib/game/game_assets.dart @@ -14,6 +14,8 @@ extension PinballGameAssetsX on PinballGame { images.load(components.Assets.images.baseboard.left.keyName), images.load(components.Assets.images.baseboard.right.keyName), images.load(Assets.images.components.background.path), + images.load(Assets.images.components.dinoLandTop.path), + images.load(Assets.images.components.dinoLandBottom.path), ]); } } diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 3e5ad5dc..1f36a8d3 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -69,6 +69,9 @@ class PinballGame extends Forge2DGame await add( DinoTopWall()..initialPosition = Vector2(-2.4, 0), ); + await add( + DinoBottomWall()..initialPosition = Vector2(-2.4, 0), + ); } Future _addPlunger() async { @@ -111,7 +114,7 @@ class DebugPinballGame extends PinballGame with TapDetector { @override Future onLoad() async { await super.onLoad(); - await _loadBackground(); + //await _loadBackground(); } // TODO(alestiago): Move to PinballGame once we have the real background @@ -125,7 +128,7 @@ class DebugPinballGame extends PinballGame with TapDetector { size: Vector2(120, 160), anchor: Anchor.center, ) - ..position = Vector2(0, -15) + ..position = Vector2(0, -7.8) ..priority = -1; await add(spriteComponent); diff --git a/lib/gen/assets.gen.dart b/lib/gen/assets.gen.dart index 8ba5344e..42dc62ea 100644 --- a/lib/gen/assets.gen.dart +++ b/lib/gen/assets.gen.dart @@ -21,6 +21,10 @@ class $AssetsImagesComponentsGen { AssetGenImage get background => const AssetGenImage('assets/images/components/background.png'); + /// File path: assets/images/components/dino-land-bottom.png + AssetGenImage get dinoLandBottom => + const AssetGenImage('assets/images/components/dino-land-bottom.png'); + /// File path: assets/images/components/dino-land-top.png AssetGenImage get dinoLandTop => const AssetGenImage('assets/images/components/dino-land-top.png');