refactor: refactored code and fixed shapes

pull/208/head
RuiAlonso 3 years ago
parent a739b05e3e
commit fdd8822e60

@ -131,69 +131,56 @@ class _DinoBottomWall extends BodyComponent with InitialPosition {
} }
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[];
const restitution = 1.0; const restitution = 1.0;
final topStraightControlPoints = [
Vector2(32.4, -8.8),
Vector2(25, -7.7),
];
final topStraightShape = EdgeShape() final topStraightShape = EdgeShape()
..set( ..set(
topStraightControlPoints.first, Vector2(32.4, -8.8),
topStraightControlPoints.last, Vector2(25, -7.7),
); );
final topStraightFixtureDef = FixtureDef( final topStraightFixtureDef = FixtureDef(
topStraightShape, topStraightShape,
restitution: restitution, restitution: restitution,
); );
fixturesDef.add(topStraightFixtureDef);
final topLeftCurveControlPoints = [
topStraightControlPoints.last,
Vector2(21.8, -7),
Vector2(29.5, 13.8),
];
final topLeftCurveShape = BezierCurveShape( final topLeftCurveShape = BezierCurveShape(
controlPoints: topLeftCurveControlPoints, controlPoints: [
topStraightShape.vertex2,
Vector2(21.8, -7),
Vector2(29.8, 13.8),
],
); );
final topLeftCurveFixtureDef = FixtureDef( final topLeftCurveFixtureDef = FixtureDef(
topLeftCurveShape, topLeftCurveShape,
restitution: restitution, restitution: restitution,
); );
fixturesDef.add(topLeftCurveFixtureDef);
final bottomLeftStraightControlPoints = [
topLeftCurveControlPoints.last,
Vector2(31.8, 44.1),
];
final bottomLeftStraightShape = EdgeShape() final bottomLeftStraightShape = EdgeShape()
..set( ..set(
bottomLeftStraightControlPoints.first, topLeftCurveShape.vertices.last,
bottomLeftStraightControlPoints.last, Vector2(31.9, 44.1),
); );
final bottomLeftStraightFixtureDef = FixtureDef( final bottomLeftStraightFixtureDef = FixtureDef(
bottomLeftStraightShape, bottomLeftStraightShape,
restitution: restitution, restitution: restitution,
); );
fixturesDef.add(bottomLeftStraightFixtureDef);
final bottomStraightControlPoints = [
bottomLeftStraightControlPoints.last,
Vector2(37.8, 44.1),
];
final bottomStraightShape = EdgeShape() final bottomStraightShape = EdgeShape()
..set( ..set(
bottomStraightControlPoints.first, bottomLeftStraightShape.vertex2,
bottomStraightControlPoints.last, Vector2(37.8, 44.1),
); );
final bottomStraightFixtureDef = FixtureDef( final bottomStraightFixtureDef = FixtureDef(
bottomStraightShape, bottomStraightShape,
restitution: restitution, restitution: restitution,
); );
fixturesDef.add(bottomStraightFixtureDef);
return fixturesDef; return [
topStraightFixtureDef,
topLeftCurveFixtureDef,
bottomLeftStraightFixtureDef,
bottomStraightFixtureDef,
];
} }
@override @override

Loading…
Cancel
Save