refactor: resolved gravityScale problems

pull/185/head
alestiago 4 years ago
parent b1b3726ade
commit b8f561c0d7

@ -79,7 +79,7 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
// TODO(allisonryan0002): prevent motion from contact with other balls. // TODO(allisonryan0002): prevent motion from contact with other balls.
void stop() { void stop() {
body body
..gravityScale = 0 ..gravityScale = Vector2.zero()
..linearVelocity = Vector2.zero() ..linearVelocity = Vector2.zero()
..angularVelocity = 0; ..angularVelocity = 0;
} }
@ -88,7 +88,7 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
/// ///
/// If previously [stop]ped, the previous ball's velocity is not kept. /// If previously [stop]ped, the previous ball's velocity is not kept.
void resume() { void resume() {
body.gravityScale = 1; body.gravityScale = Vector2(0, 1);
} }
@override @override

@ -94,7 +94,7 @@ class ChromeDino extends BodyComponent with InitialPosition {
@override @override
Body createBody() { Body createBody() {
final bodyDef = BodyDef() final bodyDef = BodyDef()
..gravityScale = 0 ..gravityScale = Vector2.zero()
..position = initialPosition ..position = initialPosition
..type = BodyType.dynamic; ..type = BodyType.dynamic;

@ -120,7 +120,7 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
Body createBody() { Body createBody() {
final bodyDef = BodyDef() final bodyDef = BodyDef()
..position = initialPosition ..position = initialPosition
..gravityScale = 0 ..gravityScale = Vector2.zero()
..type = BodyType.dynamic; ..type = BodyType.dynamic;
final body = world.createBody(bodyDef); final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture); _createFixtureDefs().forEach(body.createFixture);

@ -35,7 +35,7 @@ class Plunger extends BodyComponent with InitialPosition {
..position = initialPosition ..position = initialPosition
..userData = this ..userData = this
..type = BodyType.dynamic ..type = BodyType.dynamic
..gravityScale = 0; ..gravityScale = Vector2.zero();
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixture(fixtureDef);
} }

@ -48,7 +48,7 @@ void main() {
final ball = Ball(baseColor: Colors.blue); final ball = Ball(baseColor: Colors.blue);
await game.ensureAdd(ball); await game.ensureAdd(ball);
ball.body.gravityScale = 0; ball.body.gravityScale = Vector2.zero();
ball.body.linearVelocity.setValues(10, 10); ball.body.linearVelocity.setValues(10, 10);
game.update(1); game.update(1);
expect(ball.body.position, isNot(equals(ball.initialPosition))); expect(ball.body.position, isNot(equals(ball.initialPosition)));
@ -153,7 +153,7 @@ void main() {
ball.stop(); ball.stop();
ball.resume(); ball.resume();
ball.body.gravityScale = 0; ball.body.gravityScale = Vector2.zero();
ball.body.linearVelocity.setValues(10, 10); ball.body.linearVelocity.setValues(10, 10);
game.update(1); game.update(1);
expect(ball.body.position, isNot(equals(ball.initialPosition))); expect(ball.body.position, isNot(equals(ball.initialPosition)));

Loading…
Cancel
Save