diff --git a/packages/pinball_components/lib/src/components/chrome_dino.dart b/packages/pinball_components/lib/src/components/chrome_dino.dart index e450b661..92898622 100644 --- a/packages/pinball_components/lib/src/components/chrome_dino.dart +++ b/packages/pinball_components/lib/src/components/chrome_dino.dart @@ -6,6 +6,9 @@ import 'package:flame_forge2d/flame_forge2d.dart' hide Timer; import 'package:flutter/material.dart'; import 'package:pinball_components/pinball_components.dart'; +// TODO(alestiago): Make this global. +const _kImageToFlameRatio = 10.0; + /// {@template chrome_dino} /// Dinosaur that gobbles up a [Ball], swivel his head around, and shoots it /// back out. @@ -40,12 +43,16 @@ class ChromeDino extends BodyComponent with InitialPosition { Future onLoad() async { await super.onLoad(); final joint = await _anchorToJoint(); - await add( - TimerComponent( - period: 1, - onTick: joint._swivel, - repeat: true, - ), + await addAll( + [ + TimerComponent( + period: 1, + onTick: joint._swivel, + repeat: true, + ), + _ChromeDinoMouthSprite(), + _ChromeDinoHeadSprite(), + ], ); } @@ -152,3 +159,51 @@ class _ChromeDinoJoint extends RevoluteJoint { setMotorSpeed(-motorSpeed); } } + +class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef { + @override + Future onLoad() async { + await super.onLoad(); + final image = await gameRef.images.load( + Assets.images.chromeDino.mouth.keyName, + ); + + size = Vector2(17.5, 17); + position = Vector2(0, -2); + anchor = Anchor.center; + + const amountPerRow = 10; + const amountPerColumn = 10; + final data = SpriteAnimationData.sequenced( + amount: amountPerColumn * amountPerRow, + amountPerRow: amountPerRow, + stepTime: 0.05, + textureSize: size * _kImageToFlameRatio, + ); + animation = SpriteAnimation.fromFrameData(image, data); + } +} + +class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef { + @override + Future onLoad() async { + await super.onLoad(); + final image = await gameRef.images.load( + Assets.images.chromeDino.head.keyName, + ); + + size = Vector2(17.5, 17); + position = Vector2(0, -2); + anchor = Anchor.center; + + const amountPerRow = 10; + const amountPerColumn = 10; + final data = SpriteAnimationData.sequenced( + amount: amountPerColumn * amountPerRow, + amountPerRow: amountPerRow, + stepTime: 0.05, + textureSize: size * _kImageToFlameRatio, + ); + animation = SpriteAnimation.fromFrameData(image, data); + } +} diff --git a/packages/pinball_components/lib/src/components/spaceship.dart b/packages/pinball_components/lib/src/components/spaceship.dart index 4beb0367..0a0b39db 100644 --- a/packages/pinball_components/lib/src/components/spaceship.dart +++ b/packages/pinball_components/lib/src/components/spaceship.dart @@ -97,6 +97,12 @@ class AndroidHead extends BodyComponent with InitialPosition, Layered { priority: Ball.spaceshipPriority + 1, children: [_AndroidHeadSpriteAnimation()], ) { + layer = Layer.spaceship; + } + + @override + Future onLoad() async { + await super.onLoad(); renderBody = false; layer = Layer.spaceship; } diff --git a/packages/pinball_components/sandbox/lib/stories/chrome_dino/chrome_dino_game.dart b/packages/pinball_components/sandbox/lib/stories/chrome_dino/chrome_dino_game.dart index 94bf6e44..9e22a8ef 100644 --- a/packages/pinball_components/sandbox/lib/stories/chrome_dino/chrome_dino_game.dart +++ b/packages/pinball_components/sandbox/lib/stories/chrome_dino/chrome_dino_game.dart @@ -1,7 +1,8 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball_components/pinball_components.dart'; +import 'package:sandbox/common/common.dart'; -class ChromeDinoGame extends Forge2DGame { +class ChromeDinoGame extends BasicGame { static const info = 'Shows how a ChromeDino is rendered.'; @override diff --git a/packages/pinball_components/sandbox/pubspec.lock b/packages/pinball_components/sandbox/pubspec.lock index 7f78e365..ed0197a0 100644 --- a/packages/pinball_components/sandbox/pubspec.lock +++ b/packages/pinball_components/sandbox/pubspec.lock @@ -162,7 +162,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" json_annotation: dependency: transitive description: @@ -190,7 +190,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.4" meta: dependency: transitive description: @@ -211,7 +211,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" path_provider_linux: dependency: transitive description: @@ -335,7 +335,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -370,7 +370,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.9" typed_data: dependency: transitive description: @@ -440,7 +440,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" very_good_analysis: dependency: "direct dev" description: diff --git a/pubspec.lock b/pubspec.lock index 1a502f37..80670f71 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "31.0.0" + version: "39.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "2.8.0" + version: "4.0.0" args: dependency: transitive description: @@ -71,13 +71,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" - cli_util: - dependency: transitive - description: - name: cli_util - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.5" clock: dependency: transitive description: @@ -321,7 +314,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" json_annotation: dependency: transitive description: @@ -356,7 +349,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.4" meta: dependency: transitive description: @@ -419,7 +412,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" path_provider: dependency: transitive description: @@ -592,7 +585,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -634,21 +627,21 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.19.5" + version: "1.21.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.9" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.13" typed_data: dependency: transitive description: @@ -669,7 +662,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" very_good_analysis: dependency: "direct dev" description: