refactor: migrated to zIndex

pull/282/head
alestiago 3 years ago
parent 39715de5aa
commit ca8cc6cb81

@ -1,19 +1,21 @@
// ignore_for_file: avoid_renaming_method_parameters // ignore_for_file: avoid_renaming_method_parameters
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame/components.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template android_acres} /// {@template android_acres}
/// Area positioned on the left side of the board containing the /// Area positioned on the left side of the board containing the
/// [AndroidSpaceship], [SpaceshipRamp], [SpaceshipRail], and [AndroidBumper]s. /// [AndroidSpaceship], [SpaceshipRamp], [SpaceshipRail], and [AndroidBumper]s.
/// {@endtemplate} /// {@endtemplate}
class AndroidAcres extends Blueprint { class AndroidAcres extends Component {
/// {@macro android_acres} /// {@macro android_acres}
AndroidAcres() AndroidAcres()
: super( : super(
components: [ children: [
SpaceshipRamp(),
SpaceshipRail(),
AndroidSpaceship(position: Vector2(-26.5, -28.5)),
AndroidBumper.a( AndroidBumper.a(
children: [ children: [
ScoringBehavior(points: 20000), ScoringBehavior(points: 20000),
@ -30,10 +32,5 @@ class AndroidAcres extends Blueprint {
], ],
)..initialPosition = Vector2(-20.5, -13.8), )..initialPosition = Vector2(-20.5, -13.8),
], ],
blueprints: [
SpaceshipRamp(),
AndroidSpaceship(position: Vector2(-26.5, -28.5)),
SpaceshipRail(),
],
); );
} }

@ -17,9 +17,8 @@ class BottomGroup extends Component with Rendering {
_BottomGroupSide(side: BoardSide.right), _BottomGroupSide(side: BoardSide.right),
_BottomGroupSide(side: BoardSide.left), _BottomGroupSide(side: BoardSide.left),
], ],
priority: RenderPriority.bottomGroup,
) { ) {
zIndex = 2; zIndex = RenderPriority.bottomGroup;
} }
} }

@ -20,6 +20,7 @@ class ControlledBall extends Ball with Controls<BallController> {
}) : super(baseColor: characterTheme.ballColor) { }) : super(baseColor: characterTheme.ballColor) {
controller = BallController(this); controller = BallController(this);
layer = Layer.launcher; layer = Layer.launcher;
zIndex = RenderPriority.ballOnLaunchRamp;
} }
/// {@template bonus_ball} /// {@template bonus_ball}
@ -29,13 +30,13 @@ class ControlledBall extends Ball with Controls<BallController> {
required CharacterTheme characterTheme, required CharacterTheme characterTheme,
}) : super(baseColor: characterTheme.ballColor) { }) : super(baseColor: characterTheme.ballColor) {
controller = BallController(this); controller = BallController(this);
priority = RenderPriority.ballOnBoard; zIndex = RenderPriority.ballOnBoard;
} }
/// [Ball] used in [DebugPinballGame]. /// [Ball] used in [DebugPinballGame].
ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) { ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) {
controller = BallController(this); controller = BallController(this);
priority = RenderPriority.ballOnBoard; zIndex = RenderPriority.ballOnBoard;
} }
} }

@ -9,14 +9,12 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@endtemplate} /// {@endtemplate}
// TODO(allisonryan0002): use a controller to initiate dino bonus when dino is // TODO(allisonryan0002): use a controller to initiate dino bonus when dino is
// fully implemented. // fully implemented.
class DinoDesert extends Blueprint { class DinoDesert extends Component {
/// {@macro dino_desert} /// {@macro dino_desert}
DinoDesert() DinoDesert()
: super( : super(
components: [ children: [
// ChromeDino()..initialPosition = Vector2(12.3, -6.9), // ChromeDino()..initialPosition = Vector2(12.3, -6.9),
],
blueprints: [
DinoWalls(), DinoWalls(),
], ],
); );

@ -5,12 +5,13 @@ import 'package:flutter/material.dart';
import 'package:pinball/game/components/flutter_forest/behaviors/behaviors.dart'; import 'package:pinball/game/components/flutter_forest/behaviors/behaviors.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template flutter_forest} /// {@template flutter_forest}
/// Area positioned at the top right of the board where the [Ball] can bounce /// Area positioned at the top right of the board where the [Ball] can bounce
/// off [DashNestBumper]s. /// off [DashNestBumper]s.
/// {@endtemplate} /// {@endtemplate}
class FlutterForest extends Component { class FlutterForest extends Component with Rendering {
/// {@macro flutter_forest} /// {@macro flutter_forest}
FlutterForest() FlutterForest()
: super( : super(
@ -38,7 +39,9 @@ class FlutterForest extends Component {
DashAnimatronic()..position = Vector2(20, -66), DashAnimatronic()..position = Vector2(20, -66),
FlutterForestBonusBehavior(), FlutterForestBonusBehavior(),
], ],
); ) {
zIndex = RenderPriority.flutterForest;
}
/// Creates a [FlutterForest] without any children. /// Creates a [FlutterForest] without any children.
/// ///

@ -3,11 +3,12 @@ import 'package:flutter/material.dart';
import 'package:pinball/game/components/google_word/behaviors/behaviors.dart'; import 'package:pinball/game/components/google_word/behaviors/behaviors.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template google_word} /// {@template google_word}
/// Loads all [GoogleLetter]s to compose a [GoogleWord]. /// Loads all [GoogleLetter]s to compose a [GoogleWord].
/// {@endtemplate} /// {@endtemplate}
class GoogleWord extends Component { class GoogleWord extends Component with Rendering {
/// {@macro google_word} /// {@macro google_word}
GoogleWord({ GoogleWord({
required Vector2 position, required Vector2 position,
@ -39,7 +40,9 @@ class GoogleWord extends Component {
)..initialPosition = position + Vector2(12.92, 1.82), )..initialPosition = position + Vector2(12.92, 1.82),
GoogleWordBonusBehavior(), GoogleWordBonusBehavior(),
], ],
); ) {
zIndex = RenderPriority.decal;
}
/// Creates a [GoogleWord] without any children. /// Creates a [GoogleWord] without any children.
/// ///

@ -3,11 +3,12 @@ import 'package:flame/components.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball/game/components/multipliers/behaviors/behaviors.dart'; import 'package:pinball/game/components/multipliers/behaviors/behaviors.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template multipliers} /// {@template multipliers}
/// A group for the multipliers on the board. /// A group for the multipliers on the board.
/// {@endtemplate} /// {@endtemplate}
class Multipliers extends Component { class Multipliers extends Component with Rendering {
/// {@macro multipliers} /// {@macro multipliers}
Multipliers() Multipliers()
: super( : super(
@ -34,7 +35,9 @@ class Multipliers extends Component {
), ),
MultipliersBehavior(), MultipliersBehavior(),
], ],
); ) {
zIndex = RenderPriority.decal;
}
/// Creates [Multipliers] without any children. /// Creates [Multipliers] without any children.
/// ///

@ -24,11 +24,11 @@ class ScoringBehavior extends ContactBehavior with HasGameRef<PinballGame> {
gameRef.read<GameBloc>().add(Scored(points: _points)); gameRef.read<GameBloc>().add(Scored(points: _points));
gameRef.audio.score(); gameRef.audio.score();
gameRef.add( gameRef.firstChild<PinballCanvasComponent>()?.add(
ScoreText( ScoreText(
text: _points.toString(), text: _points.toString(),
position: other.body.position, position: other.body.position,
), ),
); );
} }
} }

@ -1,5 +1,6 @@
// ignore_for_file: avoid_renaming_method_parameters // ignore_for_file: avoid_renaming_method_parameters
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
@ -9,11 +10,11 @@ import 'package:pinball_flame/pinball_flame.dart';
/// Area positioned at the top left of the board containing the /// Area positioned at the top left of the board containing the
/// [SparkyComputer], [SparkyAnimatronic], and [SparkyBumper]s. /// [SparkyComputer], [SparkyAnimatronic], and [SparkyBumper]s.
/// {@endtemplate} /// {@endtemplate}
class SparkyScorch extends Blueprint { class SparkyScorch extends Component {
/// {@macro sparky_scorch} /// {@macro sparky_scorch}
SparkyScorch() SparkyScorch()
: super( : super(
components: [ children: [
SparkyBumper.a( SparkyBumper.a(
children: [ children: [
ScoringBehavior(points: 20000), ScoringBehavior(points: 20000),
@ -31,8 +32,6 @@ class SparkyScorch extends Blueprint {
)..initialPosition = Vector2(-3.3, -52.55), )..initialPosition = Vector2(-3.3, -52.55),
SparkyComputerSensor()..initialPosition = Vector2(-13, -49.8), SparkyComputerSensor()..initialPosition = Vector2(-13, -49.8),
SparkyAnimatronic()..position = Vector2(-13.8, -58.2), SparkyAnimatronic()..position = Vector2(-13.8, -58.2),
],
blueprints: [
SparkyComputer(), SparkyComputer(),
], ],
); );

@ -62,16 +62,15 @@ class PinballGame extends Forge2DGame
BoardDimensions.bounds.center.dy + 1.8, BoardDimensions.bounds.center.dy + 1.8,
), ),
), ),
Slingshots(),
Boundaries(),
DinoDesert(),
SparkyScorch(),
AndroidAcres(),
], ],
), ),
); );
await addFromBlueprint(Boundaries());
await addFromBlueprint(SparkyScorch());
await addFromBlueprint(AndroidAcres());
await addFromBlueprint(DinoDesert());
await addFromBlueprint(Slingshots());
await super.onLoad(); await super.onLoad();
} }
@ -205,7 +204,9 @@ class DebugPinballGame extends PinballGame with FPSCounter {
super.onTapUp(info); super.onTapUp(info);
if (info.raw.kind == PointerDeviceKind.mouse) { if (info.raw.kind == PointerDeviceKind.mouse) {
add(ControlledBall.debug()..initialPosition = info.eventPosition.game); final ball = ControlledBall.debug()
..initialPosition = info.eventPosition.game;
firstChild<PinballCanvasComponent>()?.add(ball);
} }
} }
} }

@ -12,7 +12,7 @@ export 'cubit/android_bumper_cubit.dart';
/// {@template android_bumper} /// {@template android_bumper}
/// Bumper for area under the [AndroidSpaceship]. /// Bumper for area under the [AndroidSpaceship].
/// {@endtemplate} /// {@endtemplate}
class AndroidBumper extends BodyComponent with InitialPosition { class AndroidBumper extends BodyComponent with InitialPosition, Rendering {
/// {@macro android_bumper} /// {@macro android_bumper}
AndroidBumper._({ AndroidBumper._({
required double majorRadius, required double majorRadius,
@ -25,7 +25,6 @@ class AndroidBumper extends BodyComponent with InitialPosition {
}) : _majorRadius = majorRadius, }) : _majorRadius = majorRadius,
_minorRadius = minorRadius, _minorRadius = minorRadius,
super( super(
priority: RenderPriority.androidBumper,
renderBody: false, renderBody: false,
children: [ children: [
AndroidBumperBallContactBehavior(), AndroidBumperBallContactBehavior(),
@ -38,7 +37,9 @@ class AndroidBumper extends BodyComponent with InitialPosition {
), ),
...?children, ...?children,
], ],
); ) {
zIndex = RenderPriority.androidBumper;
}
/// {@macro android_bumper} /// {@macro android_bumper}
AndroidBumper.a({ AndroidBumper.a({

@ -9,10 +9,10 @@ import 'package:pinball_components/gen/assets.gen.dart';
import 'package:pinball_components/pinball_components.dart' hide Assets; import 'package:pinball_components/pinball_components.dart' hide Assets;
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
class AndroidSpaceship extends Blueprint { class AndroidSpaceship extends Component {
AndroidSpaceship({required Vector2 position}) AndroidSpaceship({required Vector2 position})
: super( : super(
components: [ children: [
_SpaceshipSaucer()..initialPosition = position, _SpaceshipSaucer()..initialPosition = position,
_SpaceshipSaucerSpriteAnimationComponent()..position = position, _SpaceshipSaucerSpriteAnimationComponent()..position = position,
_LightBeamSpriteComponent()..position = position + Vector2(2.5, 5), _LightBeamSpriteComponent()..position = position + Vector2(2.5, 5),
@ -65,12 +65,13 @@ class _SpaceshipSaucerShape extends ChainShape {
} }
class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent
with HasGameRef { with HasGameRef, Rendering {
_SpaceshipSaucerSpriteAnimationComponent() _SpaceshipSaucerSpriteAnimationComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
priority: RenderPriority.spaceshipSaucer, ) {
); zIndex = RenderPriority.spaceshipSaucer;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -101,12 +102,14 @@ class _SpaceshipSaucerSpriteAnimationComponent extends SpriteAnimationComponent
} }
// TODO(allisonryan0002): add pulsing behavior. // TODO(allisonryan0002): add pulsing behavior.
class _LightBeamSpriteComponent extends SpriteComponent with HasGameRef { class _LightBeamSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
_LightBeamSpriteComponent() _LightBeamSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
priority: RenderPriority.spaceshipLightBeam, ) {
); zIndex = RenderPriority.spaceshipLightBeam;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -121,14 +124,15 @@ class _LightBeamSpriteComponent extends SpriteComponent with HasGameRef {
} }
} }
class _AndroidHead extends BodyComponent with InitialPosition, Layered { class _AndroidHead extends BodyComponent
with InitialPosition, Layered, Rendering {
_AndroidHead() _AndroidHead()
: super( : super(
priority: RenderPriority.androidHead,
children: [_AndroidHeadSpriteAnimationComponent()], children: [_AndroidHeadSpriteAnimationComponent()],
renderBody: false, renderBody: false,
) { ) {
layer = Layer.spaceship; layer = Layer.spaceship;
zIndex = RenderPriority.androidHead;
} }
@override @override

@ -6,12 +6,13 @@ import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template ball} /// {@template ball}
/// A solid, [BodyType.dynamic] sphere that rolls and bounces around. /// A solid, [BodyType.dynamic] sphere that rolls and bounces around.
/// {@endtemplate} /// {@endtemplate}
class Ball<T extends Forge2DGame> extends BodyComponent<T> class Ball<T extends Forge2DGame> extends BodyComponent<T>
with Layered, InitialPosition { with Layered, InitialPosition, Rendering {
/// {@macro ball} /// {@macro ball}
Ball({ Ball({
required this.baseColor, required this.baseColor,
@ -133,13 +134,14 @@ class _BallSpriteComponent extends SpriteComponent with HasGameRef {
} }
class _TurboChargeSpriteAnimationComponent extends SpriteAnimationComponent class _TurboChargeSpriteAnimationComponent extends SpriteAnimationComponent
with HasGameRef { with HasGameRef, Rendering {
_TurboChargeSpriteAnimationComponent() _TurboChargeSpriteAnimationComponent()
: super( : super(
anchor: const Anchor(0.53, 0.72), anchor: const Anchor(0.53, 0.72),
priority: RenderPriority.turboChargeFlame,
removeOnFinish: true, removeOnFinish: true,
); ) {
zIndex = RenderPriority.turboChargeFlame;
}
late final Vector2 _textureSize; late final Vector2 _textureSize;

@ -9,9 +9,10 @@ class BoardBackgroundSpriteComponent extends SpriteComponent
BoardBackgroundSpriteComponent() BoardBackgroundSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
priority: RenderPriority.boardBackground,
position: Vector2(0, -1), position: Vector2(0, -1),
); ) {
zIndex = RenderPriority.boardBackground;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -6,11 +6,11 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template boundaries} /// {@template boundaries}
/// A [Blueprint] which creates the [_BottomBoundary] and [_OuterBoundary]. /// A [Blueprint] which creates the [_BottomBoundary] and [_OuterBoundary].
///{@endtemplate boundaries} ///{@endtemplate boundaries}
class Boundaries extends Blueprint { class Boundaries extends Component {
/// {@macro boundaries} /// {@macro boundaries}
Boundaries() Boundaries()
: super( : super(
components: [ children: [
_BottomBoundary(), _BottomBoundary(),
_OuterBoundary(), _OuterBoundary(),
_OuterBottomBoundarySpriteComponent(), _OuterBottomBoundarySpriteComponent(),
@ -22,14 +22,15 @@ class Boundaries extends Blueprint {
/// Curved boundary at the bottom of the board where the [Ball] exits the field /// Curved boundary at the bottom of the board where the [Ball] exits the field
/// of play. /// of play.
/// {@endtemplate bottom_boundary} /// {@endtemplate bottom_boundary}
class _BottomBoundary extends BodyComponent with InitialPosition { class _BottomBoundary extends BodyComponent with InitialPosition, Rendering {
/// {@macro bottom_boundary} /// {@macro bottom_boundary}
_BottomBoundary() _BottomBoundary()
: super( : super(
renderBody: false, renderBody: false,
priority: RenderPriority.bottomBoundary,
children: [_BottomBoundarySpriteComponent()], children: [_BottomBoundarySpriteComponent()],
); ) {
zIndex = RenderPriority.bottomBoundary;
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final bottomLeftCurve = BezierCurveShape( final bottomLeftCurve = BezierCurveShape(
@ -87,14 +88,15 @@ class _BottomBoundarySpriteComponent extends SpriteComponent with HasGameRef {
/// Boundary enclosing the top and left side of the board. The right side of the /// Boundary enclosing the top and left side of the board. The right side of the
/// board is closed by the barrier the [LaunchRamp] creates. /// board is closed by the barrier the [LaunchRamp] creates.
/// {@endtemplate outer_boundary} /// {@endtemplate outer_boundary}
class _OuterBoundary extends BodyComponent with InitialPosition { class _OuterBoundary extends BodyComponent with InitialPosition, Rendering {
/// {@macro outer_boundary} /// {@macro outer_boundary}
_OuterBoundary() _OuterBoundary()
: super( : super(
renderBody: false, renderBody: false,
priority: RenderPriority.outerBoundary,
children: [_OuterBoundarySpriteComponent()], children: [_OuterBoundarySpriteComponent()],
); ) {
zIndex = RenderPriority.outerBoundary;
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final topWall = EdgeShape() final topWall = EdgeShape()
@ -189,13 +191,14 @@ class _OuterBoundarySpriteComponent extends SpriteComponent with HasGameRef {
} }
class _OuterBottomBoundarySpriteComponent extends SpriteComponent class _OuterBottomBoundarySpriteComponent extends SpriteComponent
with HasGameRef { with HasGameRef, Rendering {
_OuterBottomBoundarySpriteComponent() _OuterBottomBoundarySpriteComponent()
: super( : super(
priority: RenderPriority.outerBottomBoundary,
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(0, 71), position: Vector2(0, 71),
); ) {
zIndex = RenderPriority.outerBottomBoundary;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart' hide Timer; import 'package:flame_forge2d/flame_forge2d.dart' hide Timer;
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template chrome_dino} /// {@template chrome_dino}
/// Dino that swivels back and forth, opening its mouth to eat a [Ball]. /// Dino that swivels back and forth, opening its mouth to eat a [Ball].
@ -10,13 +11,14 @@ import 'package:pinball_components/pinball_components.dart';
/// Upon eating a [Ball], the dino rotates and spits the [Ball] out in a /// Upon eating a [Ball], the dino rotates and spits the [Ball] out in a
/// different direction. /// different direction.
/// {@endtemplate} /// {@endtemplate}
class ChromeDino extends BodyComponent with InitialPosition { class ChromeDino extends BodyComponent with InitialPosition, Rendering {
/// {@macro chrome_dino} /// {@macro chrome_dino}
ChromeDino() ChromeDino()
: super( : super(
priority: RenderPriority.dino,
renderBody: false, renderBody: false,
); ) {
zIndex = RenderPriority.dino;
}
/// The size of the dinosaur mouth. /// The size of the dinosaur mouth.
static final size = Vector2(5.5, 5); static final size = Vector2(5.5, 5);

@ -9,11 +9,11 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template dinowalls} /// {@template dinowalls}
/// A [Blueprint] which creates walls for the [ChromeDino]. /// A [Blueprint] which creates walls for the [ChromeDino].
/// {@endtemplate} /// {@endtemplate}
class DinoWalls extends Blueprint { class DinoWalls extends Component {
/// {@macro dinowalls} /// {@macro dinowalls}
DinoWalls() DinoWalls()
: super( : super(
components: [ children: [
_DinoTopWall(), _DinoTopWall(),
_DinoBottomWall(), _DinoBottomWall(),
], ],
@ -23,14 +23,15 @@ class DinoWalls extends Blueprint {
/// {@template dino_top_wall} /// {@template dino_top_wall}
/// Wall segment located above [ChromeDino]. /// Wall segment located above [ChromeDino].
/// {@endtemplate} /// {@endtemplate}
class _DinoTopWall extends BodyComponent with InitialPosition { class _DinoTopWall extends BodyComponent with InitialPosition, Rendering {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoTopWall() _DinoTopWall()
: super( : super(
priority: RenderPriority.dinoTopWall,
children: [_DinoTopWallSpriteComponent()], children: [_DinoTopWallSpriteComponent()],
renderBody: false, renderBody: false,
); ) {
zIndex = RenderPriority.dinoTopWall;
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final topStraightShape = EdgeShape() final topStraightShape = EdgeShape()
@ -116,14 +117,15 @@ class _DinoTopWallSpriteComponent extends SpriteComponent with HasGameRef {
/// {@template dino_bottom_wall} /// {@template dino_bottom_wall}
/// Wall segment located below [ChromeDino]. /// Wall segment located below [ChromeDino].
/// {@endtemplate} /// {@endtemplate}
class _DinoBottomWall extends BodyComponent with InitialPosition { class _DinoBottomWall extends BodyComponent with InitialPosition, Rendering {
///{@macro dino_top_wall} ///{@macro dino_top_wall}
_DinoBottomWall() _DinoBottomWall()
: super( : super(
priority: RenderPriority.dinoBottomWall,
children: [_DinoBottomWallSpriteComponent()], children: [_DinoBottomWallSpriteComponent()],
renderBody: false, renderBody: false,
); ) {
zIndex = RenderPriority.dinoBottomWall;
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final topStraightShape = EdgeShape() final topStraightShape = EdgeShape()

@ -27,7 +27,7 @@ class LaunchRamp extends Component {
/// {@template launch_ramp_base} /// {@template launch_ramp_base}
/// Ramp the [Ball] is launched from at the beginning of each ball life. /// Ramp the [Ball] is launched from at the beginning of each ball life.
/// {@endtemplate} /// {@endtemplate}
class _LaunchRampBase extends BodyComponent with Layered { class _LaunchRampBase extends BodyComponent with Layered, Rendering {
/// {@macro launch_ramp_base} /// {@macro launch_ramp_base}
_LaunchRampBase() _LaunchRampBase()
: super( : super(
@ -37,6 +37,7 @@ class _LaunchRampBase extends BodyComponent with Layered {
_LaunchRampBaseSpriteComponent(), _LaunchRampBaseSpriteComponent(),
], ],
) { ) {
zIndex = RenderPriority.launchRamp;
layer = Layer.launcher; layer = Layer.launcher;
} }
@ -124,11 +125,10 @@ class _LaunchRampBaseSpriteComponent extends SpriteComponent with HasGameRef {
} }
class _LaunchRampBackgroundRailingSpriteComponent extends SpriteComponent class _LaunchRampBackgroundRailingSpriteComponent extends SpriteComponent
with HasGameRef, Rendering { with HasGameRef {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
zIndex = 1;
final sprite = await gameRef.loadSprite( final sprite = await gameRef.loadSprite(
Assets.images.launchRamp.backgroundRailing.keyName, Assets.images.launchRamp.backgroundRailing.keyName,
@ -144,13 +144,15 @@ class _LaunchRampBackgroundRailingSpriteComponent extends SpriteComponent
/// Foreground railing for the [_LaunchRampBase] to render in front of the /// Foreground railing for the [_LaunchRampBase] to render in front of the
/// [Ball]. /// [Ball].
/// {@endtemplate} /// {@endtemplate}
class _LaunchRampForegroundRailing extends BodyComponent { class _LaunchRampForegroundRailing extends BodyComponent with Rendering {
/// {@macro launch_ramp_foreground_railing} /// {@macro launch_ramp_foreground_railing}
_LaunchRampForegroundRailing() _LaunchRampForegroundRailing()
: super( : super(
children: [_LaunchRampForegroundRailingSpriteComponent()], children: [_LaunchRampForegroundRailingSpriteComponent()],
renderBody: false, renderBody: false,
); ) {
zIndex = RenderPriority.launchRampForegroundRailing;
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[]; final fixturesDef = <FixtureDef>[];

@ -90,14 +90,12 @@ abstract class LayerSensor extends BodyComponent
if (isBallEnteringOpening) { if (isBallEnteringOpening) {
other other
..layer = insideLayer ..layer = insideLayer
..priority = insidePriority ..zIndex = insidePriority;
..reorderChildren();
} }
} else { } else {
other other
..layer = outsideLayer ..layer = outsideLayer
..priority = outsidePriority ..zIndex = outsidePriority;
..reorderChildren();
} }
} }
} }

@ -1,6 +1,7 @@
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template plunger} /// {@template plunger}
/// [Plunger] serves as a spring, that shoots the ball on the right side of the /// [Plunger] serves as a spring, that shoots the ball on the right side of the
@ -8,16 +9,12 @@ import 'package:pinball_components/pinball_components.dart';
/// ///
/// [Plunger] ignores gravity so the player controls its downward [pull]. /// [Plunger] ignores gravity so the player controls its downward [pull].
/// {@endtemplate} /// {@endtemplate}
class Plunger extends BodyComponent with InitialPosition, Layered { class Plunger extends BodyComponent with InitialPosition, Layered, Rendering {
/// {@macro plunger} /// {@macro plunger}
Plunger({ Plunger({
required this.compressionDistance, required this.compressionDistance,
// TODO(ruimiguel): set to priority +1 over LaunchRamp once all priorities }) : super(renderBody: false) {
// are fixed. zIndex = RenderPriority.plunger;
}) : super(
priority: RenderPriority.plunger,
renderBody: false,
) {
layer = Layer.launcher; layer = Layer.launcher;
} }

@ -14,106 +14,106 @@ abstract class RenderPriority {
// Ball // Ball
/// Render priority for the [Ball] while it's on the board. /// Render priority for the [Ball] while it's on the board.
static const int ballOnBoard = _base; static const ballOnBoard = _base;
/// Render priority for the [Ball] while it's on the [SpaceshipRamp]. /// Render priority for the [Ball] while it's on the [SpaceshipRamp].
static const int ballOnSpaceshipRamp = static const ballOnSpaceshipRamp = _above + spaceshipRampBackgroundRailing;
_above + spaceshipRampBackgroundRailing;
/// Render priority for the [Ball] while it's on the [AndroidSpaceship]. /// Render priority for the [Ball] while it's on the [AndroidSpaceship].
static const int ballOnSpaceship = _above + spaceshipSaucer; static const ballOnSpaceship = _above + spaceshipSaucer;
/// Render priority for the [Ball] while it's on the [SpaceshipRail]. /// Render priority for the [Ball] while it's on the [SpaceshipRail].
static const int ballOnSpaceshipRail = _above + spaceshipRail; static const ballOnSpaceshipRail = _above + spaceshipRail;
/// Render priority for the [Ball] while it's on the [LaunchRamp]. /// Render priority for the [Ball] while it's on the [LaunchRamp].
static const int ballOnLaunchRamp = launchRamp; static const ballOnLaunchRamp = launchRamp;
// Background // Background
// TODO(allisonryan0002): fix this magic priority. Could bump all priorities // TODO(allisonryan0002): fix this magic priority. Could bump all priorities
// so there are no negatives. // so there are no negatives.
static const int boardBackground = 3 * _below + _base; static const boardBackground = 3 * _below + _base;
static const decal = _above + boardBackground;
// Boundaries // Boundaries
static const int bottomBoundary = _above + dinoBottomWall; static const bottomBoundary = _above + dinoBottomWall;
static const int outerBoundary = _above + boardBackground; static const outerBoundary = _above + boardBackground;
static const int outerBottomBoundary = _above + rocket; static const outerBottomBoundary = _above + rocket;
// Bottom Group // Bottom Group
static const int bottomGroup = _above + ballOnBoard; static const bottomGroup = _above + ballOnBoard;
// Launcher // Launcher
static const int launchRamp = _above + outerBoundary; static const launchRamp = _above + outerBoundary;
static const int launchRampForegroundRailing = ballOnBoard; static const launchRampForegroundRailing = ballOnBoard;
static const int plunger = _above + launchRamp; static const plunger = _above + launchRamp;
static const int rocket = _below + bottomBoundary; static const rocket = _below + bottomBoundary;
// Dino Desert // Dino Desert
static const int dinoTopWall = _above + ballOnBoard; static const dinoTopWall = _above + ballOnBoard;
static const int dino = _above + dinoTopWall; static const dino = _above + dinoTopWall;
static const int dinoBottomWall = _above + dino; static const dinoBottomWall = _above + dino;
static const int slingshot = _above + dinoBottomWall; static const slingshots = _above + dinoBottomWall;
// Flutter Forest // Flutter Forest
static const int flutterForest = _above + launchRampForegroundRailing; static const flutterForest = _above + launchRampForegroundRailing;
// Sparky Scorch // Sparky Scorch
static const int computerBase = _below + ballOnBoard; static const computerBase = _below + ballOnBoard;
static const int computerTop = _above + ballOnBoard; static const computerTop = _above + ballOnBoard;
static const int computerGlow = _above + ballOnBoard; static const computerGlow = _above + ballOnBoard;
static const int sparkyAnimatronic = _above + spaceshipRampForegroundRailing; static const sparkyAnimatronic = _above + spaceshipRampForegroundRailing;
static const int sparkyBumper = _above + ballOnBoard; static const sparkyBumper = _above + ballOnBoard;
static const int turboChargeFlame = _above + ballOnBoard; static const turboChargeFlame = _above + ballOnBoard;
// Android Acres // Android Acres
static const int spaceshipRail = _above + bottomGroup; static const spaceshipRail = _above + bottomGroup;
static const int spaceshipRailExit = _above + ballOnSpaceshipRail; static const spaceshipRailExit = _above + ballOnSpaceshipRail;
static const int spaceshipSaucer = _above + ballOnSpaceshipRail; static const spaceshipSaucer = _above + ballOnSpaceshipRail;
static const int spaceshipLightBeam = _below + spaceshipSaucer; static const spaceshipLightBeam = _below + spaceshipSaucer;
static const int androidHead = _above + spaceshipSaucer; static const androidHead = _above + ballOnSpaceship;
static const int spaceshipRamp = _above + ballOnBoard; static const spaceshipRamp = _above + ballOnBoard;
static const int spaceshipRampBackgroundRailing = _above + spaceshipRamp; static const spaceshipRampBackgroundRailing = _above + spaceshipRamp;
static const int spaceshipRampArrow = _above + spaceshipRamp; static const spaceshipRampArrow = _above + spaceshipRamp;
static const int spaceshipRampForegroundRailing = static const spaceshipRampForegroundRailing = _above + ballOnSpaceshipRamp;
_above + ballOnSpaceshipRamp;
static const int spaceshipRampBoardOpening = _below + ballOnBoard; static const spaceshipRampBoardOpening = _below + ballOnBoard;
static const int androidBumper = _above + ballOnBoard; static const androidBumper = _above + ballOnBoard;
// Score Text // Score Text
static const int scoreText = _above + spaceshipRampForegroundRailing; static const scoreText = _above + spaceshipRampForegroundRailing;
// Debug information // Debug information
static const int debugInfo = _above + scoreText; static const debugInfo = _above + scoreText;
} }

@ -1,17 +1,16 @@
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:pinball_components/gen/assets.gen.dart'; import 'package:pinball_components/gen/assets.gen.dart';
import 'package:pinball_components/pinball_components.dart' hide Assets; import 'package:pinball_components/pinball_components.dart' hide Assets;
import 'package:pinball_flame/pinball_flame.dart';
/// {@template rocket_sprite_component} /// {@template rocket_sprite_component}
/// A [SpriteComponent] for the rocket over [Plunger]. /// A [SpriteComponent] for the rocket over [Plunger].
/// {@endtemplate} /// {@endtemplate}
class RocketSpriteComponent extends SpriteComponent with HasGameRef { class RocketSpriteComponent extends SpriteComponent with HasGameRef, Rendering {
/// {@macro rocket_sprite_component} /// {@macro rocket_sprite_component}
RocketSpriteComponent() RocketSpriteComponent() : super(anchor: Anchor.center) {
: super( zIndex = RenderPriority.rocket;
priority: RenderPriority.rocket, }
anchor: Anchor.center,
);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -4,11 +4,12 @@ import 'package:flame/components.dart';
import 'package:flame/effects.dart'; import 'package:flame/effects.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template score_text} /// {@template score_text}
/// A [TextComponent] that spawns at a given [position] with a moving animation. /// A [TextComponent] that spawns at a given [position] with a moving animation.
/// {@endtemplate} /// {@endtemplate}
class ScoreText extends TextComponent { class ScoreText extends TextComponent with Rendering {
/// {@macro score_text} /// {@macro score_text}
ScoreText({ ScoreText({
required String text, required String text,
@ -18,8 +19,9 @@ class ScoreText extends TextComponent {
text: text, text: text,
position: position, position: position,
anchor: Anchor.center, anchor: Anchor.center,
priority: RenderPriority.scoreText, ) {
); zIndex = RenderPriority.scoreText;
}
late final Effect _effect; late final Effect _effect;

@ -7,11 +7,11 @@ import 'package:pinball_flame/pinball_flame.dart';
/// A [Blueprint] which creates the pair of [Slingshot]s on the right side of /// A [Blueprint] which creates the pair of [Slingshot]s on the right side of
/// the board. /// the board.
/// {@endtemplate} /// {@endtemplate}
class Slingshots extends Blueprint { class Slingshots extends Component with Rendering {
/// {@macro slingshots} /// {@macro slingshots}
Slingshots() Slingshots()
: super( : super(
components: [ children: [
Slingshot( Slingshot(
length: 5.64, length: 5.64,
angle: -0.017, angle: -0.017,
@ -23,7 +23,9 @@ class Slingshots extends Blueprint {
spritePath: Assets.images.slingshot.lower.keyName, spritePath: Assets.images.slingshot.lower.keyName,
)..initialPosition = Vector2(24.7, 6.2), )..initialPosition = Vector2(24.7, 6.2),
], ],
); ) {
zIndex = RenderPriority.slingshots;
}
} }
/// {@template slingshot} /// {@template slingshot}
@ -38,7 +40,6 @@ class Slingshot extends BodyComponent with InitialPosition {
}) : _length = length, }) : _length = length,
_angle = angle, _angle = angle,
super( super(
priority: RenderPriority.slingshot,
children: [_SlinghsotSpriteComponent(spritePath, angle: angle)], children: [_SlinghsotSpriteComponent(spritePath, angle: angle)],
renderBody: false, renderBody: false,
); );

@ -8,11 +8,11 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template spaceship_rail} /// {@template spaceship_rail}
/// A [Blueprint] for the rail exiting the [AndroidSpaceship]. /// A [Blueprint] for the rail exiting the [AndroidSpaceship].
/// {@endtemplate} /// {@endtemplate}
class SpaceshipRail extends Blueprint { class SpaceshipRail extends Component {
/// {@macro spaceship_rail} /// {@macro spaceship_rail}
SpaceshipRail() SpaceshipRail()
: super( : super(
components: [ children: [
_SpaceshipRail(), _SpaceshipRail(),
_SpaceshipRailExit(), _SpaceshipRailExit(),
_SpaceshipRailExitSpriteComponent() _SpaceshipRailExitSpriteComponent()
@ -20,14 +20,14 @@ class SpaceshipRail extends Blueprint {
); );
} }
class _SpaceshipRail extends BodyComponent with Layered { class _SpaceshipRail extends BodyComponent with Layered, Rendering {
_SpaceshipRail() _SpaceshipRail()
: super( : super(
priority: RenderPriority.spaceshipRail,
children: [_SpaceshipRailSpriteComponent()], children: [_SpaceshipRailSpriteComponent()],
renderBody: false, renderBody: false,
) { ) {
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
zIndex = RenderPriority.spaceshipRail;
} }
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
@ -125,13 +125,14 @@ class _SpaceshipRailSpriteComponent extends SpriteComponent with HasGameRef {
} }
class _SpaceshipRailExitSpriteComponent extends SpriteComponent class _SpaceshipRailExitSpriteComponent extends SpriteComponent
with HasGameRef { with HasGameRef, Rendering {
_SpaceshipRailExitSpriteComponent() _SpaceshipRailExitSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(-28, 19.4), position: Vector2(-28, 19.4),
priority: RenderPriority.spaceshipRailExit, ) {
); zIndex = RenderPriority.spaceshipRailExit;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -10,11 +10,11 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template spaceship_ramp} /// {@template spaceship_ramp}
/// A [Blueprint] which creates the ramp leading into the [AndroidSpaceship]. /// A [Blueprint] which creates the ramp leading into the [AndroidSpaceship].
/// {@endtemplate} /// {@endtemplate}
class SpaceshipRamp extends Blueprint { class SpaceshipRamp extends Component {
/// {@macro spaceship_ramp} /// {@macro spaceship_ramp}
SpaceshipRamp() SpaceshipRamp()
: super( : super(
components: [ children: [
_SpaceshipRampOpening( _SpaceshipRampOpening(
outsidePriority: RenderPriority.ballOnBoard, outsidePriority: RenderPriority.ballOnBoard,
rotation: math.pi, rotation: math.pi,
@ -41,10 +41,8 @@ class SpaceshipRamp extends Blueprint {
/// Forwards the sprite to the next [SpaceshipRampArrowSpriteState]. /// Forwards the sprite to the next [SpaceshipRampArrowSpriteState].
/// ///
/// If the current state is the last one it cycles back to the initial state. /// If the current state is the last one it cycles back to the initial state.
void progress() => components void progress() =>
.whereType<_SpaceshipRampArrowSpriteComponent>() firstChild<_SpaceshipRampArrowSpriteComponent>()?.progress();
.first
.progress();
} }
/// Indicates the state of the arrow on the [SpaceshipRamp]. /// Indicates the state of the arrow on the [SpaceshipRamp].
@ -94,16 +92,16 @@ extension on SpaceshipRampArrowSpriteState {
} }
class _SpaceshipRampBackground extends BodyComponent class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered, Rendering {
_SpaceshipRampBackground() _SpaceshipRampBackground()
: super( : super(
priority: RenderPriority.spaceshipRamp,
renderBody: false, renderBody: false,
children: [ children: [
_SpaceshipRampBackgroundRampSpriteComponent(), _SpaceshipRampBackgroundRampSpriteComponent(),
], ],
) { ) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
zIndex = RenderPriority.spaceshipRamp;
} }
/// Width between walls of the ramp. /// Width between walls of the ramp.
@ -148,13 +146,14 @@ class _SpaceshipRampBackground extends BodyComponent
} }
class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
with HasGameRef { with HasGameRef, Rendering {
_SpaceshipRampBackgroundRailingSpriteComponent() _SpaceshipRampBackgroundRailingSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(-11.7, -54.3), position: Vector2(-11.7, -54.3),
priority: RenderPriority.spaceshipRampBackgroundRailing, ) {
); zIndex = RenderPriority.spaceshipRampBackgroundRailing;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -197,14 +196,15 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
/// {@endtemplate} /// {@endtemplate}
class _SpaceshipRampArrowSpriteComponent class _SpaceshipRampArrowSpriteComponent
extends SpriteGroupComponent<SpaceshipRampArrowSpriteState> extends SpriteGroupComponent<SpaceshipRampArrowSpriteState>
with HasGameRef { with HasGameRef, Rendering {
/// {@macro spaceship_ramp_arrow_sprite_component} /// {@macro spaceship_ramp_arrow_sprite_component}
_SpaceshipRampArrowSpriteComponent() _SpaceshipRampArrowSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(-3.9, -56.5), position: Vector2(-3.9, -56.5),
priority: RenderPriority.spaceshipRampArrow, ) {
); zIndex = RenderPriority.spaceshipRampArrow;
}
/// Changes arrow image to the next [Sprite]. /// Changes arrow image to the next [Sprite].
void progress() => current = current?.next; void progress() => current = current?.next;
@ -226,8 +226,10 @@ class _SpaceshipRampArrowSpriteComponent
} }
class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
with HasGameRef { with HasGameRef, Rendering {
_SpaceshipRampBoardOpeningSpriteComponent() : super(anchor: Anchor.center); _SpaceshipRampBoardOpeningSpriteComponent() : super(anchor: Anchor.center) {
zIndex = RenderPriority.spaceshipRampBoardOpening;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -243,14 +245,14 @@ class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
} }
class _SpaceshipRampForegroundRailing extends BodyComponent class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered, Rendering {
_SpaceshipRampForegroundRailing() _SpaceshipRampForegroundRailing()
: super( : super(
priority: RenderPriority.spaceshipRampForegroundRailing,
renderBody: false, renderBody: false,
children: [_SpaceshipRampForegroundRailingSpriteComponent()], children: [_SpaceshipRampForegroundRailingSpriteComponent()],
) { ) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
zIndex = RenderPriority.spaceshipRampForegroundRailing;
} }
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {

@ -1,17 +1,20 @@
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template sparky_animatronic} /// {@template sparky_animatronic}
/// Animated Sparky that sits on top of the [SparkyComputer]. /// Animated Sparky that sits on top of the [SparkyComputer].
/// {@endtemplate} /// {@endtemplate}
class SparkyAnimatronic extends SpriteAnimationComponent with HasGameRef { class SparkyAnimatronic extends SpriteAnimationComponent
with HasGameRef, Rendering {
/// {@macro sparky_animatronic} /// {@macro sparky_animatronic}
SparkyAnimatronic() SparkyAnimatronic()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
playing: false, playing: false,
priority: RenderPriority.sparkyAnimatronic, ) {
); zIndex = RenderPriority.sparkyAnimatronic;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -12,7 +12,7 @@ export 'cubit/sparky_bumper_cubit.dart';
/// {@template sparky_bumper} /// {@template sparky_bumper}
/// Bumper for Sparky area. /// Bumper for Sparky area.
/// {@endtemplate} /// {@endtemplate}
class SparkyBumper extends BodyComponent with InitialPosition { class SparkyBumper extends BodyComponent with InitialPosition, Rendering {
/// {@macro sparky_bumper} /// {@macro sparky_bumper}
SparkyBumper._({ SparkyBumper._({
required double majorRadius, required double majorRadius,
@ -25,7 +25,6 @@ class SparkyBumper extends BodyComponent with InitialPosition {
}) : _majorRadius = majorRadius, }) : _majorRadius = majorRadius,
_minorRadius = minorRadius, _minorRadius = minorRadius,
super( super(
priority: RenderPriority.sparkyBumper,
renderBody: false, renderBody: false,
children: [ children: [
SparkyBumperBallContactBehavior(), SparkyBumperBallContactBehavior(),
@ -38,7 +37,9 @@ class SparkyBumper extends BodyComponent with InitialPosition {
), ),
...?children, ...?children,
], ],
); ) {
zIndex = RenderPriority.sparkyBumper;
}
/// {@macro sparky_bumper} /// {@macro sparky_bumper}
SparkyBumper.a({ SparkyBumper.a({

@ -8,11 +8,11 @@ import 'package:pinball_flame/pinball_flame.dart';
/// {@template sparky_computer} /// {@template sparky_computer}
/// A computer owned by Sparky. /// A computer owned by Sparky.
/// {@endtemplate} /// {@endtemplate}
class SparkyComputer extends Blueprint { class SparkyComputer extends Component {
/// {@macro sparky_computer} /// {@macro sparky_computer}
SparkyComputer() SparkyComputer()
: super( : super(
components: [ children: [
_ComputerBase(), _ComputerBase(),
_ComputerTopSpriteComponent(), _ComputerTopSpriteComponent(),
_ComputerGlowSpriteComponent(), _ComputerGlowSpriteComponent(),
@ -20,13 +20,14 @@ class SparkyComputer extends Blueprint {
); );
} }
class _ComputerBase extends BodyComponent with InitialPosition { class _ComputerBase extends BodyComponent with InitialPosition, Rendering {
_ComputerBase() _ComputerBase()
: super( : super(
priority: RenderPriority.computerBase,
renderBody: false, renderBody: false,
children: [_ComputerBaseSpriteComponent()], children: [_ComputerBaseSpriteComponent()],
); ) {
zIndex = RenderPriority.computerBase;
}
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
final leftEdge = EdgeShape() final leftEdge = EdgeShape()
@ -83,13 +84,15 @@ class _ComputerBaseSpriteComponent extends SpriteComponent with HasGameRef {
} }
} }
class _ComputerTopSpriteComponent extends SpriteComponent with HasGameRef { class _ComputerTopSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
_ComputerTopSpriteComponent() _ComputerTopSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(-12.52, -49.37), position: Vector2(-12.52, -49.37),
priority: RenderPriority.computerTop, ) {
); zIndex = RenderPriority.computerTop;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -105,13 +108,15 @@ class _ComputerTopSpriteComponent extends SpriteComponent with HasGameRef {
} }
} }
class _ComputerGlowSpriteComponent extends SpriteComponent with HasGameRef { class _ComputerGlowSpriteComponent extends SpriteComponent
with HasGameRef, Rendering {
_ComputerGlowSpriteComponent() _ComputerGlowSpriteComponent()
: super( : super(
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(7.4, 10), position: Vector2(7.4, 10),
priority: RenderPriority.computerGlow, ) {
); zIndex = RenderPriority.computerGlow;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {

@ -26,19 +26,9 @@ class PinballCanvas implements Canvas {
_zBuffer _zBuffer
..sort((a, b) => a.zIndex.compareTo(b.zIndex)) ..sort((a, b) => a.zIndex.compareTo(b.zIndex))
..whereType<Component>().forEach(_render); ..whereType<Component>().forEach(_render);
// ..expand(_flatten).forEach(_render);
_zBuffer.clear(); _zBuffer.clear();
} }
Iterable<PositionComponent> _flatten(Rendering rendering) {
final components = <PositionComponent>[];
if (rendering is PositionComponent) {
components.add(rendering as PositionComponent);
}
components.addAll(rendering.descendants().whereType<PositionComponent>());
return components;
}
void _render(Component component) { void _render(Component component) {
// TODO(alestiago): Uses zones to detect when super.renderTree is called, // TODO(alestiago): Uses zones to detect when super.renderTree is called,
// and call _render insted. // and call _render insted.

Loading…
Cancel
Save