feat: including sprites

pull/229/head
alestiago 3 years ago
parent 4a3967ea96
commit 404f3a6ca7

@ -6,6 +6,9 @@ import 'package:flame_forge2d/flame_forge2d.dart' hide Timer;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
// TODO(alestiago): Make this global.
const _kImageToFlameRatio = 10.0;
/// {@template chrome_dino} /// {@template chrome_dino}
/// Dinosaur that gobbles up a [Ball], swivel his head around, and shoots it /// Dinosaur that gobbles up a [Ball], swivel his head around, and shoots it
/// back out. /// back out.
@ -40,12 +43,16 @@ class ChromeDino extends BodyComponent with InitialPosition {
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
final joint = await _anchorToJoint(); final joint = await _anchorToJoint();
await add( await addAll(
[
TimerComponent( TimerComponent(
period: 1, period: 1,
onTick: joint._swivel, onTick: joint._swivel,
repeat: true, repeat: true,
), ),
_ChromeDinoMouthSprite(),
_ChromeDinoHeadSprite(),
],
); );
} }
@ -152,3 +159,51 @@ class _ChromeDinoJoint extends RevoluteJoint {
setMotorSpeed(-motorSpeed); setMotorSpeed(-motorSpeed);
} }
} }
class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef {
@override
Future<void> 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<void> 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);
}
}

@ -97,6 +97,12 @@ class AndroidHead extends BodyComponent with InitialPosition, Layered {
priority: Ball.spaceshipPriority + 1, priority: Ball.spaceshipPriority + 1,
children: [_AndroidHeadSpriteAnimation()], children: [_AndroidHeadSpriteAnimation()],
) { ) {
layer = Layer.spaceship;
}
@override
Future<void> onLoad() async {
await super.onLoad();
renderBody = false; renderBody = false;
layer = Layer.spaceship; layer = Layer.spaceship;
} }

@ -1,7 +1,8 @@
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.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.'; static const info = 'Shows how a ChromeDino is rendered.';
@override @override

@ -162,7 +162,7 @@ packages:
name: js name: js
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.3" version: "0.6.4"
json_annotation: json_annotation:
dependency: transitive dependency: transitive
description: description:
@ -190,7 +190,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.4"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -211,7 +211,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.1"
path_provider_linux: path_provider_linux:
dependency: transitive dependency: transitive
description: description:
@ -335,7 +335,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -370,7 +370,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.9"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -440,7 +440,7 @@ packages:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
very_good_analysis: very_good_analysis:
dependency: "direct dev" dependency: "direct dev"
description: description:

@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared name: _fe_analyzer_shared
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "31.0.0" version: "39.0.0"
analyzer: analyzer:
dependency: transitive dependency: transitive
description: description:
name: analyzer name: analyzer
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.8.0" version: "4.0.0"
args: args:
dependency: transitive dependency: transitive
description: description:
@ -71,13 +71,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.5"
clock: clock:
dependency: transitive dependency: transitive
description: description:
@ -321,7 +314,7 @@ packages:
name: js name: js
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.3" version: "0.6.4"
json_annotation: json_annotation:
dependency: transitive dependency: transitive
description: description:
@ -356,7 +349,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.4"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -419,7 +412,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.1"
path_provider: path_provider:
dependency: transitive dependency: transitive
description: description:
@ -592,7 +585,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -634,21 +627,21 @@ packages:
name: test name: test
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.19.5" version: "1.21.0"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.9"
test_core: test_core:
dependency: transitive dependency: transitive
description: description:
name: test_core name: test_core
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.9" version: "0.4.13"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -669,7 +662,7 @@ packages:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
very_good_analysis: very_good_analysis:
dependency: "direct dev" dependency: "direct dev"
description: description:

Loading…
Cancel
Save