feat: more tests and improving sizes

pull/60/head
Erick Zanardo 4 years ago
parent 1f72366ec5
commit dc98eefcc1

@ -2,9 +2,11 @@
import 'dart:async';
import 'dart:math';
import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart';
import 'package:pinball/game/game.dart';
// TODO(erickzanardo): change this to use the layer class
@ -207,7 +209,7 @@ class SpaceshipHole extends BodyComponent with InitialPosition {
@override
Body createBody() {
renderBody = false;
final circleShape = CircleShape()..radius = _spaceShipSize / 14;
final circleShape = CircleShape()..radius = _spaceShipSize / 80;
final bodyDef = BodyDef()
..userData = this
@ -280,7 +282,7 @@ class SpaceshipWall extends BodyComponent with InitialPosition {
return world.createBody(bodyDef)
..createFixture(
FixtureDef(wallShape)
..restitution = 0.8
..restitution = 1
..filter.maskBits = _spaceShipBits
..filter.categoryBits = _spaceShipBits,
);

@ -92,12 +92,12 @@ class PinballGame extends Forge2DGame
unawaited(
add(
SpaceshipHole()..initialPosition = position - Vector2(5, 5),
SpaceshipHole()..initialPosition = position - Vector2(5, 4),
),
);
unawaited(
add(
SpaceshipHole()..initialPosition = position - Vector2(-5, 5),
SpaceshipHole()..initialPosition = position - Vector2(-5, 4),
),
);

@ -0,0 +1,103 @@
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart';
import '../../helpers/helpers.dart';
void main() {
group('Spaceship', () {
late Filter filterData;
late Fixture fixture;
late Body body;
late PinballGame game;
late Ball ball;
late SpaceshipEntrance entrance;
late SpaceshipHole hole;
setUp(() {
filterData = MockFilter();
fixture = MockFixture();
when(() => fixture.filterData).thenReturn(filterData);
body = MockBody();
when(() => body.fixtures).thenReturn([fixture]);
game = MockPinballGame();
ball = MockBall();
when(() => ball.gameRef).thenReturn(game);
when(() => ball.body).thenReturn(body);
entrance = MockSpaceshipEntrance();
hole = MockSpaceshipHole();
});
group('SpaceshipEntranceBallContactCallback', () {
test('changes the ball priority on contact', () {
SpaceshipEntranceBallContactCallback().begin(
entrance,
ball,
MockContact(),
);
verify(() => ball.priority = 3).called(1);
});
test('re order the game children', () {
SpaceshipEntranceBallContactCallback().begin(
entrance,
ball,
MockContact(),
);
verify(game.reorderChildren).called(1);
});
test('changes the filter data from the ball fixtures', () {
SpaceshipEntranceBallContactCallback().begin(
entrance,
ball,
MockContact(),
);
verify(() => filterData.maskBits = 0x0002).called(1);
verify(() => filterData.categoryBits = 0x0002).called(1);
});
});
group('SpaceshipHoleBallContactCallback', () {
test('changes the ball priority on contact', () {
SpaceshipHoleBallContactCallback().begin(
hole,
ball,
MockContact(),
);
verify(() => ball.priority = 1).called(1);
});
test('re order the game children', () {
SpaceshipHoleBallContactCallback().begin(
hole,
ball,
MockContact(),
);
verify(game.reorderChildren).called(1);
});
test('changes the filter data from the ball fixtures', () {
SpaceshipHoleBallContactCallback().begin(
hole,
ball,
MockContact(),
);
verify(() => filterData.categoryBits = 0xFFFF).called(1);
verify(() => filterData.maskBits = 0x0001).called(1);
});
});
});
}

@ -41,3 +41,13 @@ class MockTapUpInfo extends Mock implements TapUpInfo {}
class MockEventPosition extends Mock implements EventPosition {}
class MockBonusLetter extends Mock implements BonusLetter {}
class MockFilter extends Mock implements Filter {}
class MockFixture extends Mock implements Fixture {}
class MockBody extends Mock implements Body {}
class MockSpaceshipEntrance extends Mock implements SpaceshipEntrance {}
class MockSpaceshipHole extends Mock implements SpaceshipHole {}

Loading…
Cancel
Save