refactor: rename `SlingShot` to `Kicker` (#68)

* refactor: renamed SlingShot to Kicker
pull/71/head
Alejandro Santiago 3 years ago committed by GitHub
parent 5b355ff406
commit 79bb95bef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,7 @@ import 'package:pinball/game/game.dart';
/// {@template board}
/// The main flat surface of the [PinballGame], where the [Flipper]s,
/// [RoundBumper]s, [SlingShot]s are arranged.
/// [RoundBumper]s, [Kicker]s are arranged.
/// {entemplate}
class Board extends Component {
/// {@macro board}
@ -76,7 +76,7 @@ class _FlutterForest extends Component {
/// {@template bottom_group}
/// Grouping of the board's bottom [Component]s.
///
/// The [_BottomGroup] consists of[Flipper]s, [Baseboard]s and [SlingShot]s.
/// The [_BottomGroup] consists of[Flipper]s, [Baseboard]s and [Kicker]s.
/// {@endtemplate}
// TODO(alestiago): Consider renaming once entire Board is defined.
class _BottomGroup extends Component {
@ -138,14 +138,14 @@ class _BottomGroupSide extends Component {
(Flipper.size.x * direction) - direction,
Flipper.size.y,
);
final slingShot = SlingShot(
final kicker = Kicker(
side: _side,
)..initialPosition = _position +
Vector2(
(Flipper.size.x) * direction,
Flipper.size.y + SlingShot.size.y,
Flipper.size.y + Kicker.size.y,
);
await addAll([flipper, baseboard, slingShot]);
await addAll([flipper, baseboard, kicker]);
}
}

@ -3,7 +3,7 @@ import 'package:pinball/game/game.dart';
/// Indicates a side of the board.
///
/// Usually used to position or mirror elements of a [PinballGame]; such as a
/// [Flipper] or [SlingShot].
/// [Flipper] or [Kicker].
enum BoardSide {
/// The left side of the board.
left,

@ -7,6 +7,7 @@ export 'flipper.dart';
export 'initial_position.dart';
export 'jetpack_ramp.dart';
export 'joint_anchor.dart';
export 'kicker.dart';
export 'launcher_ramp.dart';
export 'layer.dart';
export 'pathway.dart';
@ -14,6 +15,5 @@ export 'plunger.dart';
export 'ramp_opening.dart';
export 'round_bumper.dart';
export 'score_points.dart';
export 'sling_shot.dart';
export 'spaceship.dart';
export 'wall.dart';

@ -6,15 +6,15 @@ import 'package:flutter/material.dart';
import 'package:geometry/geometry.dart' as geometry show centroid;
import 'package:pinball/game/game.dart';
/// {@template sling_shot}
/// {@template kicker}
/// Triangular [BodyType.static] body that propels the [Ball] towards the
/// opposite side.
///
/// [SlingShot]s are usually positioned above each [Flipper].
/// {@endtemplate sling_shot}
class SlingShot extends BodyComponent with InitialPosition {
/// {@macro sling_shot}
SlingShot({
/// [Kicker]s are usually positioned above each [Flipper].
/// {@endtemplate kicker}
class Kicker extends BodyComponent with InitialPosition {
/// {@macro kicker}
Kicker({
required BoardSide side,
}) : _side = side {
// TODO(alestiago): Use sprite instead of color when provided.
@ -23,14 +23,14 @@ class SlingShot extends BodyComponent with InitialPosition {
..style = PaintingStyle.fill;
}
/// Whether the [SlingShot] is on the left or right side of the board.
/// Whether the [Kicker] is on the left or right side of the board.
///
/// A [SlingShot] with [BoardSide.left] propels the [Ball] to the right,
/// whereas a [SlingShot] with [BoardSide.right] propels the [Ball] to the
/// A [Kicker] with [BoardSide.left] propels the [Ball] to the right,
/// whereas a [Kicker] with [BoardSide.right] propels the [Ball] to the
/// left.
final BoardSide _side;
/// The size of the [SlingShot] body.
/// The size of the [Kicker] body.
// TODO(alestiago): Use size from PositionedBodyComponent instead,
// once a sprite is given.
static final Vector2 size = Vector2(4, 10);
@ -78,7 +78,7 @@ class SlingShot extends BodyComponent with InitialPosition {
final bottomLineFixtureDef = FixtureDef(bottomEdge)..friction = 0;
fixturesDefs.add(bottomLineFixtureDef);
final kickerEdge = EdgeShape()
final bouncyEdge = EdgeShape()
..set(
upperCircle.position +
Vector2(
@ -92,11 +92,11 @@ class SlingShot extends BodyComponent with InitialPosition {
),
);
final kickerFixtureDef = FixtureDef(kickerEdge)
final bouncyFixtureDef = FixtureDef(bouncyEdge)
// TODO(alestiago): Play with restitution value once game is bundled.
..restitution = 10.0
..friction = 0;
fixturesDefs.add(kickerFixtureDef);
fixturesDefs.add(bouncyFixtureDef);
// TODO(alestiago): Evaluate if there is value on centering the fixtures.
final centroid = geometry.centroid(

@ -65,14 +65,14 @@ void main() {
);
flameTester.test(
'has two SlingShots',
'has two Kickers',
(game) async {
final board = Board(size: Vector2.all(500));
await game.ready();
await game.ensureAdd(board);
final slingShots = board.findNestedChildren<SlingShot>();
expect(slingShots.length, equals(2));
final kickers = board.findNestedChildren<Kicker>();
expect(kickers.length, equals(2));
},
);

@ -6,43 +6,43 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
void main() {
group('SlingShot', () {
group('Kicker', () {
// TODO(alestiago): Include golden tests for left and right.
final flameTester = FlameTester(Forge2DGame.new);
flameTester.test(
'loads correctly',
(game) async {
final slingShot = SlingShot(
final kicker = Kicker(
side: BoardSide.left,
);
await game.ensureAdd(slingShot);
await game.ensureAdd(kicker);
expect(game.contains(slingShot), isTrue);
expect(game.contains(kicker), isTrue);
},
);
flameTester.test(
'body is static',
(game) async {
final slingShot = SlingShot(
final kicker = Kicker(
side: BoardSide.left,
);
await game.ensureAdd(slingShot);
await game.ensureAdd(kicker);
expect(slingShot.body.bodyType, equals(BodyType.static));
expect(kicker.body.bodyType, equals(BodyType.static));
},
);
flameTester.test(
'has restitution',
(game) async {
final slingShot = SlingShot(
final kicker = Kicker(
side: BoardSide.left,
);
await game.ensureAdd(slingShot);
await game.ensureAdd(kicker);
final totalRestitution = slingShot.body.fixtures.fold<double>(
final totalRestitution = kicker.body.fixtures.fold<double>(
0,
(total, fixture) => total + fixture.restitution,
);
@ -53,12 +53,12 @@ void main() {
flameTester.test(
'has no friction',
(game) async {
final slingShot = SlingShot(
final kicker = Kicker(
side: BoardSide.left,
);
await game.ensureAdd(slingShot);
await game.ensureAdd(kicker);
final totalFriction = slingShot.body.fixtures.fold<double>(
final totalFriction = kicker.body.fixtures.fold<double>(
0,
(total, fixture) => total + fixture.friction,
);
Loading…
Cancel
Save