Merge branch 'main' into refactor/specify-contact-callback

pull/202/head
Alejandro Santiago 3 years ago committed by GitHub
commit 9e84d39e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,7 +42,7 @@ class Board extends Component {
// TODO(alestiago): Consider renaming once entire Board is defined.
class _BottomGroup extends Component {
/// {@macro bottom_group}
_BottomGroup();
_BottomGroup() : super(priority: RenderPriority.bottomGroup);
@override
Future<void> onLoad() async {

@ -19,7 +19,7 @@ class ControlledBall extends Ball<PinballGame>
required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this);
priority = Ball.launchRampPriority;
priority = RenderPriority.ballOnLaunchRamp;
layer = Layer.launcher;
}
@ -32,13 +32,13 @@ class ControlledBall extends Ball<PinballGame>
required PinballTheme theme,
}) : super(baseColor: theme.characterTheme.ballColor) {
controller = BallController(this);
priority = Ball.boardPriority;
priority = RenderPriority.ballOnBoard;
}
/// [Ball] used in [DebugPinballGame].
ControlledBall.debug() : super(baseColor: const Color(0xFFFF0000)) {
controller = DebugBallController(this);
priority = Ball.boardPriority;
priority = RenderPriority.ballOnBoard;
}
@override
@ -72,9 +72,8 @@ class BallController extends ComponentController<Ball>
// given animations.
component.stop();
await Future<void>.delayed(const Duration(seconds: 1));
component
..resume()
..boost(Vector2(200, 500));
component.resume();
await component.boost(Vector2(40, 110));
}
@override

@ -7,7 +7,8 @@ extension PinballGameAssetsX on PinballGame {
/// Returns a list of assets to be loaded
List<Future> preLoadAssets() {
return [
images.load(components.Assets.images.ball.keyName),
images.load(components.Assets.images.ball.ball.keyName),
images.load(components.Assets.images.ball.flameEffect.keyName),
images.load(components.Assets.images.flutterSignPost.keyName),
images.load(components.Assets.images.flipper.left.keyName),
images.load(components.Assets.images.flipper.right.keyName),
@ -21,6 +22,9 @@ extension PinballGameAssetsX on PinballGame {
images.load(
components.Assets.images.launchRamp.foregroundRailing.keyName,
),
images.load(
components.Assets.images.launchRamp.backgroundRailing.keyName,
),
images.load(components.Assets.images.dino.dinoLandTop.keyName),
images.load(components.Assets.images.dino.dinoLandBottom.keyName),
images.load(components.Assets.images.dash.animatronic.keyName),

@ -159,7 +159,7 @@ class DebugPinballGame extends PinballGame with TapDetector {
anchor: Anchor.center,
)
..position = Vector2(0, -7.8)
..priority = -4;
..priority = RenderPriority.background;
await add(spriteComponent);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 283 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 128 KiB

@ -13,10 +13,7 @@ class $AssetsImagesGen {
$AssetsImagesAlienBumperGen get alienBumper =>
const $AssetsImagesAlienBumperGen();
$AssetsImagesBackboardGen get backboard => const $AssetsImagesBackboardGen();
/// File path: assets/images/ball.png
AssetGenImage get ball => const AssetGenImage('assets/images/ball.png');
$AssetsImagesBallGen get ball => const $AssetsImagesBallGen();
$AssetsImagesBaseboardGen get baseboard => const $AssetsImagesBaseboardGen();
$AssetsImagesBoundaryGen get boundary => const $AssetsImagesBoundaryGen();
$AssetsImagesChromeDinoGen get chromeDino =>
@ -57,10 +54,23 @@ class $AssetsImagesBackboardGen {
/// File path: assets/images/backboard/backboard_scores.png
AssetGenImage get backboardScores =>
const AssetGenImage('assets/images/backboard/backboard_scores.png');
/// File path: assets/images/backboard/display.png
AssetGenImage get display =>
const AssetGenImage('assets/images/backboard/display.png');
}
class $AssetsImagesBallGen {
const $AssetsImagesBallGen();
/// File path: assets/images/ball/ball.png
AssetGenImage get ball => const AssetGenImage('assets/images/ball/ball.png');
/// File path: assets/images/ball/flame_effect.png
AssetGenImage get flameEffect =>
const AssetGenImage('assets/images/ball/flame_effect.png');
}
class $AssetsImagesBaseboardGen {
const $AssetsImagesBaseboardGen();
@ -174,6 +184,10 @@ class $AssetsImagesKickerGen {
class $AssetsImagesLaunchRampGen {
const $AssetsImagesLaunchRampGen();
/// File path: assets/images/launch_ramp/background-railing.png
AssetGenImage get backgroundRailing =>
const AssetGenImage('assets/images/launch_ramp/background-railing.png');
/// File path: assets/images/launch_ramp/foreground-railing.png
AssetGenImage get foregroundRailing =>
const AssetGenImage('assets/images/launch_ramp/foreground-railing.png');
@ -309,8 +323,11 @@ class $AssetsImagesSparkyBumperGen {
class $AssetsImagesSparkyComputerGen {
const $AssetsImagesSparkyComputerGen();
/// File path: assets/images/sparky/computer/base.png
AssetGenImage get base =>
const AssetGenImage('assets/images/sparky/computer/base.png');
/// File path: assets/images/sparky/computer/top.png
AssetGenImage get top =>
const AssetGenImage('assets/images/sparky/computer/top.png');
}
@ -354,8 +371,11 @@ class $AssetsImagesDashBumperMainGen {
class $AssetsImagesSparkyBumperAGen {
const $AssetsImagesSparkyBumperAGen();
/// File path: assets/images/sparky/bumper/a/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/sparky/bumper/a/active.png');
/// File path: assets/images/sparky/bumper/a/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/sparky/bumper/a/inactive.png');
}
@ -363,8 +383,11 @@ class $AssetsImagesSparkyBumperAGen {
class $AssetsImagesSparkyBumperBGen {
const $AssetsImagesSparkyBumperBGen();
/// File path: assets/images/sparky/bumper/b/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/sparky/bumper/b/active.png');
/// File path: assets/images/sparky/bumper/b/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/sparky/bumper/b/inactive.png');
}
@ -372,8 +395,11 @@ class $AssetsImagesSparkyBumperBGen {
class $AssetsImagesSparkyBumperCGen {
const $AssetsImagesSparkyBumperCGen();
/// File path: assets/images/sparky/bumper/c/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/sparky/bumper/c/active.png');
/// File path: assets/images/sparky/bumper/c/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/sparky/bumper/c/inactive.png');
}

@ -18,7 +18,8 @@ class AlienBumper extends BodyComponent with InitialPosition {
_minorRadius = minorRadius,
_activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath,
_spriteComponent = spriteComponent;
_spriteComponent = spriteComponent,
super(priority: RenderPriority.alienBumper);
/// {@macro alien_bumper}
AlienBumper.a()

@ -4,6 +4,7 @@ import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/widgets.dart';
import 'package:pinball_components/pinball_components.dart';
/// {@template ball}
@ -28,30 +29,12 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
renderBody = false;
}
/// 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 = -2;
/// The size of the [Ball].
static final Vector2 size = Vector2.all(4.13);
/// The base [Color] used to tint this [Ball].
final Color baseColor;
double _boostTimer = 0;
static const _boostDuration = 2.0;
@override
Body createBody() {
final shape = CircleShape()..radius = size.x / 2;
@ -87,32 +70,20 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
body.gravityScale = Vector2(0, 1);
}
/// Applies a boost and [_TurboChargeSpriteAnimationComponent] on this [Ball].
Future<void> boost(Vector2 impulse) async {
body.linearVelocity = impulse;
await add(_TurboChargeSpriteAnimationComponent());
}
@override
void update(double dt) {
super.update(dt);
if (_boostTimer > 0) {
_boostTimer -= dt;
final direction = body.linearVelocity.normalized();
final effect = FireEffect(
burstPower: _boostTimer,
direction: direction,
position: Vector2(body.position.x, body.position.y),
priority: priority - 1,
);
unawaited(gameRef.add(effect));
}
_rescaleSize();
_setPositionalGravity();
}
/// Applies a boost on this [Ball].
void boost(Vector2 impulse) {
body.linearVelocity = impulse;
_boostTimer = _boostDuration;
}
void _rescaleSize() {
final boardHeight = BoardDimensions.bounds.height;
const maxShrinkValue = BoardDimensions.perspectiveShrinkFactor;
@ -153,10 +124,61 @@ class _BallSpriteComponent extends SpriteComponent with HasGameRef {
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.ball.keyName,
Assets.images.ball.ball.keyName,
);
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.center;
}
}
class _TurboChargeSpriteAnimationComponent extends SpriteAnimationComponent
with HasGameRef {
_TurboChargeSpriteAnimationComponent()
: super(
anchor: const Anchor(0.53, 0.72),
priority: RenderPriority.turboChargeFlame,
removeOnFinish: true,
);
late final Vector2 _textureSize;
@override
Future<void> onLoad() async {
await super.onLoad();
final spriteSheet = await gameRef.images.load(
Assets.images.ball.flameEffect.keyName,
);
const amountPerRow = 8;
const amountPerColumn = 4;
_textureSize = Vector2(
spriteSheet.width / amountPerRow,
spriteSheet.height / amountPerColumn,
);
animation = SpriteAnimation.fromFrameData(
spriteSheet,
SpriteAnimationData.sequenced(
amount: amountPerRow * amountPerColumn,
amountPerRow: amountPerRow,
stepTime: 1 / 24,
textureSize: _textureSize,
loop: false,
),
);
}
@override
void update(double dt) {
super.update(dt);
if (parent != null) {
final body = (parent! as BodyComponent).body;
final direction = -body.linearVelocity.normalized();
angle = math.atan2(direction.x, -direction.y);
size = (_textureSize / 45) * body.fixtures.first.shape.radius;
}
}
}

@ -26,7 +26,7 @@ class _BottomBoundary extends BodyComponent with InitialPosition {
/// {@macro bottom_boundary}
_BottomBoundary()
: super(
priority: 1,
priority: RenderPriority.bottomBoundary,
children: [_BottomBoundarySpriteComponent()],
) {
renderBody = false;
@ -78,7 +78,7 @@ class _BottomBoundarySpriteComponent extends SpriteComponent with HasGameRef {
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(-5.4, 55.8);
position = Vector2(-5.4, 55.6);
}
}
@ -90,7 +90,7 @@ class _OuterBoundary extends BodyComponent with InitialPosition {
/// {@macro outer_boundary}
_OuterBoundary()
: super(
priority: Ball.launchRampPriority - 1,
priority: RenderPriority.outerBoudary,
children: [_OuterBoundarySpriteComponent()],
) {
renderBody = false;

@ -12,10 +12,12 @@ import 'package:pinball_components/pinball_components.dart';
/// {@endtemplate}
class ChromeDino extends BodyComponent with InitialPosition {
/// {@macro chrome_dino}
ChromeDino() {
ChromeDino()
: super(
// TODO(alestiago): Remove once sprites are defined.
paint = Paint()..color = Colors.blue;
}
paint: Paint()..color = Colors.blue,
priority: RenderPriority.dino,
);
/// The size of the dinosaur mouth.
static final size = Vector2(5, 2.5);

@ -21,6 +21,7 @@ export 'launch_ramp.dart';
export 'layer.dart';
export 'layer_sensor.dart';
export 'plunger.dart';
export 'render_priority.dart';
export 'rocket.dart';
export 'score_text.dart';
export 'shapes/shapes.dart';

@ -10,6 +10,7 @@ class DashAnimatronic extends SpriteAnimationComponent with HasGameRef {
: super(
anchor: Anchor.center,
playing: false,
priority: RenderPriority.dashAnimatronic,
);
@override

@ -15,7 +15,8 @@ abstract class DashNestBumper extends BodyComponent with InitialPosition {
required SpriteComponent spriteComponent,
}) : _activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath,
_spriteComponent = spriteComponent;
_spriteComponent = spriteComponent,
super(priority: RenderPriority.dashBumper);
final String _activeAssetPath;
late final Sprite _activeSprite;

@ -31,7 +31,7 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall}
_DinoTopWall()
: super(
priority: 1,
priority: RenderPriority.dinoTopWall,
children: [_DinoTopWallSpriteComponent()],
) {
renderBody = false;
@ -42,7 +42,7 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
final topStraightShape = EdgeShape()
..set(
Vector2(28.4, -35.1),
Vector2(28.65, -35.1),
Vector2(29.5, -35.1),
);
final topStraightFixtureDef = FixtureDef(topStraightShape);
@ -69,8 +69,8 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
final bottomCurveShape = BezierCurveShape(
controlPoints: [
middleCurveShape.vertices.last,
Vector2(21.15, -16),
Vector2(25.6, -15.2),
Vector2(21.5, -15.8),
Vector2(25.8, -14.8),
],
);
fixturesDef.add(FixtureDef(bottomCurveShape));
@ -126,6 +126,7 @@ class _DinoBottomWall extends BodyComponent with InitialPosition {
///{@macro dino_top_wall}
_DinoBottomWall()
: super(
priority: RenderPriority.dinoBottomWall,
children: [_DinoBottomWallSpriteComponent()],
) {
renderBody = false;
@ -136,7 +137,7 @@ class _DinoBottomWall extends BodyComponent with InitialPosition {
const restitution = 1.0;
final topStraightControlPoints = [
Vector2(32.4, -8.3),
Vector2(32.4, -8.8),
Vector2(25, -7.7),
];
final topStraightShape = EdgeShape()
@ -220,6 +221,6 @@ class _DinoBottomWallSpriteComponent extends SpriteComponent with HasGameRef {
);
this.sprite = sprite;
size = sprite.originalSize / 10;
position = Vector2(23.8, -9.5);
position = Vector2(23.6, -9.5);
}
}

@ -9,6 +9,7 @@ class FlutterSignPost extends BodyComponent with InitialPosition {
/// {@macro flutter_sign_post}
FlutterSignPost()
: super(
priority: RenderPriority.flutterSignPost,
children: [_FlutterSignPostSpriteComponent()],
) {
renderBody = false;

@ -38,10 +38,21 @@ class LaunchRamp extends Blueprint {
/// {@endtemplate}
class _LaunchRampBase extends BodyComponent with InitialPosition, Layered {
/// {@macro launch_ramp_base}
_LaunchRampBase() : super(priority: Ball.launchRampPriority - 1) {
_LaunchRampBase()
: super(
priority: RenderPriority.launchRamp,
children: [
_LaunchRampBackgroundRailingSpriteComponent(),
_LaunchRampBaseSpriteComponent(),
],
) {
layer = Layer.launcher;
renderBody = false;
}
// TODO(ruimiguel): final asset differs slightly from the current shape. We
// need to fix shape with correct vertices, but right now merge them to have
// final assets at game and not be blocked.
List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[];
@ -110,28 +121,36 @@ class _LaunchRampBase extends BodyComponent with InitialPosition, Layered {
return body;
}
}
class _LaunchRampBaseSpriteComponent extends SpriteComponent with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
renderBody = false;
await add(_LaunchRampBaseSpriteComponent());
final sprite = await gameRef.loadSprite(
Assets.images.launchRamp.ramp.keyName,
);
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(25.65, 0.7);
}
}
class _LaunchRampBaseSpriteComponent extends SpriteComponent with HasGameRef {
class _LaunchRampBackgroundRailingSpriteComponent extends SpriteComponent
with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.launchRamp.ramp.keyName,
Assets.images.launchRamp.backgroundRailing.keyName,
);
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(25.65, 0);
position = Vector2(25.6, -1.3);
}
}
@ -141,7 +160,13 @@ class _LaunchRampBaseSpriteComponent extends SpriteComponent with HasGameRef {
/// {@endtemplate}
class _LaunchRampForegroundRailing extends BodyComponent with InitialPosition {
/// {@macro launch_ramp_foreground_railing}
_LaunchRampForegroundRailing() : super(priority: Ball.launchRampPriority + 1);
_LaunchRampForegroundRailing()
: super(
priority: RenderPriority.launchRampForegroundRailing,
children: [_LaunchRampForegroundRailingSpriteComponent()],
) {
renderBody = false;
}
List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[];
@ -149,7 +174,7 @@ class _LaunchRampForegroundRailing extends BodyComponent with InitialPosition {
final rightStraightShape = EdgeShape()
..set(
Vector2(27.6, -57.9),
Vector2(30, -35.1),
Vector2(38.1, 42.6),
);
final rightStraightFixtureDef = FixtureDef(rightStraightShape);
fixturesDef.add(rightStraightFixtureDef);
@ -185,14 +210,6 @@ class _LaunchRampForegroundRailing extends BodyComponent with InitialPosition {
return body;
}
@override
Future<void> onLoad() async {
await super.onLoad();
renderBody = false;
await add(_LaunchRampForegroundRailingSpriteComponent());
}
}
class _LaunchRampForegroundRailingSpriteComponent extends SpriteComponent
@ -207,7 +224,7 @@ class _LaunchRampForegroundRailingSpriteComponent extends SpriteComponent
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.center;
position = Vector2(22.8, 0);
position = Vector2(22.8, 0.5);
}
}
@ -244,8 +261,8 @@ class _LaunchRampExit extends LayerSensor {
insideLayer: Layer.launcher,
outsideLayer: Layer.board,
orientation: LayerEntranceOrientation.down,
insidePriority: Ball.launchRampPriority,
outsidePriority: 0,
insidePriority: RenderPriority.ballOnLaunchRamp,
outsidePriority: RenderPriority.ballOnBoard,
) {
layer = Layer.launcher;
renderBody = false;

@ -36,7 +36,7 @@ abstract class LayerSensor extends BodyComponent
}) : _insideLayer = insideLayer,
_outsideLayer = outsideLayer ?? Layer.board,
_insidePriority = insidePriority,
_outsidePriority = outsidePriority ?? Ball.boardPriority {
_outsidePriority = outsidePriority ?? RenderPriority.ballOnBoard {
layer = Layer.opening;
}
final Layer _insideLayer;

@ -14,7 +14,7 @@ class Plunger extends BodyComponent with InitialPosition, Layered {
required this.compressionDistance,
// TODO(ruimiguel): set to priority +1 over LaunchRamp once all priorities
// are fixed.
}) : super(priority: 0) {
}) : super(priority: RenderPriority.plunger) {
layer = Layer.launcher;
}

@ -0,0 +1,114 @@
// ignore_for_file: public_member_api_docs
import 'package:pinball_components/pinball_components.dart';
/// {@template render_priority}
/// Priorities for the component rendering order in the pinball game.
/// {@endtemplate}
// TODO(allisonryan0002): find alternative to section comments.
abstract class RenderPriority {
static const _base = 0;
static const _above = 1;
static const _below = -1;
// Ball
/// Render priority for the [Ball] while it's on the board.
static const int ballOnBoard = _base;
/// Render priority for the [Ball] while it's on the [SpaceshipRamp].
static const int ballOnSpaceshipRamp =
_above + spaceshipRampBackgroundRailing;
/// Render priority for the [Ball] while it's on the [Spaceship].
static const int ballOnSpaceship = _above + spaceshipSaucer;
/// Render priority for the [Ball] while it's on the [SpaceshipRail].
static const int ballOnSpaceshipRail = _below + spaceshipSaucer;
/// Render priority for the [Ball] while it's on the [LaunchRamp].
static const int ballOnLaunchRamp = _above + launchRamp;
// Background
// TODO(allisonryan0002): fix this magic priority. Could bump all priorities
// so there are no negatives.
static const int background = 3 * _below + _base;
// Boundaries
static const int bottomBoundary = _above + dinoBottomWall;
static const int outerBoudary = _above + background;
// Bottom Group
static const int bottomGroup = _above + ballOnBoard;
// Launcher
static const int launchRamp = _above + outerBoudary;
static const int launchRampForegroundRailing = _above + ballOnLaunchRamp;
static const int plunger = _above + launchRamp;
static const int rocket = _above + bottomBoundary;
// Dino Land
static const int dinoTopWall = _above + ballOnBoard;
static const int dino = _above + dinoTopWall;
static const int dinoBottomWall = _above + dino;
static const int slingshot = _above + ballOnBoard;
// Flutter Forest
static const int flutterSignPost = _above + launchRampForegroundRailing;
static const int dashBumper = _above + ballOnBoard;
static const int dashAnimatronic = _above + launchRampForegroundRailing;
// Sparky Fire Zone
static const int computerBase = _below + ballOnBoard;
static const int computerTop = _above + ballOnBoard;
static const int sparkyAnimatronic = _above + spaceshipRampForegroundRailing;
static const int sparkyBumper = _above + ballOnBoard;
static const int turboChargeFlame = _above + ballOnBoard;
// Android Spaceship
static const int spaceshipRail = _above + bottomGroup;
static const int spaceshipRailForeground = _above + spaceshipRail;
static const int spaceshipSaucer = _above + spaceshipRail;
static const int spaceshipSaucerWall = _above + spaceshipSaucer;
static const int androidHead = _above + spaceshipSaucer;
static const int spaceshipRamp = _above + ballOnBoard;
static const int spaceshipRampBackgroundRailing = _above + spaceshipRamp;
static const int spaceshipRampForegroundRailing =
_above + ballOnSpaceshipRamp;
static const int spaceshipRampBoardOpening = _below + ballOnBoard;
static const int alienBumper = _above + ballOnBoard;
// Score Text
static const int scoreText = _above + spaceshipRampForegroundRailing;
}

@ -9,7 +9,7 @@ class RocketSpriteComponent extends SpriteComponent with HasGameRef {
// TODO(ruimiguel): change this priority to be over launcher ramp and bottom
// wall.
/// {@macro rocket_sprite_component}
RocketSpriteComponent() : super(priority: 5);
RocketSpriteComponent() : super(priority: RenderPriority.rocket);
@override
Future<void> onLoad() async {

@ -18,7 +18,7 @@ class ScoreText extends TextComponent {
text: text,
position: position,
anchor: Anchor.center,
priority: Ball.spaceshipRampPriority + 1,
priority: RenderPriority.scoreText,
);
late final Effect _effect;

@ -43,7 +43,7 @@ class Slingshot extends BodyComponent with InitialPosition {
}) : _length = length,
_angle = angle,
super(
priority: 1,
priority: RenderPriority.slingshot,
children: [_SlinghsotSpriteComponent(spritePath, angle: angle)],
) {
renderBody = false;

@ -30,9 +30,12 @@ class Spaceship extends Blueprint {
AndroidHead()..initialPosition = position,
_SpaceshipHole(
outsideLayer: Layer.spaceshipExitRail,
outsidePriority: Ball.spaceshipRailPriority,
outsidePriority: RenderPriority.ballOnSpaceshipRail,
)..initialPosition = position - Vector2(5.2, -4.8),
_SpaceshipHole()..initialPosition = position - Vector2(-7.2, -0.8),
_SpaceshipHole(
outsideLayer: Layer.board,
outsidePriority: RenderPriority.ballOnBoard,
)..initialPosition = position - Vector2(-7.2, -0.8),
SpaceshipWall()..initialPosition = position,
]);
}
@ -43,7 +46,7 @@ class Spaceship extends Blueprint {
/// {@endtemplate}
class SpaceshipSaucer extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_saucer}
SpaceshipSaucer() : super(priority: Ball.spaceshipPriority - 1) {
SpaceshipSaucer() : super(priority: RenderPriority.spaceshipSaucer) {
layer = Layer.spaceship;
}
@ -89,7 +92,7 @@ class AndroidHead extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_bridge}
AndroidHead()
: super(
priority: Ball.spaceshipPriority + 1,
priority: RenderPriority.androidHead,
children: [_AndroidHeadSpriteAnimation()],
) {
renderBody = false;
@ -140,7 +143,7 @@ class _SpaceshipEntrance extends LayerSensor {
: super(
insideLayer: Layer.spaceship,
orientation: LayerEntranceOrientation.up,
insidePriority: Ball.spaceshipPriority,
insidePriority: RenderPriority.ballOnSpaceship,
) {
layer = Layer.spaceship;
}
@ -164,12 +167,12 @@ class _SpaceshipEntrance extends LayerSensor {
}
class _SpaceshipHole extends LayerSensor {
_SpaceshipHole({Layer? outsideLayer, int? outsidePriority = 1})
_SpaceshipHole({required Layer outsideLayer, required int outsidePriority})
: super(
insideLayer: Layer.spaceship,
outsideLayer: outsideLayer,
orientation: LayerEntranceOrientation.down,
insidePriority: 4,
insidePriority: RenderPriority.ballOnSpaceship,
outsidePriority: outsidePriority,
) {
renderBody = false;
@ -220,7 +223,7 @@ class _SpaceshipWallShape extends ChainShape {
/// {@endtemplate}
class SpaceshipWall extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_wall}
SpaceshipWall() : super(priority: Ball.spaceshipPriority + 1) {
SpaceshipWall() : super(priority: RenderPriority.spaceshipSaucerWall) {
layer = Layer.spaceship;
}

@ -37,10 +37,7 @@ class SpaceshipRail extends Blueprint {
/// Represents the spaceship drop rail from the [Spaceship].
class _SpaceshipRailRamp extends BodyComponent with InitialPosition, Layered {
_SpaceshipRailRamp()
: super(
priority: Ball.spaceshipRailPriority - 1,
) {
_SpaceshipRailRamp() : super(priority: RenderPriority.spaceshipRail) {
layer = Layer.spaceshipExitRail;
}
@ -156,7 +153,8 @@ class _SpaceshipRailRampSpriteComponent extends SpriteComponent
}
class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
_SpaceshipRailForeground() : super(priority: Ball.spaceshipRailPriority + 1);
_SpaceshipRailForeground()
: super(priority: RenderPriority.spaceshipRailForeground);
@override
Future<void> onLoad() async {
@ -173,13 +171,9 @@ class _SpaceshipRailForeground extends SpriteComponent with HasGameRef {
}
/// Represents the ground bases of the [_SpaceshipRailRamp].
class _SpaceshipRailBase extends BodyComponent with InitialPosition, Layered {
_SpaceshipRailBase({required this.radius})
: super(
priority: Ball.spaceshipRailPriority + 1,
) {
class _SpaceshipRailBase extends BodyComponent with InitialPosition {
_SpaceshipRailBase({required this.radius}) {
renderBody = false;
layer = Layer.board;
}
final double radius;
@ -202,7 +196,7 @@ class _SpaceshipRailExit extends LayerSensor {
: super(
orientation: LayerEntranceOrientation.down,
insideLayer: Layer.spaceshipExitRail,
insidePriority: Ball.spaceshipRailPriority,
insidePriority: RenderPriority.ballOnSpaceshipRail,
) {
renderBody = false;
layer = Layer.spaceshipExitRail;

@ -18,15 +18,14 @@ class SpaceshipRamp extends Blueprint {
@override
void build(_) {
final rightOpening = _SpaceshipRampOpening(
// TODO(ruimiguel): set Board priority when defined.
outsidePriority: 1,
outsidePriority: RenderPriority.ballOnBoard,
rotation: math.pi,
)
..initialPosition = Vector2(1.7, -19.8)
..layer = Layer.opening;
final leftOpening = _SpaceshipRampOpening(
outsideLayer: Layer.spaceship,
outsidePriority: Ball.spaceshipPriority,
outsidePriority: RenderPriority.ballOnSpaceship,
rotation: math.pi,
)
..initialPosition = Vector2(-13.7, -18.6)
@ -47,6 +46,7 @@ class SpaceshipRamp extends Blueprint {
rightOpening,
leftOpening,
baseRight,
_SpaceshipRampBackgroundRailingSpriteComponent(),
spaceshipRamp,
spaceshipRampForegroundRailing,
]);
@ -55,7 +55,7 @@ class SpaceshipRamp extends Blueprint {
class _SpaceshipRampBackground extends BodyComponent
with InitialPosition, Layered {
_SpaceshipRampBackground() : super(priority: Ball.spaceshipRampPriority - 1) {
_SpaceshipRampBackground() : super(priority: RenderPriority.spaceshipRamp) {
layer = Layer.spaceshipEntranceRamp;
}
@ -115,12 +115,13 @@ class _SpaceshipRampBackground extends BodyComponent
renderBody = false;
await add(_SpaceshipRampBackgroundRampSpriteComponent());
await add(_SpaceshipRampBackgroundRailingSpriteComponent());
}
}
class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
with HasGameRef {
_SpaceshipRampBackgroundRailingSpriteComponent()
: super(priority: RenderPriority.spaceshipRampBackgroundRailing);
@override
Future<void> onLoad() async {
await super.onLoad();
@ -167,7 +168,7 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition, Layered {
_SpaceshipRampForegroundRailing()
: super(
priority: Ball.spaceshipRampPriority + 1,
priority: RenderPriority.spaceshipRampForegroundRailing,
children: [_SpaceshipRampForegroundRailingSpriteComponent()],
) {
layer = Layer.spaceshipEntranceRamp;
@ -283,7 +284,7 @@ class _SpaceshipRampOpening extends LayerSensor {
insideLayer: Layer.spaceshipEntranceRamp,
outsideLayer: outsideLayer,
orientation: LayerEntranceOrientation.down,
insidePriority: Ball.spaceshipRampPriority,
insidePriority: RenderPriority.ballOnSpaceshipRamp,
outsidePriority: outsidePriority,
) {
renderBody = false;

@ -20,7 +20,8 @@ class SparkyBumper extends BodyComponent with InitialPosition {
_minorRadius = minorRadius,
_activeAssetPath = activeAssetPath,
_inactiveAssetPath = inactiveAssetPath,
_spriteComponent = spriteComponent;
_spriteComponent = spriteComponent,
super(priority: RenderPriority.sparkyBumper);
/// {@macro sparky_bumper}
SparkyBumper.a()

@ -23,7 +23,7 @@ class SparkyComputer extends Blueprint {
}
class _ComputerBase extends BodyComponent with InitialPosition {
_ComputerBase();
_ComputerBase() : super(priority: RenderPriority.computerBase);
List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[];
@ -101,7 +101,7 @@ class _ComputerTopSpriteComponent extends SpriteComponent with HasGameRef {
: super(
anchor: Anchor.center,
position: Vector2(-12.45, -49.75),
priority: 1,
priority: RenderPriority.computerTop,
);
@override

@ -39,6 +39,7 @@ flutter:
assets:
- assets/images/
- assets/images/ball/
- assets/images/baseboard/
- assets/images/boundary/
- assets/images/dino/

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

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

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

@ -1,5 +1,6 @@
// ignore_for_file: cascade_invocations
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter/material.dart';
@ -169,20 +170,41 @@ void main() {
expect(ball.body.linearVelocity, equals(Vector2.zero()));
ball.boost(Vector2.all(10));
await ball.boost(Vector2.all(10));
expect(ball.body.linearVelocity.x, greaterThan(0));
expect(ball.body.linearVelocity.y, greaterThan(0));
});
flameTester.test('adds fire effect components to the game', (game) async {
flameTester.test('adds TurboChargeSpriteAnimation', (game) async {
final ball = Ball(baseColor: Colors.blue);
await game.ensureAdd(ball);
ball.boost(Vector2.all(10));
await ball.boost(Vector2.all(10));
game.update(0);
await game.ready();
expect(game.children.whereType<FireEffect>().length, greaterThan(0));
expect(
ball.children.whereType<SpriteAnimationComponent>().single,
isNotNull,
);
});
flameTester.test('removes TurboChargeSpriteAnimation after it finishes',
(game) async {
final ball = Ball(baseColor: Colors.blue);
await game.ensureAdd(ball);
await ball.boost(Vector2.all(10));
game.update(0);
final turboChargeSpriteAnimation =
ball.children.whereType<SpriteAnimationComponent>().single;
expect(ball.contains(turboChargeSpriteAnimation), isTrue);
game.update(turboChargeSpriteAnimation.animation!.totalDuration());
game.update(0.1);
expect(ball.contains(turboChargeSpriteAnimation), isFalse);
});
});
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 KiB

After

Width:  |  Height:  |  Size: 466 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

After

Width:  |  Height:  |  Size: 216 KiB

@ -16,6 +16,7 @@ void main() {
'renders correctly',
setUp: (game, tester) async {
await game.addFromBlueprint(LaunchRamp());
await game.ready();
game.camera.followVector2(Vector2.zero());
game.camera.zoom = 4.1;
},

@ -148,7 +148,7 @@ void main() {
callback.begin(ball, sensor, MockContact());
verify(() => ball.layer = Layer.board);
verify(() => ball.priority = Ball.boardPriority).called(1);
verify(() => ball.priority = RenderPriority.ballOnBoard).called(1);
verify(ball.reorderChildren).called(1);
});
@ -174,7 +174,7 @@ void main() {
callback.begin(ball, sensor, MockContact());
verify(() => ball.layer = Layer.board);
verify(() => ball.priority = Ball.boardPriority).called(1);
verify(() => ball.priority = RenderPriority.ballOnBoard).called(1);
verify(ball.reorderChildren).called(1);
});
});

@ -94,6 +94,7 @@ void main() {
final controller = WrappedBallController(ball, gameRef);
when(() => gameRef.read<GameBloc>()).thenReturn(gameBloc);
when(() => ball.controller).thenReturn(controller);
when(() => ball.boost(any())).thenAnswer((_) async {});
await controller.turboCharge();
@ -109,6 +110,7 @@ void main() {
final controller = WrappedBallController(ball, gameRef);
when(() => gameRef.read<GameBloc>()).thenReturn(gameBloc);
when(() => ball.controller).thenReturn(controller);
when(() => ball.boost(any())).thenAnswer((_) async {});
await controller.turboCharge();
@ -124,6 +126,7 @@ void main() {
final controller = WrappedBallController(ball, gameRef);
when(() => gameRef.read<GameBloc>()).thenReturn(gameBloc);
when(() => ball.controller).thenReturn(controller);
when(() => ball.boost(any())).thenAnswer((_) async {});
await controller.turboCharge();

Loading…
Cancel
Save