Skip to content

Commit b7774a9

Browse files
authored
Merge pull request #4 from Ayush2006128/dev
feat: add lives
2 parents ca18f7a + c1cf7c5 commit b7774a9

8 files changed

Lines changed: 102 additions & 21 deletions

File tree

lib/src/brick_breaker.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class BrickBreaker extends FlameGame
2626

2727
final ValueNotifier<int> score = ValueNotifier(0);
2828
final ValueNotifier<int> highScore = ValueNotifier(0);
29+
final ValueNotifier<int> lives = ValueNotifier(3);
2930
bool newHighScoreAchieved = false;
3031
final rand = math.Random();
3132
double get width => size.x;
@@ -114,6 +115,7 @@ class BrickBreaker extends FlameGame
114115

115116
playState = PlayState.playing;
116117
score.value = 0;
118+
lives.value = 3;
117119
newHighScoreAchieved = false;
118120
FlameAudio.bgm.play("background.mp3", volume: 0.7);
119121
world.add(
@@ -150,6 +152,26 @@ class BrickBreaker extends FlameGame
150152
]);
151153
}
152154

155+
void onBallLost() {
156+
lives.value--;
157+
if (lives.value > 0) {
158+
world.add(
159+
Ball(
160+
difficultyModifier: difficultyModifier,
161+
radius: ballRadius,
162+
position: size / 2,
163+
velocity: Vector2(
164+
(rand.nextDouble() - 0.5) * width,
165+
height * 0.2,
166+
).normalized()
167+
..scale(height / 4),
168+
),
169+
);
170+
} else {
171+
playState = PlayState.gameOver;
172+
}
173+
}
174+
153175
@override
154176
void onTapDown(TapDownEvent event) {
155177
super.onTapDown(event);

lib/src/components/ball.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ class Ball extends CircleComponent
5454
RemoveEffect(
5555
delay: 0.35,
5656
onComplete: () {
57-
game.playState = PlayState.gameOver;
57+
game.onBallLost();
5858
},
5959
),
6060
);
61-
FlameAudio.bgm.stop();
62-
if (game.gameOver != null){
63-
game.gameOver!.start();
64-
} else {
65-
if (await Vibration.hasVibrator()) {
66-
Vibration.vibrate(preset: VibrationPreset.zigZagAlert);
61+
if (game.lives.value <= 1) {
62+
FlameAudio.bgm.stop();
63+
if (game.gameOver != null) {
64+
game.gameOver!.start();
65+
} else {
66+
if (await Vibration.hasVibrator()) {
67+
Vibration.vibrate(preset: VibrationPreset.zigZagAlert);
68+
}
6769
}
6870
}
6971
}

lib/src/widgets/game_app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class _GameAppState extends State<GameApp> {
5050
child: Center(
5151
child: Column(
5252
children: [
53-
ScoreCard(score: game.score),
53+
ScoreCard(score: game.score, lives: game.lives),
5454
Expanded(
5555
child: FittedBox(
5656
child: SizedBox(

lib/src/widgets/score_card.dart

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,61 @@
11
import 'package:flutter/material.dart';
22

33
class ScoreCard extends StatelessWidget {
4-
const ScoreCard({super.key, required this.score});
4+
const ScoreCard({
5+
super.key,
6+
required this.score,
7+
required this.lives,
8+
});
59

610
final ValueNotifier<int> score;
11+
final ValueNotifier<int> lives;
712

813
@override
914
Widget build(BuildContext context) {
1015
return ValueListenableBuilder<int>(
1116
valueListenable: score,
1217
builder: (context, score, child) {
13-
return Padding(
14-
padding: const EdgeInsets.fromLTRB(12, 6, 12, 18),
15-
child: Text(
16-
'Score: $score'.toUpperCase(),
17-
style: Theme.of(context).textTheme.titleLarge!,
18-
),
18+
return ValueListenableBuilder<int>(
19+
valueListenable: lives,
20+
builder: (context, lives, child) {
21+
return Padding(
22+
padding: const EdgeInsets.fromLTRB(12, 6, 12, 18),
23+
child: Column(
24+
children: [
25+
Text(
26+
'Score: $score'.toUpperCase(),
27+
style: Theme.of(context).textTheme.titleLarge!,
28+
),
29+
const SizedBox(height: 10),
30+
Row(
31+
mainAxisAlignment: MainAxisAlignment.center,
32+
children: List.generate(
33+
3,
34+
(index) => Padding(
35+
padding: const EdgeInsets.symmetric(horizontal: 5),
36+
child: Container(
37+
width: 16,
38+
height: 16,
39+
decoration: BoxDecoration(
40+
color: index < lives
41+
? const Color(0xff1e6091)
42+
: Colors.transparent,
43+
shape: BoxShape.circle,
44+
border: Border.all(
45+
color: const Color(0xff1e6091),
46+
width: 2,
47+
),
48+
),
49+
),
50+
),
51+
),
52+
),
53+
],
54+
),
55+
);
56+
},
1957
);
2058
},
2159
);
2260
}
23-
}
61+
}

macos/Runner/Release.entitlements

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
<dict>
55
<key>com.apple.security.app-sandbox</key>
66
<true/>
7+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8+
<true/>
9+
<key>com.apple.security.network.client</key>
10+
<true/>
711
</dict>
812
</plist>

pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ packages:
388388
dependency: transitive
389389
description:
390390
name: meta
391-
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
391+
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
392392
url: "https://pub.dev"
393393
source: hosted
394-
version: "1.16.0"
394+
version: "1.17.0"
395395
ordered_set:
396396
dependency: transitive
397397
description:
@@ -545,10 +545,10 @@ packages:
545545
dependency: transitive
546546
description:
547547
name: test_api
548-
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
548+
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
549549
url: "https://pub.dev"
550550
source: hosted
551-
version: "0.7.6"
551+
version: "0.7.7"
552552
typed_data:
553553
dependency: transitive
554554
description:

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: bricked
22
description: "brick"
33
publish_to: 'none'
4-
version: 0.5.7+6
4+
version: 0.6.1+1
55

66
environment:
77
sdk: ^3.9.2
@@ -30,6 +30,7 @@ flutter:
3030
assets:
3131
- assets/icons/
3232
- assets/audio/
33+
- shorebird.yaml
3334

3435
flutter_native_splash:
3536
color: "#ffffff"

shorebird.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is used to configure the Shorebird updater used by your app.
2+
# Learn more at https://docs.shorebird.dev
3+
# This file does not contain any sensitive information and should be checked into version control.
4+
5+
# Your app_id is the unique identifier assigned to your app.
6+
# It is used to identify your app when requesting patches from Shorebird's servers.
7+
# It is not a secret and can be shared publicly.
8+
app_id: adc69db1-d3b8-4cde-acf8-108867bf88d2
9+
10+
# auto_update controls if Shorebird should automatically update in the background on launch.
11+
# If auto_update: false, you will need to use package:shorebird_code_push to trigger updates.
12+
# https://pub.dev/packages/shorebird_code_push
13+
# Uncomment the following line to disable automatic updates.
14+
# auto_update: false

0 commit comments

Comments
 (0)