|
|
@ -32,24 +32,21 @@ class ChromeDino extends BodyComponent with InitialPosition {
|
|
|
|
chromeDino: this,
|
|
|
|
chromeDino: this,
|
|
|
|
anchor: anchor,
|
|
|
|
anchor: anchor,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
_joint = _ChromeDinoJoint(jointDef)..create(world);
|
|
|
|
_joint = _ChromeDinoJoint(jointDef);
|
|
|
|
}
|
|
|
|
world.createJoint2(_joint);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(alestiago): Remove once the following is added to Flame.
|
|
|
|
|
|
|
|
// ignore: public_member_api_docs
|
|
|
|
|
|
|
|
Completer removed = Completer<bool>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void onRemove() {
|
|
|
|
|
|
|
|
super.onRemove();
|
|
|
|
|
|
|
|
removed.complete(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
await _anchorToJoint();
|
|
|
|
await _anchorToJoint();
|
|
|
|
await add(TimerComponent(period: 1, onTick: _joint.swivel));
|
|
|
|
await add(
|
|
|
|
|
|
|
|
TimerComponent(
|
|
|
|
|
|
|
|
period: 1,
|
|
|
|
|
|
|
|
onTick: _joint.swivel,
|
|
|
|
|
|
|
|
repeat: true,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
|
List<FixtureDef> _createFixtureDefs() {
|
|
|
@ -65,29 +62,31 @@ class ChromeDino extends BodyComponent with InitialPosition {
|
|
|
|
..isSensor = true;
|
|
|
|
..isSensor = true;
|
|
|
|
fixtureDefs.add(fixtureDef);
|
|
|
|
fixtureDefs.add(fixtureDef);
|
|
|
|
|
|
|
|
|
|
|
|
final upperEdge = EdgeShape()
|
|
|
|
// FIXME(alestiago): Investigate why adding these fixtures is considered as
|
|
|
|
..set(
|
|
|
|
// an invalid contact type.
|
|
|
|
Vector2(-size.x / 2, -size.y / 2),
|
|
|
|
// final upperEdge = EdgeShape()
|
|
|
|
Vector2(size.x / 2, -size.y / 2),
|
|
|
|
// ..set(
|
|
|
|
);
|
|
|
|
// Vector2(-size.x / 2, -size.y / 2),
|
|
|
|
final upperEdgeDef = FixtureDef(upperEdge)..density = 0.5;
|
|
|
|
// Vector2(size.x / 2, -size.y / 2),
|
|
|
|
fixtureDefs.add(upperEdgeDef);
|
|
|
|
// );
|
|
|
|
|
|
|
|
// final upperEdgeDef = FixtureDef(upperEdge)..density = 0.5;
|
|
|
|
final lowerEdge = EdgeShape()
|
|
|
|
// fixtureDefs.add(upperEdgeDef);
|
|
|
|
..set(
|
|
|
|
|
|
|
|
Vector2(-size.x / 2, size.y / 2),
|
|
|
|
// final lowerEdge = EdgeShape()
|
|
|
|
Vector2(size.x / 2, size.y / 2),
|
|
|
|
// ..set(
|
|
|
|
);
|
|
|
|
// Vector2(-size.x / 2, size.y / 2),
|
|
|
|
final lowerEdgeDef = FixtureDef(lowerEdge)..density = 0.5;
|
|
|
|
// Vector2(size.x / 2, size.y / 2),
|
|
|
|
fixtureDefs.add(lowerEdgeDef);
|
|
|
|
// );
|
|
|
|
|
|
|
|
// final lowerEdgeDef = FixtureDef(lowerEdge)..density = 0.5;
|
|
|
|
final rightEdge = EdgeShape()
|
|
|
|
// fixtureDefs.add(lowerEdgeDef);
|
|
|
|
..set(
|
|
|
|
|
|
|
|
Vector2(size.x / 2, -size.y / 2),
|
|
|
|
// final rightEdge = EdgeShape()
|
|
|
|
Vector2(size.x / 2, size.y / 2),
|
|
|
|
// ..set(
|
|
|
|
);
|
|
|
|
// Vector2(size.x / 2, -size.y / 2),
|
|
|
|
final rightEdgeDef = FixtureDef(rightEdge)..density = 0.5;
|
|
|
|
// Vector2(size.x / 2, size.y / 2),
|
|
|
|
fixtureDefs.add(rightEdgeDef);
|
|
|
|
// );
|
|
|
|
|
|
|
|
// final rightEdgeDef = FixtureDef(rightEdge)..density = 0.5;
|
|
|
|
|
|
|
|
// fixtureDefs.add(rightEdgeDef);
|
|
|
|
|
|
|
|
|
|
|
|
return fixtureDefs;
|
|
|
|
return fixtureDefs;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -149,15 +148,20 @@ class _ChromeDinoAnchorRevoluteJointDef extends RevoluteJointDef {
|
|
|
|
class _ChromeDinoJoint extends RevoluteJoint {
|
|
|
|
class _ChromeDinoJoint extends RevoluteJoint {
|
|
|
|
_ChromeDinoJoint(_ChromeDinoAnchorRevoluteJointDef def) : super(def);
|
|
|
|
_ChromeDinoJoint(_ChromeDinoAnchorRevoluteJointDef def) : super(def);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(alestiago): Remove once Forge2D supports custom joints.
|
|
|
|
|
|
|
|
void create(World world) {
|
|
|
|
|
|
|
|
world.joints.add(this);
|
|
|
|
|
|
|
|
bodyA.joints.add(this);
|
|
|
|
|
|
|
|
bodyB.joints.add(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Sweeps the [ChromeDino] up and down repeatedly.
|
|
|
|
/// Sweeps the [ChromeDino] up and down repeatedly.
|
|
|
|
void swivel() {
|
|
|
|
void swivel() {
|
|
|
|
setMotorSpeed(-motorSpeed);
|
|
|
|
setMotorSpeed(-motorSpeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extension on World {
|
|
|
|
|
|
|
|
// TODO(alestiago): Remove once Forge2D supports custom joints.
|
|
|
|
|
|
|
|
void createJoint2(Joint joint) {
|
|
|
|
|
|
|
|
assert(!isLocked, '');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
joints.add(joint);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
joint.bodyA.joints.add(joint);
|
|
|
|
|
|
|
|
joint.bodyB.joints.add(joint);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|