refactor: ball priority

pull/183/head
Allison Ryan 4 years ago
parent b424f0a008
commit 8daeda43da

@ -18,6 +18,7 @@ class ControlledBall extends Ball with Controls<BallController> {
required PinballTheme theme, required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) { }) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this); controller = BallController(this);
priority = Ball.launchRampPriority;
} }
/// {@template bonus_ball} /// {@template bonus_ball}
@ -29,11 +30,13 @@ class ControlledBall extends Ball with Controls<BallController> {
required PinballTheme theme, required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) { }) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this); controller = BallController(this);
priority = Ball.boardPriority;
} }
/// [Ball] used in [DebugPinballGame]. /// [Ball] used in [DebugPinballGame].
ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) { ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) {
controller = DebugBallController(this); controller = DebugBallController(this);
priority = Ball.boardPriority;
} }
} }

@ -22,6 +22,21 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
layer = Layer.board; layer = Layer.board;
} }
/// Render priority for the [Ball] while it's on the board.
static const int boardPriority = 0;
/// Render priority for the [Ball] while it's on the [SpaceshipRamp].
static const int spaceshipRampPriority = 4;
/// Render priority for the [Ball] while it's on the [Spaceship].
static const int spaceshipPriority = 4;
/// Render priority for the [Ball] while it's on the [SpaceshipRail].
static const int spaceshipRailPriority = 2;
/// Render priority for the [Ball] while it's on the [LaunchRamp].
static const int launchRampPriority = 0;
/// The size of the [Ball]. /// The size of the [Ball].
static final Vector2 size = Vector2.all(4.13); static final Vector2 size = Vector2.all(4.13);

@ -11,9 +11,6 @@ import 'package:pinball_components/pinball_components.dart';
/// [_LaunchRampForegroundRailing]. /// [_LaunchRampForegroundRailing].
/// {@endtemplate} /// {@endtemplate}
class LaunchRamp extends Forge2DBlueprint { class LaunchRamp extends Forge2DBlueprint {
/// Base priority for [Ball] while inside [LaunchRamp].
static const ballPriorityInsideRamp = 0;
@override @override
void build(_) { void build(_) {
addAllContactCallback([ addAllContactCallback([
@ -45,7 +42,7 @@ class _LaunchRampBase extends BodyComponent with InitialPosition, Layered {
/// {@macro launch_ramp_base} /// {@macro launch_ramp_base}
_LaunchRampBase() _LaunchRampBase()
: super( : super(
priority: LaunchRamp.ballPriorityInsideRamp - 1, priority: Ball.launchRampPriority - 1,
) { ) {
layer = Layer.launcher; layer = Layer.launcher;
} }
@ -151,7 +148,7 @@ class _LaunchRampForegroundRailing extends BodyComponent
/// {@macro launch_ramp_foreground_railing} /// {@macro launch_ramp_foreground_railing}
_LaunchRampForegroundRailing() _LaunchRampForegroundRailing()
: super( : super(
priority: LaunchRamp.ballPriorityInsideRamp + 1, priority: Ball.launchRampPriority + 1,
) { ) {
layer = Layer.launcher; layer = Layer.launcher;
} }
@ -236,7 +233,7 @@ class _LaunchRampExit extends RampOpening {
super( super(
insideLayer: Layer.launcher, insideLayer: Layer.launcher,
orientation: RampOrientation.down, orientation: RampOrientation.down,
insidePriority: LaunchRamp.ballPriorityInsideRamp, insidePriority: Ball.launchRampPriority,
); );
final double _rotation; final double _rotation;

@ -18,7 +18,7 @@ class ScoreText extends TextComponent {
text: text, text: text,
position: position, position: position,
anchor: Anchor.center, anchor: Anchor.center,
priority: 100, priority: 5,
); );
late final Effect _effect; late final Effect _effect;

@ -21,9 +21,6 @@ class Spaceship extends Forge2DBlueprint {
/// The [position] where the elements will be created /// The [position] where the elements will be created
final Vector2 position; final Vector2 position;
/// Base priority for wall while be on spaceship.
static const ballPriorityWhenOnSpaceship = 4;
@override @override
void build(_) { void build(_) {
addAllContactCallback([ addAllContactCallback([
@ -37,7 +34,7 @@ class Spaceship extends Forge2DBlueprint {
AndroidHead()..initialPosition = position, AndroidHead()..initialPosition = position,
SpaceshipHole( SpaceshipHole(
outsideLayer: Layer.spaceshipExitRail, outsideLayer: Layer.spaceshipExitRail,
outsidePriority: SpaceshipRail.ballPriorityInsideRail, outsidePriority: Ball.spaceshipRailPriority,
)..initialPosition = position - Vector2(5.2, 4.8), )..initialPosition = position - Vector2(5.2, 4.8),
SpaceshipHole()..initialPosition = position - Vector2(-7.2, 0.8), SpaceshipHole()..initialPosition = position - Vector2(-7.2, 0.8),
SpaceshipWall()..initialPosition = position, SpaceshipWall()..initialPosition = position,
@ -50,8 +47,7 @@ class Spaceship extends Forge2DBlueprint {
/// {@endtemplate} /// {@endtemplate}
class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered { class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_saucer} /// {@macro spaceship_saucer}
SpaceshipSaucer() SpaceshipSaucer() : super(priority: Ball.spaceshipPriority - 1) {
: super(priority: Spaceship.ballPriorityWhenOnSpaceship - 1) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -95,7 +91,7 @@ class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
/// {@endtemplate} /// {@endtemplate}
class AndroidHead extends BodyComponent with InitialPosition, Layered { class AndroidHead extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_bridge} /// {@macro spaceship_bridge}
AndroidHead() : super(priority: Spaceship.ballPriorityWhenOnSpaceship + 1) { AndroidHead() : super(priority: Ball.spaceshipPriority + 1) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -157,7 +153,7 @@ class SpaceshipEntrance extends RampOpening {
: super( : super(
insideLayer: Layer.spaceship, insideLayer: Layer.spaceship,
orientation: RampOrientation.up, orientation: RampOrientation.up,
insidePriority: Spaceship.ballPriorityWhenOnSpaceship, insidePriority: Ball.spaceshipPriority,
) { ) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@ -242,7 +238,7 @@ class _SpaceshipWallShape extends ChainShape {
/// {@endtemplate} /// {@endtemplate}
class SpaceshipWall extends BodyComponent with InitialPosition, Layered { class SpaceshipWall extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_wall} /// {@macro spaceship_wall}
SpaceshipWall() : super(priority: Spaceship.ballPriorityWhenOnSpaceship + 1) { SpaceshipWall() : super(priority: Ball.spaceshipPriority + 1) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }

@ -14,9 +14,6 @@ class SpaceshipRail extends Forge2DBlueprint {
/// {@macro spaceship_rail} /// {@macro spaceship_rail}
SpaceshipRail(); SpaceshipRail();
/// Base priority for [Ball] while inside [SpaceshipRail].
static const ballPriorityInsideRail = 2;
@override @override
void build(_) { void build(_) {
addAllContactCallback([ addAllContactCallback([
@ -45,7 +42,7 @@ class SpaceshipRail extends Forge2DBlueprint {
class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered { class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered {
_SpaceshipRailRamp() _SpaceshipRailRamp()
: super( : super(
priority: SpaceshipRail.ballPriorityInsideRail - 1, priority: Ball.spaceshipRailPriority - 1,
) { ) {
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;
} }
@ -161,8 +158,7 @@ class _SpaceshipRailRampSpriteComponent extends SpriteComponent
} }
class _SpaceshipRailForeground extends SpriteComponent with HasGameRef { class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
_SpaceshipRailForeground() _SpaceshipRailForeground() : super(priority: Ball.spaceshipRailPriority + 1);
: super(priority: SpaceshipRail.ballPriorityInsideRail + 1);
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -182,7 +178,7 @@ class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
class _SpaceshipRailBase extends BodyComponent with InitialPosition, Layered { class _SpaceshipRailBase extends BodyComponent with InitialPosition, Layered {
_SpaceshipRailBase({required this.radius}) _SpaceshipRailBase({required this.radius})
: super( : super(
priority: SpaceshipRail.ballPriorityInsideRail + 1, priority: Ball.spaceshipRailPriority + 1,
) { ) {
renderBody = false; renderBody = false;
layer = Layer.board; layer = Layer.board;
@ -214,7 +210,7 @@ class SpaceshipRailExit extends RampOpening {
: super( : super(
orientation: RampOrientation.down, orientation: RampOrientation.down,
insideLayer: Layer.spaceshipExitRail, insideLayer: Layer.spaceshipExitRail,
insidePriority: SpaceshipRail.ballPriorityInsideRail, insidePriority: Ball.spaceshipRailPriority,
) { ) {
renderBody = false; renderBody = false;
layer = Layer.spaceshipExitRail; layer = Layer.spaceshipExitRail;

@ -14,9 +14,6 @@ class SpaceshipRamp extends Forge2DBlueprint {
/// {@macro spaceship_ramp} /// {@macro spaceship_ramp}
SpaceshipRamp(); SpaceshipRamp();
/// Base priority for wall while be in the ramp.
static const int ballPriorityInsideRamp = 4;
@override @override
void build(_) { void build(_) {
addAllContactCallback([ addAllContactCallback([
@ -32,7 +29,7 @@ class SpaceshipRamp extends Forge2DBlueprint {
..layer = Layer.opening; ..layer = Layer.opening;
final leftOpening = _SpaceshipRampOpening( final leftOpening = _SpaceshipRampOpening(
outsideLayer: Layer.spaceship, outsideLayer: Layer.spaceship,
outsidePriority: Spaceship.ballPriorityWhenOnSpaceship, outsidePriority: Ball.spaceshipPriority,
rotation: math.pi, rotation: math.pi,
) )
..initialPosition = Vector2(-13.7, 19) ..initialPosition = Vector2(-13.7, 19)
@ -58,8 +55,7 @@ class SpaceshipRamp extends Forge2DBlueprint {
/// railing. /// railing.
class _SpaceshipRampBackground extends BodyComponent class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered {
_SpaceshipRampBackground() _SpaceshipRampBackground() : super(priority: Ball.spaceshipRampPriority - 1) {
: super(priority: SpaceshipRamp.ballPriorityInsideRamp - 1) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
} }
@ -150,7 +146,7 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
class _SpaceshipRampForegroundRailing extends BodyComponent class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered { with InitialPosition, Layered {
_SpaceshipRampForegroundRailing() _SpaceshipRampForegroundRailing()
: super(priority: SpaceshipRamp.ballPriorityInsideRamp + 1) { : super(priority: Ball.spaceshipRampPriority + 1) {
layer = Layer.spaceshipEntranceRamp; layer = Layer.spaceshipEntranceRamp;
} }
@ -263,7 +259,7 @@ class _SpaceshipRampOpening extends RampOpening {
insideLayer: Layer.spaceshipEntranceRamp, insideLayer: Layer.spaceshipEntranceRamp,
outsideLayer: outsideLayer, outsideLayer: outsideLayer,
orientation: RampOrientation.down, orientation: RampOrientation.down,
insidePriority: SpaceshipRamp.ballPriorityInsideRamp, insidePriority: Ball.spaceshipRampPriority,
outsidePriority: outsidePriority, outsidePriority: outsidePriority,
) { ) {
renderBody = false; renderBody = false;

@ -9,7 +9,7 @@ class LaunchRampGame extends BasicBallGame {
LaunchRampGame() LaunchRampGame()
: super( : super(
color: Colors.blue, color: Colors.blue,
ballPriority: LaunchRamp.ballPriorityInsideRamp, ballPriority: Ball.launchRampPriority,
ballLayer: Layer.launcher, ballLayer: Layer.launcher,
); );

@ -9,7 +9,7 @@ class SpaceshipRailGame extends BasicBallGame {
SpaceshipRailGame() SpaceshipRailGame()
: super( : super(
color: Colors.blue, color: Colors.blue,
ballPriority: SpaceshipRail.ballPriorityInsideRail, ballPriority: Ball.spaceshipRailPriority,
ballLayer: Layer.spaceshipExitRail, ballLayer: Layer.spaceshipExitRail,
); );

@ -9,7 +9,7 @@ class SpaceshipRampGame extends BasicBallGame {
SpaceshipRampGame() SpaceshipRampGame()
: super( : super(
color: Colors.blue, color: Colors.blue,
ballPriority: SpaceshipRamp.ballPriorityInsideRamp, ballPriority: Ball.spaceshipRampPriority,
ballLayer: Layer.spaceshipEntranceRamp, ballLayer: Layer.spaceshipEntranceRamp,
); );

Loading…
Cancel
Save