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,
}
/// 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.
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.
///
/// Detects when a [Ball] goes through it,
/// Collisions with [RampArea] are listened by [RampAreaCallback].
/// [RampOpeningBallContactCallback] detects when a [Ball] passes
/// through this opening.
/// Collisions with [RampOpening] are listened
/// by [RampOpeningBallContactCallback].
/// {@endtemplate}
abstract class RampArea extends BodyComponent {
/// {@macro ramp_area}
RampArea({
abstract class RampOpening extends BodyComponent {
/// {@macro ramp_opening}
RampOpening({
required Vector2 position,
required int categoryBits,
}) : _position = position,
@ -66,37 +68,38 @@ abstract class RampArea extends BodyComponent {
final Vector2 _position;
final int _categoryBits;
/// Mask of category bits for collision with [RampArea]
/// Mask of category bits for collision with [RampOpening]
int get categoryBits => _categoryBits;
/// The [Shape] of the [RampArea]
/// The [Shape] of the [RampOpening]
Shape get shape;
/// Orientation of the [RampArea] entrance/exit
/// Orientation of the [RampOpening] entrance/exit
RampOrientation get orientation;
@override
Body createBody() {
final fixtureDef = FixtureDef(shape)
..isSensor = true
..filter.categoryBits = _categoryBits;
final fixtureDef = FixtureDef(shape)..isSensor = true;
final bodyDef = BodyDef()
..userData = this
..position = _position
..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}
/// Listens when a [Ball] goes through a [RampArea] and gets into a [Pathway]
/// ramp, in order to avoid collisions with other crossing ramps.
/// Modifies [Ball]'s maskBits while is inside the ramp. When exits sets [Ball]
/// maskBits to collide with all elements.
/// {@template ramp_opening_ball_contact_callback}
/// Detects when a [Ball] enters or exits a [Pathway] ramp through a
/// [RampOpening].
/// Modifies [Ball]'s maskBits while is inside the ramp. When [Ball] exits,
/// sets maskBits to collide with all elements.
/// {@endtemplate}
abstract class RampAreaCallback<Area extends RampArea>
abstract class RampOpeningBallContactCallback<Area extends RampOpening>
extends ContactCallback<Ball, Area> {
/// Collection of balls inside ramp pathway.
Set get ballsInside;

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

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

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

@ -9,7 +9,7 @@ import 'package:pinball/game/game.dart';
import '../../helpers/helpers.dart';
class MockJetpackRampArea extends Mock implements JetpackRampArea {}
class MockJetpackRampArea extends Mock implements JetpackRampOpening {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
@ -33,7 +33,7 @@ void main() {
flameTester.test(
'positions correctly',
(game) async {
final position = Vector2.zero();
final position = Vector2.all(10);
final ramp = JetpackRamp(
position: position,
);
@ -72,7 +72,8 @@ void main() {
await game.ready();
await game.ensureAdd(ramp);
final rampAreas = ramp.children.whereType<JetpackRampArea>().toList();
final rampAreas =
ramp.children.whereType<JetpackRampOpening>().toList();
expect(rampAreas.length, 2);
},
);
@ -84,7 +85,7 @@ void main() {
'orientation is down',
(game) async {
final position = Vector2.all(10);
final ramp = JetpackRampArea(
final ramp = JetpackRampOpening(
position: position,
orientation: RampOrientation.down,
);
@ -98,7 +99,8 @@ void main() {
group('JetpackRampAreaCallback', () {
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';
class MockSparkyRampArea extends Mock implements SparkyRampArea {}
class MockSparkyRampArea extends Mock implements SparkyRampOpening {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
@ -33,7 +33,7 @@ void main() {
flameTester.test(
'positions correctly',
(game) async {
final position = Vector2.zero();
final position = Vector2.all(10);
final ramp = SparkyRamp(
position: position,
);
@ -72,7 +72,8 @@ void main() {
await game.ready();
await game.ensureAdd(ramp);
final rampAreas = ramp.children.whereType<SparkyRampArea>().toList();
final rampAreas =
ramp.children.whereType<SparkyRampOpening>().toList();
expect(rampAreas.length, 2);
},
);
@ -84,7 +85,7 @@ void main() {
'orientation is down',
(game) async {
final position = Vector2.all(10);
final ramp = SparkyRampArea(
final ramp = SparkyRampOpening(
position: position,
orientation: RampOrientation.down,
);
@ -98,7 +99,8 @@ void main() {
group('SparkyRampAreaCallback', () {
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 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 {}

Loading…
Cancel
Save