diff --git a/lib/game/components/wall.dart b/lib/game/components/wall.dart index c80e5bb3..bb527c3b 100644 --- a/lib/game/components/wall.dart +++ b/lib/game/components/wall.dart @@ -3,32 +3,16 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/components/components.dart'; -class BallWallContactCallback extends ContactCallback { - @override - void begin(Ball ball, Wall wall, Contact contact) { - if (wall.type == WallType.bottom) { - ball - ..ballLost() - ..shouldRemove = true; - } - } - - @override - void end(_, __, ___) {} -} - enum WallType { - top, - bottom, - left, - right, + fatal, + passive, } class Wall extends BodyComponent { Wall({ - required this.type, required this.start, required this.end, + this.type = WallType.passive, }); factory Wall.bottom(Forge2DGame game) { @@ -36,7 +20,7 @@ class Wall extends BodyComponent { final bottomLeft = Vector2(0, bottomRight.y); return Wall( - type: WallType.bottom, + type: WallType.fatal, start: bottomRight, end: bottomLeft, ); @@ -62,3 +46,17 @@ class Wall extends BodyComponent { return world.createBody(bodyDef)..createFixture(fixtureDef); } } + +class BallWallContactCallback extends ContactCallback { + @override + void begin(Ball ball, Wall wall, Contact contact) { + if (wall.type == WallType.fatal) { + ball + ..ballLost() + ..shouldRemove = true; + } + } + + @override + void end(_, __, ___) {} +} diff --git a/test/game/components/wall_test.dart b/test/game/components/wall_test.dart index 2c4b241a..1ff5df95 100644 --- a/test/game/components/wall_test.dart +++ b/test/game/components/wall_test.dart @@ -14,13 +14,13 @@ void main() { group('Wall', () { group('BallWallContactCallback', () { 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 wall = MockWall(); final ball = MockBall(); - when(() => wall.type).thenReturn(WallType.bottom); + when(() => wall.type).thenReturn(WallType.fatal); when(() => ball.gameRef).thenReturn(game); BallWallContactCallback() @@ -39,7 +39,6 @@ void main() { 'loads correctly', (game) async { final wall = Wall( - type: WallType.bottom, start: Vector2.zero(), end: Vector2(100, 0), ); @@ -54,7 +53,6 @@ void main() { 'positions correctly', (game) async { final wall = Wall( - type: WallType.top, start: Vector2.zero(), end: Vector2(100, 0), ); @@ -69,7 +67,6 @@ void main() { 'is static', (game) async { final wall = Wall( - type: WallType.top, start: Vector2.zero(), end: Vector2(100, 0), ); @@ -85,7 +82,6 @@ void main() { 'exists', (game) async { final wall = Wall( - type: WallType.top, start: Vector2.zero(), end: Vector2(100, 0), ); @@ -99,7 +95,6 @@ void main() { 'has restitution equals 0', (game) async { final wall = Wall( - type: WallType.top, start: Vector2.zero(), end: Vector2(100, 0), ); @@ -114,7 +109,6 @@ void main() { 'has friction', (game) async { final wall = Wall( - type: WallType.top, start: Vector2.zero(), end: Vector2(100, 0), );