|
|
@ -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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|