Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: allow modifying gravity in the x-axis and y-axis (#53)
- Loading branch information
Showing
4 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:forge2d/forge2d.dart'; | ||
import 'package:test/expect.dart'; | ||
import 'package:test/scaffolding.dart'; | ||
|
||
void main() { | ||
group('Body', () { | ||
group('gravityOverride', () { | ||
test("body doesn't move when is zero", () { | ||
final gravity = Vector2(10, 10); | ||
final world = World(gravity); | ||
|
||
final body = world.createBody( | ||
BodyDef() | ||
..type = BodyType.dynamic | ||
..gravityOverride = Vector2.zero(), | ||
); | ||
|
||
final bodyInitialPosition = body.position.clone(); | ||
|
||
world.stepDt(1); | ||
|
||
expect(bodyInitialPosition.x, equals(body.position.x)); | ||
expect(bodyInitialPosition.y, equals(body.position.y)); | ||
}); | ||
|
||
test( | ||
"body moves with world's gravity " | ||
'when gravityOverride is not specfied', () { | ||
final gravity = Vector2(10, 10); | ||
final world = World(gravity); | ||
|
||
final body = world.createBody(BodyDef()..type = BodyType.dynamic); | ||
|
||
final bodyInitialPosition = body.position.clone(); | ||
|
||
world.stepDt(1); | ||
|
||
expect(bodyInitialPosition.x, isNot(equals(body.position.x))); | ||
expect(bodyInitialPosition.y, isNot(equals(body.position.y))); | ||
}); | ||
}); | ||
|
||
group('gravityScale', () { | ||
test("body doesn't move when is zero", () { | ||
final gravity = Vector2(10, 10); | ||
final world = World(gravity); | ||
|
||
final body = world.createBody( | ||
BodyDef() | ||
..type = BodyType.dynamic | ||
..gravityScale = Vector2.zero(), | ||
); | ||
|
||
final bodyInitialPosition = body.position.clone(); | ||
|
||
world.stepDt(1); | ||
|
||
expect(bodyInitialPosition.x, equals(body.position.x)); | ||
expect(bodyInitialPosition.y, equals(body.position.y)); | ||
}); | ||
|
||
test( | ||
"body moves with world's gravity " | ||
'when gravityScale is not specfied', () { | ||
final gravity = Vector2(10, 10); | ||
final world = World(gravity); | ||
|
||
final body = world.createBody(BodyDef()..type = BodyType.dynamic); | ||
|
||
final bodyInitialPosition = body.position.clone(); | ||
|
||
world.stepDt(1); | ||
|
||
expect(bodyInitialPosition.x, isNot(equals(body.position.x))); | ||
expect(bodyInitialPosition.y, isNot(equals(body.position.y))); | ||
}); | ||
}); | ||
}); | ||
} |