Skip to content

Commit bc84d71

Browse files
committed
Update brick_breaker rebuild script
1 parent f078780 commit bc84d71

File tree

1 file changed

+80
-99
lines changed

1 file changed

+80
-99
lines changed

brick_breaker/codelab_rebuild.yaml

Lines changed: 80 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ steps:
230230
double get width => size.x;
231231
double get height => size.y;
232232
233-
@@ -29,5 +31,20 @@ class BrickBreaker extends FlameGame {
233+
@@ -29,5 +31,18 @@ class BrickBreaker extends FlameGame {
234234
camera.viewfinder.anchor = Anchor.topLeft;
235235
236236
world.add(PlayArea());
@@ -239,12 +239,10 @@ steps:
239239
+ Ball(
240240
+ radius: ballRadius,
241241
+ position: size / 2,
242-
+ velocity:
243-
+ Vector2(
244-
+ (rand.nextDouble() - 0.5) * width,
245-
+ height * 0.2,
246-
+ ).normalized()
247-
+ ..scale(height / 4),
242+
+ velocity: Vector2(
243+
+ (rand.nextDouble() - 0.5) * width,
244+
+ height * 0.2,
245+
+ ).normalized()..scale(height / 4),
248246
+ ),
249247
+ );
250248
+
@@ -290,10 +288,9 @@ steps:
290288
}) : super(
291289
radius: radius,
292290
anchor: Anchor.center,
293-
paint:
294-
Paint()
295-
..color = const Color(0xff1e6091)
296-
..style = PaintingStyle.fill,
291+
paint: Paint()
292+
..color = const Color(0xff1e6091)
293+
..style = PaintingStyle.fill,
297294
);
298295
299296
final Vector2 velocity;
@@ -351,15 +348,15 @@ steps:
351348
Ball({
352349
required this.velocity,
353350
required super.position,
354-
@@ -17,6 +22,7 @@ class Ball extends CircleComponent {
355-
Paint()
356-
..color = const Color(0xff1e6091)
357-
..style = PaintingStyle.fill,
351+
@@ -16,6 +21,7 @@ class Ball extends CircleComponent {
352+
paint: Paint()
353+
..color = const Color(0xff1e6091)
354+
..style = PaintingStyle.fill,
358355
+ children: [CircleHitbox()],
359356
);
360357
361358
final Vector2 velocity;
362-
@@ -26,4 +32,25 @@ class Ball extends CircleComponent {
359+
@@ -25,4 +31,25 @@ class Ball extends CircleComponent {
363360
super.update(dt);
364361
position += velocity * dt;
365362
}
@@ -444,7 +441,7 @@ steps:
444441
BrickBreaker()
445442
: super(
446443
camera: CameraComponent.withFixedResolution(
447-
@@ -45,6 +49,29 @@ class BrickBreaker extends FlameGame with HasCollisionDetection {
444+
@@ -43,6 +47,29 @@ class BrickBreaker extends FlameGame with HasCollisionDetection {
448445
),
449446
);
450447
@@ -503,7 +500,7 @@ steps:
503500
import 'play_area.dart';
504501
505502
class Ball extends CircleComponent
506-
@@ -47,8 +49,13 @@ class Ball extends CircleComponent
503+
@@ -46,8 +48,13 @@ class Ball extends CircleComponent
507504
} else if (intersectionPoints.first.x >= game.width) {
508505
velocity.x = -velocity.x;
509506
} else if (intersectionPoints.first.y >= game.height) {
@@ -554,10 +551,9 @@ steps:
554551
555552
final Radius cornerRadius;
556553
557-
final _paint =
558-
Paint()
559-
..color = const Color(0xff1e6091)
560-
..style = PaintingStyle.fill;
554+
final _paint = Paint()
555+
..color = const Color(0xff1e6091)
556+
..style = PaintingStyle.fill;
561557
562558
@override
563559
void render(Canvas canvas) {
@@ -606,8 +602,8 @@ steps:
606602
+ difficultyModifier: difficultyModifier,
607603
radius: ballRadius,
608604
position: size / 2,
609-
velocity:
610-
@@ -57,6 +58,18 @@ class BrickBreaker extends FlameGame
605+
velocity: Vector2(
606+
@@ -55,6 +56,18 @@ class BrickBreaker extends FlameGame
611607
),
612608
);
613609
@@ -681,15 +677,15 @@ steps:
681677
}) : super(
682678
radius: radius,
683679
anchor: Anchor.center,
684-
@@ -28,6 +30,7 @@ class Ball extends CircleComponent
680+
@@ -27,6 +29,7 @@ class Ball extends CircleComponent
685681
);
686682
687683
final Vector2 velocity;
688684
+ final double difficultyModifier;
689685
690686
@override
691687
void update(double dt) {
692-
@@ -56,8 +59,17 @@ class Ball extends CircleComponent
688+
@@ -55,8 +58,17 @@ class Ball extends CircleComponent
693689
velocity.x =
694690
velocity.x +
695691
(position.x - other.position.x) / other.size.x * game.width * 0.3;
@@ -726,37 +722,36 @@ steps:
726722
// Copyright 2023 The Flutter Authors. All rights reserved.
727723
// Use of this source code is governed by a BSD-style license that can be
728724
// found in the LICENSE file.
729-
725+
730726
import 'package:flame/collisions.dart';
731727
import 'package:flame/components.dart';
732728
import 'package:flutter/material.dart';
733-
729+
734730
import '../brick_breaker.dart';
735731
import '../config.dart';
736732
import 'ball.dart';
737733
import 'bat.dart';
738-
734+
739735
class Brick extends RectangleComponent
740736
with CollisionCallbacks, HasGameReference<BrickBreaker> {
741737
Brick({required super.position, required Color color})
742738
: super(
743739
size: Vector2(brickWidth, brickHeight),
744740
anchor: Anchor.center,
745-
paint:
746-
Paint()
747-
..color = color
748-
..style = PaintingStyle.fill,
741+
paint: Paint()
742+
..color = color
743+
..style = PaintingStyle.fill,
749744
children: [RectangleHitbox()],
750745
);
751-
746+
752747
@override
753748
void onCollisionStart(
754749
Set<Vector2> intersectionPoints,
755750
PositionComponent other,
756751
) {
757752
super.onCollisionStart(intersectionPoints, other);
758753
removeFromParent();
759-
754+
760755
if (game.world.children.query<Brick>().length == 1) {
761756
game.world.removeAll(game.world.children.query<Ball>());
762757
game.world.removeAll(game.world.children.query<Bat>());
@@ -853,7 +848,7 @@ steps:
853848
world.add(
854849
Ball(
855850
difficultyModifier: difficultyModifier,
856-
@@ -58,7 +88,7 @@ class BrickBreaker extends FlameGame
851+
@@ -56,7 +86,7 @@ class BrickBreaker extends FlameGame
857852
),
858853
);
859854
@@ -862,7 +857,7 @@ steps:
862857
for (var i = 0; i < brickColors.length; i++)
863858
for (var j = 1; j <= 5; j++)
864859
Brick(
865-
@@ -69,8 +99,12 @@ class BrickBreaker extends FlameGame
860+
@@ -67,8 +97,12 @@ class BrickBreaker extends FlameGame
866861
color: brickColors[i],
867862
),
868863
]);
@@ -876,7 +871,7 @@ steps:
876871
}
877872
878873
@override
879-
@@ -84,7 +118,13 @@ class BrickBreaker extends FlameGame
874+
@@ -82,7 +116,13 @@ class BrickBreaker extends FlameGame
880875
world.children.query<Bat>().first.moveBy(-batStep);
881876
case LogicalKeyboardKey.arrowRight:
882877
world.children.query<Bat>().first.moveBy(batStep);
@@ -895,7 +890,7 @@ steps:
895890
patch-u: |
896891
--- b/brick_breaker/step_09/lib/src/components/ball.dart
897892
+++ a/brick_breaker/step_09/lib/src/components/ball.dart
898-
@@ -52,7 +52,14 @@ class Ball extends CircleComponent
893+
@@ -51,7 +51,14 @@ class Ball extends CircleComponent
899894
} else if (intersectionPoints.first.x >= game.width) {
900895
velocity.x = -velocity.x;
901896
} else if (intersectionPoints.first.y >= game.height) {
@@ -916,7 +911,7 @@ steps:
916911
patch-u: |
917912
--- b/brick_breaker/step_09/lib/src/components/brick.dart
918913
+++ a/brick_breaker/step_09/lib/src/components/brick.dart
919-
@@ -33,6 +33,7 @@ class Brick extends RectangleComponent
914+
@@ -32,6 +32,7 @@ class Brick extends RectangleComponent
920915
removeFromParent();
921916
922917
if (game.world.children.query<Brick>().length == 1) {
@@ -973,30 +968,24 @@ steps:
973968
child: GameWidget.controlled(
974969
gameFactory: BrickBreaker.new,
975970
overlayBuilderMap: {
976-
PlayState.welcome.name:
977-
(context, game) => Center(
978-
child: Text(
979-
'TAP TO PLAY',
980-
style:
981-
Theme.of(context).textTheme.headlineLarge,
982-
),
983-
),
984-
PlayState.gameOver.name:
985-
(context, game) => Center(
986-
child: Text(
987-
'G A M E O V E R',
988-
style:
989-
Theme.of(context).textTheme.headlineLarge,
990-
),
991-
),
992-
PlayState.won.name:
993-
(context, game) => Center(
994-
child: Text(
995-
'Y O U W O N ! ! !',
996-
style:
997-
Theme.of(context).textTheme.headlineLarge,
998-
),
999-
),
971+
PlayState.welcome.name: (context, game) => Center(
972+
child: Text(
973+
'TAP TO PLAY',
974+
style: Theme.of(context).textTheme.headlineLarge,
975+
),
976+
),
977+
PlayState.gameOver.name: (context, game) => Center(
978+
child: Text(
979+
'G A M E O V E R',
980+
style: Theme.of(context).textTheme.headlineLarge,
981+
),
982+
),
983+
PlayState.won.name: (context, game) => Center(
984+
child: Text(
985+
'Y O U W O N ! ! !',
986+
style: Theme.of(context).textTheme.headlineLarge,
987+
),
988+
),
1000989
},
1001990
),
1002991
),
@@ -1083,7 +1072,7 @@ steps:
10831072
patch-u: |
10841073
--- b/brick_breaker/step_10/lib/src/components/brick.dart
10851074
+++ a/brick_breaker/step_10/lib/src/components/brick.dart
1086-
@@ -31,6 +31,7 @@ class Brick extends RectangleComponent
1075+
@@ -30,6 +30,7 @@ class Brick extends RectangleComponent
10871076
) {
10881077
super.onCollisionStart(intersectionPoints, other);
10891078
removeFromParent();
@@ -1123,7 +1112,7 @@ steps:
11231112
@override
11241113
Widget build(BuildContext context) {
11251114
return MaterialApp(
1126-
@@ -35,40 +50,38 @@ class GameApp extends StatelessWidget {
1115+
@@ -35,34 +50,38 @@ class GameApp extends StatelessWidget {
11271116
child: Padding(
11281117
padding: const EdgeInsets.all(16),
11291118
child: Center(
@@ -1134,31 +1123,22 @@ steps:
11341123
- child: GameWidget.controlled(
11351124
- gameFactory: BrickBreaker.new,
11361125
- overlayBuilderMap: {
1137-
- PlayState.welcome.name:
1138-
- (context, game) => Center(
1139-
- child: Text(
1140-
- 'TAP TO PLAY',
1141-
- style:
1142-
- Theme.of(context).textTheme.headlineLarge,
1143-
- ),
1144-
- ),
1145-
- PlayState.gameOver.name:
1146-
- (context, game) => Center(
1147-
- child: Text(
1148-
- 'G A M E O V E R',
1149-
- style:
1150-
- Theme.of(context).textTheme.headlineLarge,
1151-
- ),
1152-
- ),
1153-
- PlayState.won.name:
1154-
- (context, game) => Center(
1155-
- child: Text(
1156-
- 'Y O U W O N ! ! !',
1157-
- style:
1158-
- Theme.of(context).textTheme.headlineLarge,
1159-
- ),
1160-
- ),
1161-
- },
1126+
- PlayState.welcome.name: (context, game) => Center(
1127+
- child: Text(
1128+
- 'TAP TO PLAY',
1129+
- style: Theme.of(context).textTheme.headlineLarge,
1130+
- ),
1131+
- ),
1132+
- PlayState.gameOver.name: (context, game) => Center(
1133+
- child: Text(
1134+
- 'G A M E O V E R',
1135+
- style: Theme.of(context).textTheme.headlineLarge,
1136+
- ),
1137+
- ),
1138+
- PlayState.won.name: (context, game) => Center(
1139+
- child: Text(
1140+
- 'Y O U W O N ! ! !',
1141+
- style: Theme.of(context).textTheme.headlineLarge,
11621142
+ child: Column(
11631143
+ children: [
11641144
+ ScoreCard(score: game.score),
@@ -1170,24 +1150,25 @@ steps:
11701150
+ child: GameWidget(
11711151
+ game: game,
11721152
+ overlayBuilderMap: {
1173-
+ PlayState.welcome.name:
1174-
+ (context, game) => const OverlayScreen(
1153+
+ PlayState.welcome.name: (context, game) =>
1154+
+ const OverlayScreen(
11751155
+ title: 'TAP TO PLAY',
11761156
+ subtitle: 'Use arrow keys or swipe',
11771157
+ ),
1178-
+ PlayState.gameOver.name:
1179-
+ (context, game) => const OverlayScreen(
1158+
+ PlayState.gameOver.name: (context, game) =>
1159+
+ const OverlayScreen(
11801160
+ title: 'G A M E O V E R',
11811161
+ subtitle: 'Tap to Play Again',
11821162
+ ),
1183-
+ PlayState.won.name:
1184-
+ (context, game) => const OverlayScreen(
1163+
+ PlayState.won.name: (context, game) =>
1164+
+ const OverlayScreen(
11851165
+ title: 'Y O U W O N ! ! !',
11861166
+ subtitle: 'Tap to Play Again',
11871167
+ ),
11881168
+ },
1189-
+ ),
1190-
+ ),
1169+
),
1170+
),
1171+
- },
11911172
+ ),
11921173
),
11931174
- ),

0 commit comments

Comments
 (0)