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

* refactor: renamed SlingShot to Kicker
pull/71/head
Alejandro Santiago 4 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} /// {@template board}
/// The main flat surface of the [PinballGame], where the [Flipper]s, /// The main flat surface of the [PinballGame], where the [Flipper]s,
/// [RoundBumper]s, [SlingShot]s are arranged. /// [RoundBumper]s, [Kicker]s are arranged.
/// {entemplate} /// {entemplate}
class Board extends Component { class Board extends Component {
/// {@macro board} /// {@macro board}
@ -76,7 +76,7 @@ class _FlutterForest extends Component {
/// {@template bottom_group} /// {@template bottom_group}
/// Grouping of the board's bottom [Component]s. /// 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} /// {@endtemplate}
// TODO(alestiago): Consider renaming once entire Board is defined. // TODO(alestiago): Consider renaming once entire Board is defined.
class _BottomGroup extends Component { class _BottomGroup extends Component {
@ -138,14 +138,14 @@ class _BottomGroupSide extends Component {
(Flipper.size.x * direction) - direction, (Flipper.size.x * direction) - direction,
Flipper.size.y, Flipper.size.y,
); );
final slingShot = SlingShot( final kicker = Kicker(
side: _side, side: _side,
)..initialPosition = _position + )..initialPosition = _position +
Vector2( Vector2(
(Flipper.size.x) * direction, (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. /// Indicates a side of the board.
/// ///
/// Usually used to position or mirror elements of a [PinballGame]; such as a /// Usually used to position or mirror elements of a [PinballGame]; such as a
/// [Flipper] or [SlingShot]. /// [Flipper] or [Kicker].
enum BoardSide { enum BoardSide {
/// The left side of the board. /// The left side of the board.
left, left,

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

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

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

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