chore: ramp area name changed to opening

pull/40/head
RuiAlonso 4 years ago
parent a5fb9ed8df
commit c880884b5c

@ -14,7 +14,7 @@ enum RampOrientation {
down, down,
} }
/// Indicates the type of the ramp. /// Indicates a type of the ramp.
/// ///
/// Used to set the maskBits of the ramp to determine their possible collisions. /// Used to set the maskBits of the ramp to determine their possible collisions.
enum RampType { enum RampType {
@ -46,15 +46,17 @@ extension RampTypeX on RampType {
} }
} }
/// {@template ramp_area} /// {@template ramp_opening}
/// [BodyComponent] located at the entrance and exit of a ramp. /// [BodyComponent] located at the entrance and exit of a ramp.
/// ///
/// Detects when a [Ball] goes through it, /// [RampOpeningBallContactCallback] detects when a [Ball] passes
/// Collisions with [RampArea] are listened by [RampAreaCallback]. /// through this opening.
/// Collisions with [RampOpening] are listened
/// by [RampOpeningBallContactCallback].
/// {@endtemplate} /// {@endtemplate}
abstract class RampArea extends BodyComponent { abstract class RampOpening extends BodyComponent {
/// {@macro ramp_area} /// {@macro ramp_opening}
RampArea({ RampOpening({
required Vector2 position, required Vector2 position,
required int categoryBits, required int categoryBits,
}) : _position = position, }) : _position = position,
@ -66,37 +68,38 @@ abstract class RampArea extends BodyComponent {
final Vector2 _position; final Vector2 _position;
final int _categoryBits; final int _categoryBits;
/// Mask of category bits for collision with [RampArea] /// Mask of category bits for collision with [RampOpening]
int get categoryBits => _categoryBits; int get categoryBits => _categoryBits;
/// The [Shape] of the [RampArea] /// The [Shape] of the [RampOpening]
Shape get shape; Shape get shape;
/// Orientation of the [RampArea] entrance/exit /// Orientation of the [RampOpening] entrance/exit
RampOrientation get orientation; RampOrientation get orientation;
@override @override
Body createBody() { Body createBody() {
final fixtureDef = FixtureDef(shape) final fixtureDef = FixtureDef(shape)..isSensor = true;
..isSensor = true
..filter.categoryBits = _categoryBits;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..userData = this ..userData = this
..position = _position ..position = _position
..type = BodyType.static; ..type = BodyType.static;
return world.createBody(bodyDef)..createFixture(fixtureDef); final body = world.createBody(bodyDef);
body.createFixture(fixtureDef).filterData.categoryBits = _categoryBits;
return body;
} }
} }
/// {@template ramp_area_callback} /// {@template ramp_opening_ball_contact_callback}
/// Listens when a [Ball] goes through a [RampArea] and gets into a [Pathway] /// Detects when a [Ball] enters or exits a [Pathway] ramp through a
/// ramp, in order to avoid collisions with other crossing ramps. /// [RampOpening].
/// Modifies [Ball]'s maskBits while is inside the ramp. When exits sets [Ball] /// Modifies [Ball]'s maskBits while is inside the ramp. When [Ball] exits,
/// maskBits to collide with all elements. /// sets maskBits to collide with all elements.
/// {@endtemplate} /// {@endtemplate}
abstract class RampAreaCallback<Area extends RampArea> abstract class RampOpeningBallContactCallback<Area extends RampOpening>
extends ContactCallback<Ball, Area> { extends ContactCallback<Ball, Area> {
/// Collection of balls inside ramp pathway. /// Collection of balls inside ramp pathway.
Set get ballsInside; Set get ballsInside;

@ -7,13 +7,13 @@ import 'package:pinball/game/game.dart';
/// Represents the upper left blue ramp for the game. /// Represents the upper left blue ramp for the game.
/// ///
/// Composed of a [Pathway.arc] defining the ramp, and two /// Composed of a [Pathway.arc] defining the ramp, and two
/// [JetpackRampArea]s at the entrance and exit of the ramp. /// [JetpackRampOpening]s at the entrance and exit of the ramp.
/// {@endtemplate} /// {@endtemplate}
class JetpackRamp extends PositionComponent with HasGameRef<PinballGame> { class JetpackRamp extends Component with HasGameRef<PinballGame> {
/// {@macro jetpack_ramp} /// {@macro jetpack_ramp}
JetpackRamp({ JetpackRamp({
required Vector2 position, required this.position,
}) : _position = position; });
final double _radius = 200; final double _radius = 200;
final double _width = 80; final double _width = 80;
@ -21,14 +21,16 @@ class JetpackRamp extends PositionComponent with HasGameRef<PinballGame> {
final double _rotation = radians(-10); final double _rotation = radians(-10);
final double _entranceRotation = radians(15); final double _entranceRotation = radians(15);
final double _exitRotation = radians(-5); final double _exitRotation = radians(-5);
final Vector2 _position;
/// The position of this [JetpackRamp]
final Vector2 position;
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await add( await add(
Pathway.arc( Pathway.arc(
color: const Color.fromARGB(255, 8, 218, 241), color: const Color.fromARGB(255, 8, 218, 241),
position: _position, position: position,
width: _width, width: _width,
radius: _radius, radius: _radius,
angle: _angle, angle: _angle,
@ -38,33 +40,33 @@ class JetpackRamp extends PositionComponent with HasGameRef<PinballGame> {
); );
await add( await add(
JetpackRampArea( JetpackRampOpening(
position: _position + Vector2(-10.5, 0), position: position + Vector2(-10.5, 0),
rotation: _entranceRotation, rotation: _entranceRotation,
orientation: RampOrientation.down, orientation: RampOrientation.down,
), ),
); );
await add( await add(
JetpackRampArea( JetpackRampOpening(
position: _position + Vector2(20.5, 3), position: position + Vector2(20.5, 3),
rotation: _exitRotation, rotation: _exitRotation,
orientation: RampOrientation.down, orientation: RampOrientation.down,
), ),
); );
gameRef.addContactCallback(JetpackRampAreaCallback()); gameRef.addContactCallback(JetpackRampOpeningBallContactCallback());
} }
} }
/// {@template jetpack_ramp_area} /// {@template jetpack_ramp_opening}
/// Implementation of [RampArea] for sensors in [JetpackRamp]. /// Implementation of [RampOpening] for sensors in [JetpackRamp].
/// ///
/// [RampArea] with [RampType.jetpack] to filter [Ball]s collisions /// [RampOpening] with [RampType.jetpack] to filter [Ball]s collisions
/// inside [JetpackRamp]. /// inside [JetpackRamp].
/// {@endtemplate} /// {@endtemplate}
class JetpackRampArea extends RampArea { class JetpackRampOpening extends RampOpening {
/// {@macro jetpack_ramp_area} /// {@macro jetpack_ramp_opening}
JetpackRampArea({ JetpackRampOpening({
required Vector2 position, required Vector2 position,
double rotation = 0, double rotation = 0,
required RampOrientation orientation, required RampOrientation orientation,
@ -76,14 +78,14 @@ class JetpackRampArea extends RampArea {
); );
/// Orientation of entrance/exit of [JetpackRamp] where /// Orientation of entrance/exit of [JetpackRamp] where
/// this [JetpackRampArea] is placed. /// this [JetpackRampOpening] is placed.
final RampOrientation _orientation; final RampOrientation _orientation;
/// Rotation of the [RampArea] to place it right at the /// Rotation of the [RampOpening] to place it right at the
/// entrance/exit of [JetpackRamp]. /// entrance/exit of [JetpackRamp].
final double _rotation; final double _rotation;
/// Size of the [RampArea] placed at the entrance/exit of [JetpackRamp]. /// Size of the [RampOpening] placed at the entrance/exit of [JetpackRamp].
final int _size = 7; final int _size = 7;
@override @override
@ -99,13 +101,14 @@ class JetpackRampArea extends RampArea {
]); ]);
} }
/// {@template jetpack_ramp_area_callback} /// {@template jetpack_ramp_opening_ball_contact_callback}
/// Implementation of [RampAreaCallback] to listen when a [Ball] /// Implementation of [RampOpeningBallContactCallback] to listen when a [Ball]
/// gets into a [JetpackRampArea]. /// gets into a [JetpackRampOpening].
/// {@endtemplate} /// {@endtemplate}
class JetpackRampAreaCallback extends RampAreaCallback<JetpackRampArea> { class JetpackRampOpeningBallContactCallback
/// {@macro jetpack_ramp_area_callback} extends RampOpeningBallContactCallback<JetpackRampOpening> {
JetpackRampAreaCallback() : super(); /// {@macro jetpack_ramp_opening_ball_contact_callback}
JetpackRampOpeningBallContactCallback() : super();
/// Collection of balls inside [JetpackRamp]. /// Collection of balls inside [JetpackRamp].
final _ballsInsideJetpack = <Ball>{}; final _ballsInsideJetpack = <Ball>{};

@ -7,27 +7,28 @@ import 'package:pinball/game/game.dart';
/// Represent the upper right yellow ramp for the game. /// Represent the upper right yellow ramp for the game.
/// ///
/// Group of [Component]s composed by a [Pathway.arc] as the ramp, and two /// Group of [Component]s composed by a [Pathway.arc] as the ramp, and two
/// [SparkyRampArea] at the entrance and exit of the ramp, to detect when /// [SparkyRampOpening] at the entrance and exit of the ramp, to detect when
/// a ball gets into/out of the ramp. /// a ball gets into/out of the ramp.
/// {@endtemplate} /// {@endtemplate}
class SparkyRamp extends PositionComponent with HasGameRef<PinballGame> { class SparkyRamp extends Component with HasGameRef<PinballGame> {
/// {@macro sparky_ramp} /// {@macro sparky_ramp}
SparkyRamp({ SparkyRamp({
required Vector2 position, required this.position,
}) : _position = position, });
super();
final double _radius = 300; final double _radius = 300;
final double _width = 80; final double _width = 80;
final double _angle = radians(200); final double _angle = radians(200);
final Vector2 _position;
/// The position of this [SparkyRamp]
final Vector2 position;
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await add( await add(
Pathway.arc( Pathway.arc(
color: const Color.fromARGB(255, 251, 255, 0), color: const Color.fromARGB(255, 251, 255, 0),
position: _position, position: position,
radius: _radius, radius: _radius,
angle: _angle, angle: _angle,
width: _width, width: _width,
@ -35,32 +36,32 @@ class SparkyRamp extends PositionComponent with HasGameRef<PinballGame> {
), ),
); );
await add( await add(
SparkyRampArea( SparkyRampOpening(
position: _position + Vector2(-18, -2), position: position + Vector2(-18, -2),
orientation: RampOrientation.down, orientation: RampOrientation.down,
rotation: radians(13), rotation: radians(13),
), ),
); );
await add( await add(
SparkyRampArea( SparkyRampOpening(
position: _position + Vector2(33, 6), position: position + Vector2(33, 6),
orientation: RampOrientation.down, orientation: RampOrientation.down,
), ),
); );
gameRef.addContactCallback(SparkyRampAreaCallback()); gameRef.addContactCallback(SparkyRampOpeningBallContactCallback());
} }
} }
/// {@template sparky_ramp_area} /// {@template sparky_ramp_opening}
/// Implementation of [RampArea] for sensors in [SparkyRamp]. /// Implementation of [RampOpening] for sensors in [SparkyRamp].
/// ///
/// [RampArea] with [RampType.sparky] to filter [Ball]s collisions /// [RampOpening] with [RampType.sparky] to filter [Ball]s collisions
/// inside [SparkyRamp]. /// inside [SparkyRamp].
/// {@endtemplate} /// {@endtemplate}
class SparkyRampArea extends RampArea { class SparkyRampOpening extends RampOpening {
/// {@macro sparky_ramp_area} /// {@macro sparky_ramp_opening}
SparkyRampArea({ SparkyRampOpening({
required Vector2 position, required Vector2 position,
double rotation = 0, double rotation = 0,
required RampOrientation orientation, required RampOrientation orientation,
@ -72,14 +73,14 @@ class SparkyRampArea extends RampArea {
); );
/// Orientation of entrance/exit of [SparkyRamp] where /// Orientation of entrance/exit of [SparkyRamp] where
/// this [SparkyRampArea] is placed. /// this [SparkyRampOpening] is placed.
final RampOrientation _orientation; final RampOrientation _orientation;
/// Rotation of the [RampArea] to place it right at the /// Rotation of the [RampOpening] to place it right at the
/// entrance/exit of [SparkyRamp]. /// entrance/exit of [SparkyRamp].
final double _rotation; final double _rotation;
/// Size of the [RampArea] placed at the entrance/exit of [SparkyRamp]. /// Size of the [RampOpening] placed at the entrance/exit of [SparkyRamp].
final int _size = 7; final int _size = 7;
@override @override
@ -95,13 +96,14 @@ class SparkyRampArea extends RampArea {
]); ]);
} }
/// {@template sparky_ramp_area_callback} /// {@template sparky_ramp_opening_ball_contact_callback}
/// Implementation of [RampAreaCallback] to listen when a [Ball] /// Implementation of [RampOpeningBallContactCallback] to listen when a [Ball]
/// gets into a [SparkyRampArea]. /// gets into a [SparkyRampOpening].
/// {@endtemplate} /// {@endtemplate}
class SparkyRampAreaCallback extends RampAreaCallback<SparkyRampArea> { class SparkyRampOpeningBallContactCallback
/// {@macro sparky_ramp_area_callback} extends RampOpeningBallContactCallback<SparkyRampOpening> {
SparkyRampAreaCallback() : super(); /// {@macro sparky_ramp_opening_ball_contact_callback}
SparkyRampOpeningBallContactCallback() : super();
/// Collection of balls inside [SparkyRamp]. /// Collection of balls inside [SparkyRamp].
final _ballsInsideSparky = <Ball>{}; final _ballsInsideSparky = <Ball>{};

@ -7,7 +7,7 @@ import 'package:pinball/game/game.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
class TestRampArea extends RampArea { class TestRampArea extends RampOpening {
TestRampArea({ TestRampArea({
required Vector2 position, required Vector2 position,
required RampOrientation orientation, required RampOrientation orientation,
@ -30,7 +30,8 @@ class TestRampArea extends RampArea {
]); ]);
} }
class TestRampAreaCallback extends RampAreaCallback<TestRampArea> { class TestRampAreaCallback
extends RampOpeningBallContactCallback<TestRampArea> {
TestRampAreaCallback() : super(); TestRampAreaCallback() : super();
final _ballsInside = <Ball>{}; final _ballsInside = <Ball>{};

@ -9,7 +9,7 @@ import 'package:pinball/game/game.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
class MockJetpackRampArea extends Mock implements JetpackRampArea {} class MockJetpackRampArea extends Mock implements JetpackRampOpening {}
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
@ -33,7 +33,7 @@ void main() {
flameTester.test( flameTester.test(
'positions correctly', 'positions correctly',
(game) async { (game) async {
final position = Vector2.zero(); final position = Vector2.all(10);
final ramp = JetpackRamp( final ramp = JetpackRamp(
position: position, position: position,
); );
@ -72,7 +72,8 @@ void main() {
await game.ready(); await game.ready();
await game.ensureAdd(ramp); await game.ensureAdd(ramp);
final rampAreas = ramp.children.whereType<JetpackRampArea>().toList(); final rampAreas =
ramp.children.whereType<JetpackRampOpening>().toList();
expect(rampAreas.length, 2); expect(rampAreas.length, 2);
}, },
); );
@ -84,7 +85,7 @@ void main() {
'orientation is down', 'orientation is down',
(game) async { (game) async {
final position = Vector2.all(10); final position = Vector2.all(10);
final ramp = JetpackRampArea( final ramp = JetpackRampOpening(
position: position, position: position,
orientation: RampOrientation.down, orientation: RampOrientation.down,
); );
@ -98,7 +99,8 @@ void main() {
group('JetpackRampAreaCallback', () { group('JetpackRampAreaCallback', () {
test('has no ball inside on creation', () { test('has no ball inside on creation', () {
expect(JetpackRampAreaCallback().ballsInside, equals(<Ball>{})); expect(JetpackRampOpeningBallContactCallback().ballsInside,
equals(<Ball>{}));
}); });
}); });
} }

@ -9,7 +9,7 @@ import 'package:pinball/game/game.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
class MockSparkyRampArea extends Mock implements SparkyRampArea {} class MockSparkyRampArea extends Mock implements SparkyRampOpening {}
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
@ -33,7 +33,7 @@ void main() {
flameTester.test( flameTester.test(
'positions correctly', 'positions correctly',
(game) async { (game) async {
final position = Vector2.zero(); final position = Vector2.all(10);
final ramp = SparkyRamp( final ramp = SparkyRamp(
position: position, position: position,
); );
@ -72,7 +72,8 @@ void main() {
await game.ready(); await game.ready();
await game.ensureAdd(ramp); await game.ensureAdd(ramp);
final rampAreas = ramp.children.whereType<SparkyRampArea>().toList(); final rampAreas =
ramp.children.whereType<SparkyRampOpening>().toList();
expect(rampAreas.length, 2); expect(rampAreas.length, 2);
}, },
); );
@ -84,7 +85,7 @@ void main() {
'orientation is down', 'orientation is down',
(game) async { (game) async {
final position = Vector2.all(10); final position = Vector2.all(10);
final ramp = SparkyRampArea( final ramp = SparkyRampOpening(
position: position, position: position,
orientation: RampOrientation.down, orientation: RampOrientation.down,
); );
@ -98,7 +99,8 @@ void main() {
group('SparkyRampAreaCallback', () { group('SparkyRampAreaCallback', () {
test('has no ball inside on creation', () { test('has no ball inside on creation', () {
expect(SparkyRampAreaCallback().ballsInside, equals(<Ball>{})); expect(
SparkyRampOpeningBallContactCallback().ballsInside, equals(<Ball>{}));
}); });
}); });
} }

@ -18,9 +18,10 @@ class MockBall extends Mock implements Ball {}
class MockContact extends Mock implements Contact {} class MockContact extends Mock implements Contact {}
class MockArea extends Mock implements RampArea {} class MockRampOpening extends Mock implements RampOpening {}
class MockRampAreaCallback extends Mock implements RampAreaCallback {} class MockRampOpeningBallContactCallback extends Mock
implements RampOpeningBallContactCallback {}
class MockGameBloc extends Mock implements GameBloc {} class MockGameBloc extends Mock implements GameBloc {}

Loading…
Cancel
Save