|
|
@ -1,26 +1,23 @@
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:math' as math;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart' hide Timer;
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart' hide Timer;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template chrome_dino}
|
|
|
|
/// {@template chrome_dino}
|
|
|
|
/// Dinosaur that gobbles up a [Ball], swivel his head around, and shoots it
|
|
|
|
/// Dino that swivels back and forth, opening its mouth to eat a [Ball].
|
|
|
|
/// back out.
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Upon eating a [Ball], the dino rotates and spits the [Ball] out in a
|
|
|
|
|
|
|
|
/// different direction.
|
|
|
|
/// {@endtemplate}
|
|
|
|
/// {@endtemplate}
|
|
|
|
class ChromeDino extends BodyComponent with InitialPosition {
|
|
|
|
class ChromeDino extends BodyComponent with InitialPosition {
|
|
|
|
/// {@macro chrome_dino}
|
|
|
|
/// {@macro chrome_dino}
|
|
|
|
ChromeDino()
|
|
|
|
ChromeDino() : super(priority: RenderPriority.dino) {
|
|
|
|
: super(
|
|
|
|
renderBody = false;
|
|
|
|
// TODO(alestiago): Remove once sprites are defined.
|
|
|
|
}
|
|
|
|
paint: Paint()..color = Colors.blue,
|
|
|
|
|
|
|
|
priority: RenderPriority.dino,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The size of the dinosaur mouth.
|
|
|
|
/// The size of the dinosaur mouth.
|
|
|
|
static final size = Vector2(5, 2.5);
|
|
|
|
static final size = Vector2(5.5, 5);
|
|
|
|
|
|
|
|
|
|
|
|
/// Anchors the [ChromeDino] to the [RevoluteJoint] that controls its arc
|
|
|
|
/// Anchors the [ChromeDino] to the [RevoluteJoint] that controls its arc
|
|
|
|
/// motion.
|
|
|
|
/// motion.
|
|
|
@ -42,60 +39,30 @@ 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 addAll(
|
|
|
|
await add(
|
|
|
|
[
|
|
|
|
|
|
|
|
TimerComponent(
|
|
|
|
TimerComponent(
|
|
|
|
period: 1,
|
|
|
|
period: 98 / 48,
|
|
|
|
onTick: joint._swivel,
|
|
|
|
onTick: joint._swivel,
|
|
|
|
repeat: true,
|
|
|
|
repeat: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
_ChromeDinoMouthSprite(),
|
|
|
|
|
|
|
|
_ChromeDinoHeadSprite(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
joint._swivel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
final fixtureDefs = <FixtureDef>[];
|
|
|
|
final fixtureDefs = <FixtureDef>[];
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(alestiago): Subject to change when sprites are added.
|
|
|
|
// TODO(allisonryan0002): Update this to match sprite.
|
|
|
|
final box = PolygonShape()..setAsBoxXY(size.x / 2, size.y / 2);
|
|
|
|
final box = PolygonShape()
|
|
|
|
final fixtureDef = FixtureDef(
|
|
|
|
..setAsBox(
|
|
|
|
box,
|
|
|
|
size.x / 2,
|
|
|
|
density: 999,
|
|
|
|
size.y / 2,
|
|
|
|
friction: 0.3,
|
|
|
|
initialPosition + Vector2(-4, 2),
|
|
|
|
restitution: 0.1,
|
|
|
|
-0.1143,
|
|
|
|
isSensor: true,
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
final fixtureDef = FixtureDef(box, density: 1);
|
|
|
|
fixtureDefs.add(fixtureDef);
|
|
|
|
fixtureDefs.add(fixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME(alestiago): Investigate why adding these fixtures is considered as
|
|
|
|
|
|
|
|
// an invalid contact type.
|
|
|
|
|
|
|
|
// final upperEdge = EdgeShape()
|
|
|
|
|
|
|
|
// ..set(
|
|
|
|
|
|
|
|
// Vector2(-size.x / 2, -size.y / 2),
|
|
|
|
|
|
|
|
// Vector2(size.x / 2, -size.y / 2),
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// final upperEdgeDef = FixtureDef(upperEdge)..density = 0.5;
|
|
|
|
|
|
|
|
// fixtureDefs.add(upperEdgeDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// final lowerEdge = EdgeShape()
|
|
|
|
|
|
|
|
// ..set(
|
|
|
|
|
|
|
|
// Vector2(-size.x / 2, size.y / 2),
|
|
|
|
|
|
|
|
// Vector2(size.x / 2, size.y / 2),
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// final lowerEdgeDef = FixtureDef(lowerEdge)..density = 0.5;
|
|
|
|
|
|
|
|
// fixtureDefs.add(lowerEdgeDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// final rightEdge = EdgeShape()
|
|
|
|
|
|
|
|
// ..set(
|
|
|
|
|
|
|
|
// Vector2(size.x / 2, -size.y / 2),
|
|
|
|
|
|
|
|
// Vector2(size.x / 2, size.y / 2),
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// final rightEdgeDef = FixtureDef(rightEdge)..density = 0.5;
|
|
|
|
|
|
|
|
// fixtureDefs.add(rightEdgeDef);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fixtureDefs;
|
|
|
|
return fixtureDefs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -115,12 +82,22 @@ class ChromeDino extends BodyComponent with InitialPosition {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template flipper_anchor}
|
|
|
|
/// {@template flipper_anchor}
|
|
|
|
/// [JointAnchor] positioned at the end of a [ChromeDino].
|
|
|
|
/// [JointAnchor] positioned at the back of the [ChromeDino].
|
|
|
|
/// {@endtemplate}
|
|
|
|
/// {@endtemplate}
|
|
|
|
class _ChromeDinoAnchor extends JointAnchor {
|
|
|
|
class _ChromeDinoAnchor extends JointAnchor {
|
|
|
|
/// {@macro flipper_anchor}
|
|
|
|
/// {@macro flipper_anchor}
|
|
|
|
_ChromeDinoAnchor() {
|
|
|
|
_ChromeDinoAnchor() {
|
|
|
|
initialPosition = Vector2(9, 0);
|
|
|
|
initialPosition = Vector2(9, -4);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
|
|
|
const spriteAngle = 0.1143;
|
|
|
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
|
|
|
await addAll([
|
|
|
|
|
|
|
|
_ChromeDinoMouthSprite()..angle = spriteAngle,
|
|
|
|
|
|
|
|
_ChromeDinoHeadSprite()..angle = spriteAngle,
|
|
|
|
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -139,20 +116,22 @@ class _ChromeDinoAnchorRevoluteJointDef extends RevoluteJointDef {
|
|
|
|
chromeDino.body.position + anchor.body.position,
|
|
|
|
chromeDino.body.position + anchor.body.position,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
enableLimit = true;
|
|
|
|
enableLimit = true;
|
|
|
|
// TODO(alestiago): Apply design angle value.
|
|
|
|
const angle = 0.1143;
|
|
|
|
const angle = math.pi / 3.5;
|
|
|
|
lowerAngle = -angle;
|
|
|
|
lowerAngle = -angle / 2;
|
|
|
|
upperAngle = angle;
|
|
|
|
upperAngle = angle / 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enableMotor = true;
|
|
|
|
enableMotor = true;
|
|
|
|
// TODO(alestiago): Tune this values.
|
|
|
|
maxMotorTorque = chromeDino.body.mass * 255;
|
|
|
|
maxMotorTorque = motorSpeed = chromeDino.body.mass * 30;
|
|
|
|
motorSpeed = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _ChromeDinoJoint extends RevoluteJoint {
|
|
|
|
class _ChromeDinoJoint extends RevoluteJoint {
|
|
|
|
_ChromeDinoJoint(_ChromeDinoAnchorRevoluteJointDef def) : super(def);
|
|
|
|
_ChromeDinoJoint(_ChromeDinoAnchorRevoluteJointDef def) : super(def);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Half the angle of the arc motion.
|
|
|
|
|
|
|
|
// static const _halfSweepingAngle = 0.1143;
|
|
|
|
|
|
|
|
|
|
|
|
/// Sweeps the [ChromeDino] up and down repeatedly.
|
|
|
|
/// Sweeps the [ChromeDino] up and down repeatedly.
|
|
|
|
void _swivel() {
|
|
|
|
void _swivel() {
|
|
|
|
setMotorSpeed(-motorSpeed);
|
|
|
|
setMotorSpeed(-motorSpeed);
|
|
|
@ -160,16 +139,18 @@ class _ChromeDinoJoint extends RevoluteJoint {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef {
|
|
|
|
class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef {
|
|
|
|
|
|
|
|
_ChromeDinoMouthSprite()
|
|
|
|
|
|
|
|
: super(
|
|
|
|
|
|
|
|
anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
final image = await gameRef.images.load(
|
|
|
|
final image = gameRef.images.fromCache(
|
|
|
|
Assets.images.chromeDino.mouth.keyName,
|
|
|
|
Assets.images.dino.animatronic.mouth.keyName,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
position = Vector2(0, -2);
|
|
|
|
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const amountPerRow = 11;
|
|
|
|
const amountPerRow = 11;
|
|
|
|
const amountPerColumn = 9;
|
|
|
|
const amountPerColumn = 9;
|
|
|
|
final textureSize = Vector2(
|
|
|
|
final textureSize = Vector2(
|
|
|
@ -181,24 +162,26 @@ class _ChromeDinoMouthSprite extends SpriteAnimationComponent with HasGameRef {
|
|
|
|
final data = SpriteAnimationData.sequenced(
|
|
|
|
final data = SpriteAnimationData.sequenced(
|
|
|
|
amount: (amountPerColumn * amountPerRow) - 1,
|
|
|
|
amount: (amountPerColumn * amountPerRow) - 1,
|
|
|
|
amountPerRow: amountPerRow,
|
|
|
|
amountPerRow: amountPerRow,
|
|
|
|
stepTime: 0.1,
|
|
|
|
stepTime: 1 / 24,
|
|
|
|
textureSize: textureSize,
|
|
|
|
textureSize: textureSize,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
animation = SpriteAnimation.fromFrameData(image, data);
|
|
|
|
animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 95;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef {
|
|
|
|
class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef {
|
|
|
|
|
|
|
|
_ChromeDinoHeadSprite()
|
|
|
|
|
|
|
|
: super(
|
|
|
|
|
|
|
|
anchor: Anchor(Anchor.center.x + 0.47, Anchor.center.y - 0.29),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
final image = await gameRef.images.load(
|
|
|
|
final image = gameRef.images.fromCache(
|
|
|
|
Assets.images.chromeDino.head.keyName,
|
|
|
|
Assets.images.dino.animatronic.head.keyName,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
position = Vector2(0, -2);
|
|
|
|
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const amountPerRow = 11;
|
|
|
|
const amountPerRow = 11;
|
|
|
|
const amountPerColumn = 9;
|
|
|
|
const amountPerColumn = 9;
|
|
|
|
final textureSize = Vector2(
|
|
|
|
final textureSize = Vector2(
|
|
|
@ -210,9 +193,9 @@ class _ChromeDinoHeadSprite extends SpriteAnimationComponent with HasGameRef {
|
|
|
|
final data = SpriteAnimationData.sequenced(
|
|
|
|
final data = SpriteAnimationData.sequenced(
|
|
|
|
amount: (amountPerColumn * amountPerRow) - 1,
|
|
|
|
amount: (amountPerColumn * amountPerRow) - 1,
|
|
|
|
amountPerRow: amountPerRow,
|
|
|
|
amountPerRow: amountPerRow,
|
|
|
|
stepTime: 0.1,
|
|
|
|
stepTime: 1 / 24,
|
|
|
|
textureSize: textureSize,
|
|
|
|
textureSize: textureSize,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
animation = SpriteAnimation.fromFrameData(image, data);
|
|
|
|
animation = SpriteAnimation.fromFrameData(image, data)..currentIndex = 95;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|