Skip to content

Commit

Permalink
feat: Bump forg2d version and have flame_forge2d examples use latest …
Browse files Browse the repository at this point in the history
…syntax (#1535)
  • Loading branch information
spydon authored Apr 12, 2022
1 parent 5ed0833 commit 4f7a12e
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 94 deletions.
23 changes: 13 additions & 10 deletions packages/flame_forge2d/example/lib/animated_body_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ class ChopperBody extends BodyComponent {
@override
Body createBody() {
final shape = CircleShape()..radius = size.x / 4;
final fixtureDef = FixtureDef(shape)
..userData = this // To be able to determine object in collision
..restitution = 0.8
..density = 1.0
..friction = 0.2;
final fixtureDef = FixtureDef(
shape,
userData: this, // To be able to determine object in collision
restitution: 0.8,
density: 1.0,
friction: 0.2,
);

final velocity = (Vector2.random() - Vector2.random()) * 200;
final bodyDef = BodyDef()
..position = position
..angle = velocity.angleTo(Vector2(1, 0))
..linearVelocity = velocity
..type = BodyType.dynamic;
final bodyDef = BodyDef(
position: position,
angle: velocity.angleTo(Vector2(1, 0)),
linearVelocity: velocity,
type: BodyType.dynamic,
);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
Expand Down
22 changes: 12 additions & 10 deletions packages/flame_forge2d/example/lib/balls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ class Ball extends BodyComponent {
final shape = CircleShape();
shape.radius = radius;

final fixtureDef = FixtureDef(shape)
..restitution = 0.8
..density = 1.0
..friction = 0.4;
final fixtureDef = FixtureDef(
shape,
restitution: 0.8,
density: 1.0,
friction: 0.4,
);

final bodyDef = BodyDef()
// To be able to determine object in collision
..userData = this
..angularDamping = 0.8
..position = _position
..type = BodyType.dynamic;
final bodyDef = BodyDef(
userData: this,
angularDamping: 0.8,
position: _position,
type: BodyType.dynamic,
);

return world.createBody(bodyDef)..createFixture(fixtureDef);
}
Expand Down
27 changes: 15 additions & 12 deletions packages/flame_forge2d/example/lib/blob_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class Ground extends BodyComponent {
final shape = PolygonShape();
shape.setAsBoxXY(20.0, 0.4);

final bodyDef = BodyDef();
bodyDef.position.setFrom(worldCenter);
final bodyDef = BodyDef(position: worldCenter.clone());
final ground = world.createBody(bodyDef);
ground.createFixtureFromShape(shape);

Expand Down Expand Up @@ -49,16 +48,19 @@ class BlobPart extends BodyComponent {
final x = blobCenter.x + blobRadius.x * math.sin(angle);
final y = blobCenter.y + blobRadius.y * math.cos(angle);

final bodyDef = BodyDef()
..fixedRotation = true
..position.setValues(x, y)
..type = BodyType.dynamic;
final bodyDef = BodyDef(
fixedRotation: true,
position: Vector2(x, y),
type: BodyType.dynamic,
);
final body = world.createBody(bodyDef);

final shape = CircleShape()..radius = bodyRadius;
final fixtureDef = FixtureDef(shape)
..density = 1.0
..filter.groupIndex = -2;
final fixtureDef = FixtureDef(
shape,
density: 1.0,
filter: Filter()..groupIndex = -2,
);
body.createFixture(fixtureDef);
jointDef.addBody(body);
return body;
Expand All @@ -72,9 +74,10 @@ class FallingBox extends BodyComponent {

@override
Body createBody() {
final bodyDef = BodyDef()
..type = BodyType.dynamic
..position = position;
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: position,
);
final shape = PolygonShape()..setAsBoxXY(2, 4);
final body = world.createBody(bodyDef);
body.createFixtureFromShape(shape, 1.0);
Expand Down
14 changes: 5 additions & 9 deletions packages/flame_forge2d/example/lib/boundaries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ class Wall extends BodyComponent {
@override
Body createBody() {
final shape = EdgeShape()..set(start, end);

final fixtureDef = FixtureDef(shape)
..restitution = 0.0
..friction = 0.3;

final bodyDef = BodyDef()
..userData = this // To be able to determine object in collision
..position = Vector2.zero()
..type = BodyType.static;
final fixtureDef = FixtureDef(shape, friction: 0.3);
final bodyDef = BodyDef(
userData: this, // To be able to determine object in collision
position: Vector2.zero(),
);

return world.createBody(bodyDef)..createFixture(fixtureDef);
}
Expand Down
22 changes: 11 additions & 11 deletions packages/flame_forge2d/example/lib/circle_stress_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class CircleShuffler extends BodyComponent {

@override
Body createBody() {
final bodyDef = BodyDef()
..type = BodyType.dynamic
..position = _center + Vector2(0.0, -25.0);
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: _center + Vector2(0.0, -25.0),
);
const numPieces = 5;
const radius = 6.0;
final body = world.createBody(bodyDef);
Expand All @@ -28,10 +29,12 @@ class CircleShuffler extends BodyComponent {
..radius = 1.2
..position.setValues(xPos, yPos);

final fixtureDef = FixtureDef(shape)
..density = 50.0
..friction = .1
..restitution = .9;
final fixtureDef = FixtureDef(
shape,
density: 50.0,
friction: .1,
restitution: .9,
);

body.createFixture(fixtureDef);
}
Expand Down Expand Up @@ -67,10 +70,7 @@ class CornerRamp extends BodyComponent {
];
shape.createLoop(vertices);

final fixtureDef = FixtureDef(shape)
..restitution = 0.0
..friction = 0.1;

final fixtureDef = FixtureDef(shape, friction: 0.1);
final bodyDef = BodyDef()
..position = _center
..type = BodyType.static;
Expand Down
20 changes: 9 additions & 11 deletions packages/flame_forge2d/example/lib/domino_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class Platform extends BodyComponent {
final shape = PolygonShape()..setAsBoxXY(14.8, 0.125);
final fixtureDef = FixtureDef(shape);

final bodyDef = BodyDef();
bodyDef.position = position;
final bodyDef = BodyDef(position: position);
final body = world.createBody(bodyDef);
return body..createFixture(fixtureDef);
}
Expand All @@ -31,15 +30,14 @@ class DominoBrick extends BodyComponent {
@override
Body createBody() {
final shape = PolygonShape()..setAsBoxXY(0.125, 2.0);
final fixtureDef = FixtureDef(shape)
..density = 25.0
..restitution = 0.4
..friction = 0.5;

final bodyDef = BodyDef()
..type = BodyType.dynamic
..position = position;

final fixtureDef = FixtureDef(
shape,
density: 25.0,
restitution: 0.4,
friction: 0.5,
);

final bodyDef = BodyDef(type: BodyType.dynamic, position: position);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
Expand Down
17 changes: 10 additions & 7 deletions packages/flame_forge2d/example/lib/joint_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class CircleShuffler extends BodyComponent {

@override
Body createBody() {
final bodyDef = BodyDef()
..type = BodyType.dynamic
..position = ball.body.position.clone();
final bodyDef = BodyDef(
type: BodyType.dynamic,
position: ball.body.position.clone(),
);
const numPieces = 5;
const radius = 6.0;
final body = world.createBody(bodyDef);
Expand All @@ -28,10 +29,12 @@ class CircleShuffler extends BodyComponent {
..radius = 1.2
..position.setValues(xPos, yPos);

final fixtureDef = FixtureDef(shape)
..density = 50.0
..friction = .1
..restitution = .9;
final fixtureDef = FixtureDef(
shape,
density: 50.0,
friction: 0.1,
restitution: 0.9,
);

body.createFixture(fixtureDef);
}
Expand Down
8 changes: 2 additions & 6 deletions packages/flame_forge2d/example/lib/raycast_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ class Box extends BodyComponent {
@override
Body createBody() {
final shape = PolygonShape()..setAsBoxXY(2.0, 4.0);
final fixtureDef = FixtureDef(shape)..userData = this;

final bodyDef = BodyDef()
..type = BodyType.static
..position = position;

final fixtureDef = FixtureDef(shape, userData: this);
final bodyDef = BodyDef(position: position);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
Expand Down
21 changes: 12 additions & 9 deletions packages/flame_forge2d/example/lib/sprite_body_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ class Pizza extends BodyComponent {
];
shape.set(vertices);

final fixtureDef = FixtureDef(shape)
..userData = this // To be able to determine object in collision
..restitution = 0.4
..density = 1.0
..friction = 0.5;
final fixtureDef = FixtureDef(
shape,
userData: this, // To be able to determine object in collision
restitution: 0.4,
density: 1.0,
friction: 0.5,
);

final bodyDef = BodyDef()
..position = position
..angle = (position.x + position.y) / 2 * pi
..type = BodyType.dynamic;
final bodyDef = BodyDef(
position: position,
angle: (position.x + position.y) / 2 * pi,
type: BodyType.dynamic,
);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
19 changes: 11 additions & 8 deletions packages/flame_forge2d/example/lib/widget_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ class WidgetSample extends Forge2DGame with TapDetector {
}

Body createBody() {
final bodyDef = BodyDef()
..angularVelocity = 3
..position = screenToWorld(
final bodyDef = BodyDef(
angularVelocity: 3,
position: screenToWorld(
Vector2.random()..multiply(camera.viewport.effectiveSize),
)
..type = BodyType.dynamic;
),
type: BodyType.dynamic,
);
final body = world.createBody(bodyDef);

final shape = PolygonShape()..setAsBoxXY(4.6, 0.8);
final fixtureDef = FixtureDef(shape)
..density = 1.0
..restitution = 0.95;
final fixtureDef = FixtureDef(
shape,
density: 1.0,
restitution: 0.95,
);
body.createFixture(fixtureDef);
return body;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_forge2d/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:

dependencies:
flame: ^1.1.0
forge2d: ^0.10.0
forge2d: ">=0.11.0 <0.12.0"

flutter:
sdk: flutter
Expand Down

0 comments on commit 4f7a12e

Please sign in to comment.