feat: pr suggestions

pull/9/head
Erick Zanardo 4 years ago
parent adcc43d04a
commit 4ccd172b4f

@ -3,32 +3,16 @@
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball/game/components/components.dart'; import 'package:pinball/game/components/components.dart';
class BallWallContactCallback extends ContactCallback<Ball, Wall> {
@override
void begin(Ball ball, Wall wall, Contact contact) {
if (wall.type == WallType.bottom) {
ball
..ballLost()
..shouldRemove = true;
}
}
@override
void end(_, __, ___) {}
}
enum WallType { enum WallType {
top, fatal,
bottom, passive,
left,
right,
} }
class Wall extends BodyComponent { class Wall extends BodyComponent {
Wall({ Wall({
required this.type,
required this.start, required this.start,
required this.end, required this.end,
this.type = WallType.passive,
}); });
factory Wall.bottom(Forge2DGame game) { factory Wall.bottom(Forge2DGame game) {
@ -36,7 +20,7 @@ class Wall extends BodyComponent {
final bottomLeft = Vector2(0, bottomRight.y); final bottomLeft = Vector2(0, bottomRight.y);
return Wall( return Wall(
type: WallType.bottom, type: WallType.fatal,
start: bottomRight, start: bottomRight,
end: bottomLeft, end: bottomLeft,
); );
@ -62,3 +46,17 @@ class Wall extends BodyComponent {
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixture(fixtureDef);
} }
} }
class BallWallContactCallback extends ContactCallback<Ball, Wall> {
@override
void begin(Ball ball, Wall wall, Contact contact) {
if (wall.type == WallType.fatal) {
ball
..ballLost()
..shouldRemove = true;
}
}
@override
void end(_, __, ___) {}
}

@ -14,13 +14,13 @@ void main() {
group('Wall', () { group('Wall', () {
group('BallWallContactCallback', () { group('BallWallContactCallback', () {
test( test(
'removes the ball on begin contact when the wall is a bottom one', 'removes the ball on begin contact when the wall is a fatal one',
() { () {
final game = MockPinballGame(); final game = MockPinballGame();
final wall = MockWall(); final wall = MockWall();
final ball = MockBall(); final ball = MockBall();
when(() => wall.type).thenReturn(WallType.bottom); when(() => wall.type).thenReturn(WallType.fatal);
when(() => ball.gameRef).thenReturn(game); when(() => ball.gameRef).thenReturn(game);
BallWallContactCallback() BallWallContactCallback()
@ -39,7 +39,6 @@ void main() {
'loads correctly', 'loads correctly',
(game) async { (game) async {
final wall = Wall( final wall = Wall(
type: WallType.bottom,
start: Vector2.zero(), start: Vector2.zero(),
end: Vector2(100, 0), end: Vector2(100, 0),
); );
@ -54,7 +53,6 @@ void main() {
'positions correctly', 'positions correctly',
(game) async { (game) async {
final wall = Wall( final wall = Wall(
type: WallType.top,
start: Vector2.zero(), start: Vector2.zero(),
end: Vector2(100, 0), end: Vector2(100, 0),
); );
@ -69,7 +67,6 @@ void main() {
'is static', 'is static',
(game) async { (game) async {
final wall = Wall( final wall = Wall(
type: WallType.top,
start: Vector2.zero(), start: Vector2.zero(),
end: Vector2(100, 0), end: Vector2(100, 0),
); );
@ -85,7 +82,6 @@ void main() {
'exists', 'exists',
(game) async { (game) async {
final wall = Wall( final wall = Wall(
type: WallType.top,
start: Vector2.zero(), start: Vector2.zero(),
end: Vector2(100, 0), end: Vector2(100, 0),
); );
@ -99,7 +95,6 @@ void main() {
'has restitution equals 0', 'has restitution equals 0',
(game) async { (game) async {
final wall = Wall( final wall = Wall(
type: WallType.top,
start: Vector2.zero(), start: Vector2.zero(),
end: Vector2(100, 0), end: Vector2(100, 0),
); );
@ -114,7 +109,6 @@ void main() {
'has friction', 'has friction',
(game) async { (game) async {
final wall = Wall( final wall = Wall(
type: WallType.top,
start: Vector2.zero(), start: Vector2.zero(),
end: Vector2(100, 0), end: Vector2(100, 0),
); );

Loading…
Cancel
Save