@@ -230,7 +230,7 @@ steps:
230
230
double get width => size.x;
231
231
double get height => size.y;
232
232
233
- @@ -29,5 +31,20 @@ class BrickBreaker extends FlameGame {
233
+ @@ -29,5 +31,18 @@ class BrickBreaker extends FlameGame {
234
234
camera.viewfinder.anchor = Anchor.topLeft;
235
235
236
236
world.add(PlayArea());
@@ -239,12 +239,10 @@ steps:
239
239
+ Ball(
240
240
+ radius: ballRadius,
241
241
+ 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),
248
246
+ ),
249
247
+ );
250
248
+
@@ -290,10 +288,9 @@ steps:
290
288
}) : super(
291
289
radius: radius,
292
290
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,
297
294
);
298
295
299
296
final Vector2 velocity;
@@ -351,15 +348,15 @@ steps:
351
348
Ball({
352
349
required this.velocity,
353
350
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,
358
355
+ children: [CircleHitbox()],
359
356
);
360
357
361
358
final Vector2 velocity;
362
- @@ -26 ,4 +32 ,25 @@ class Ball extends CircleComponent {
359
+ @@ -25 ,4 +31 ,25 @@ class Ball extends CircleComponent {
363
360
super.update(dt);
364
361
position += velocity * dt;
365
362
}
@@ -444,7 +441,7 @@ steps:
444
441
BrickBreaker()
445
442
: super(
446
443
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 {
448
445
),
449
446
);
450
447
@@ -503,7 +500,7 @@ steps:
503
500
import 'play_area.dart';
504
501
505
502
class Ball extends CircleComponent
506
- @@ -47 ,8 +49 ,13 @@ class Ball extends CircleComponent
503
+ @@ -46 ,8 +48 ,13 @@ class Ball extends CircleComponent
507
504
} else if (intersectionPoints.first.x >= game.width) {
508
505
velocity.x = -velocity.x;
509
506
} else if (intersectionPoints.first.y >= game.height) {
@@ -554,10 +551,9 @@ steps:
554
551
555
552
final Radius cornerRadius;
556
553
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;
561
557
562
558
@override
563
559
void render(Canvas canvas) {
@@ -606,8 +602,8 @@ steps:
606
602
+ difficultyModifier: difficultyModifier,
607
603
radius: ballRadius,
608
604
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
611
607
),
612
608
);
613
609
@@ -681,15 +677,15 @@ steps:
681
677
}) : super(
682
678
radius: radius,
683
679
anchor: Anchor.center,
684
- @@ -28 ,6 +30 ,7 @@ class Ball extends CircleComponent
680
+ @@ -27 ,6 +29 ,7 @@ class Ball extends CircleComponent
685
681
);
686
682
687
683
final Vector2 velocity;
688
684
+ final double difficultyModifier;
689
685
690
686
@override
691
687
void update(double dt) {
692
- @@ -56 ,8 +59 ,17 @@ class Ball extends CircleComponent
688
+ @@ -55 ,8 +58 ,17 @@ class Ball extends CircleComponent
693
689
velocity.x =
694
690
velocity.x +
695
691
(position.x - other.position.x) / other.size.x * game.width * 0.3;
@@ -726,37 +722,36 @@ steps:
726
722
// Copyright 2023 The Flutter Authors. All rights reserved.
727
723
// Use of this source code is governed by a BSD-style license that can be
728
724
// found in the LICENSE file.
729
-
725
+
730
726
import 'package:flame/collisions.dart';
731
727
import 'package:flame/components.dart';
732
728
import 'package:flutter/material.dart';
733
-
729
+
734
730
import '../brick_breaker.dart';
735
731
import '../config.dart';
736
732
import 'ball.dart';
737
733
import 'bat.dart';
738
-
734
+
739
735
class Brick extends RectangleComponent
740
736
with CollisionCallbacks, HasGameReference<BrickBreaker> {
741
737
Brick({required super.position, required Color color})
742
738
: super(
743
739
size: Vector2(brickWidth, brickHeight),
744
740
anchor: Anchor.center,
745
- paint:
746
- Paint()
747
- ..color = color
748
- ..style = PaintingStyle.fill,
741
+ paint: Paint()
742
+ ..color = color
743
+ ..style = PaintingStyle.fill,
749
744
children: [RectangleHitbox()],
750
745
);
751
-
746
+
752
747
@override
753
748
void onCollisionStart(
754
749
Set<Vector2> intersectionPoints,
755
750
PositionComponent other,
756
751
) {
757
752
super.onCollisionStart(intersectionPoints, other);
758
753
removeFromParent();
759
-
754
+
760
755
if (game.world.children.query<Brick>().length == 1) {
761
756
game.world.removeAll(game.world.children.query<Ball>());
762
757
game.world.removeAll(game.world.children.query<Bat>());
@@ -853,7 +848,7 @@ steps:
853
848
world.add(
854
849
Ball(
855
850
difficultyModifier: difficultyModifier,
856
- @@ -58 ,7 +88 ,7 @@ class BrickBreaker extends FlameGame
851
+ @@ -56 ,7 +86 ,7 @@ class BrickBreaker extends FlameGame
857
852
),
858
853
);
859
854
@@ -862,7 +857,7 @@ steps:
862
857
for (var i = 0; i < brickColors.length; i++)
863
858
for (var j = 1; j <= 5; j++)
864
859
Brick(
865
- @@ -69 ,8 +99 ,12 @@ class BrickBreaker extends FlameGame
860
+ @@ -67 ,8 +97 ,12 @@ class BrickBreaker extends FlameGame
866
861
color: brickColors[i],
867
862
),
868
863
]);
@@ -876,7 +871,7 @@ steps:
876
871
}
877
872
878
873
@override
879
- @@ -84 ,7 +118 ,13 @@ class BrickBreaker extends FlameGame
874
+ @@ -82 ,7 +116 ,13 @@ class BrickBreaker extends FlameGame
880
875
world.children.query<Bat>().first.moveBy(-batStep);
881
876
case LogicalKeyboardKey.arrowRight:
882
877
world.children.query<Bat>().first.moveBy(batStep);
@@ -895,7 +890,7 @@ steps:
895
890
patch-u : |
896
891
--- b/brick_breaker/step_09/lib/src/components/ball.dart
897
892
+++ 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
899
894
} else if (intersectionPoints.first.x >= game.width) {
900
895
velocity.x = -velocity.x;
901
896
} else if (intersectionPoints.first.y >= game.height) {
@@ -916,7 +911,7 @@ steps:
916
911
patch-u : |
917
912
--- b/brick_breaker/step_09/lib/src/components/brick.dart
918
913
+++ 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
920
915
removeFromParent();
921
916
922
917
if (game.world.children.query<Brick>().length == 1) {
@@ -973,30 +968,24 @@ steps:
973
968
child: GameWidget.controlled(
974
969
gameFactory: BrickBreaker.new,
975
970
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
+ ),
1000
989
},
1001
990
),
1002
991
),
@@ -1083,7 +1072,7 @@ steps:
1083
1072
patch-u : |
1084
1073
--- b/brick_breaker/step_10/lib/src/components/brick.dart
1085
1074
+++ 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
1087
1076
) {
1088
1077
super.onCollisionStart(intersectionPoints, other);
1089
1078
removeFromParent();
@@ -1123,7 +1112,7 @@ steps:
1123
1112
@override
1124
1113
Widget build(BuildContext context) {
1125
1114
return MaterialApp(
1126
- @@ -35,40 +50,38 @@ class GameApp extends StatelessWidget {
1115
+ @@ -35,34 +50,38 @@ class GameApp extends StatelessWidget {
1127
1116
child: Padding(
1128
1117
padding: const EdgeInsets.all(16),
1129
1118
child: Center(
@@ -1134,31 +1123,22 @@ steps:
1134
1123
- child: GameWidget.controlled(
1135
1124
- gameFactory: BrickBreaker.new,
1136
1125
- 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,
1162
1142
+ child: Column(
1163
1143
+ children: [
1164
1144
+ ScoreCard(score: game.score),
@@ -1170,24 +1150,25 @@ steps:
1170
1150
+ child: GameWidget(
1171
1151
+ game: game,
1172
1152
+ overlayBuilderMap: {
1173
- + PlayState.welcome.name:
1174
- + (context, game) => const OverlayScreen(
1153
+ + PlayState.welcome.name: (context, game) =>
1154
+ + const OverlayScreen(
1175
1155
+ title: 'TAP TO PLAY',
1176
1156
+ subtitle: 'Use arrow keys or swipe',
1177
1157
+ ),
1178
- + PlayState.gameOver.name:
1179
- + (context, game) => const OverlayScreen(
1158
+ + PlayState.gameOver.name: (context, game) =>
1159
+ + const OverlayScreen(
1180
1160
+ title: 'G A M E O V E R',
1181
1161
+ subtitle: 'Tap to Play Again',
1182
1162
+ ),
1183
- + PlayState.won.name:
1184
- + (context, game) => const OverlayScreen(
1163
+ + PlayState.won.name: (context, game) =>
1164
+ + const OverlayScreen(
1185
1165
+ title: 'Y O U W O N ! ! !',
1186
1166
+ subtitle: 'Tap to Play Again',
1187
1167
+ ),
1188
1168
+ },
1189
- + ),
1190
- + ),
1169
+ ),
1170
+ ),
1171
+ - },
1191
1172
+ ),
1192
1173
),
1193
1174
- ),
0 commit comments