From 0197e07401734fde8f1b9372d3bebc6e454b67d9 Mon Sep 17 00:00:00 2001 From: PresenceOP-Coder Date: Tue, 21 Oct 2025 17:12:43 +0530 Subject: [PATCH 1/3] fix(core): resolve all minor gameplay bugs --- .dart_tool/package_config.json | 70 +++++++------- .dart_tool/package_graph.json | 166 ++++++++++++++++----------------- .dart_tool/version | 2 +- lib/homepage.dart | 70 +++++++++++--- pubspec.lock | 22 ++--- 5 files changed, 182 insertions(+), 148 deletions(-) diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 861acea..5ee87a5 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -3,163 +3,163 @@ "packages": [ { "name": "async", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/async-2.13.0", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/async-2.13.0", "packageUri": "lib/", "languageVersion": "3.4" }, { "name": "boolean_selector", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/boolean_selector-2.1.2", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/boolean_selector-2.1.2", "packageUri": "lib/", "languageVersion": "3.1" }, { "name": "characters", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/characters-1.4.0", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/characters-1.4.0", "packageUri": "lib/", "languageVersion": "3.4" }, { "name": "clock", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/clock-1.1.2", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/clock-1.1.2", "packageUri": "lib/", "languageVersion": "3.4" }, { "name": "collection", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/collection-1.19.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/collection-1.19.1", "packageUri": "lib/", "languageVersion": "3.4" }, { "name": "cupertino_icons", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/cupertino_icons-1.0.8", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/cupertino_icons-1.0.8", "packageUri": "lib/", "languageVersion": "3.1" }, { "name": "fake_async", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/fake_async-1.3.3", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/fake_async-1.3.3", "packageUri": "lib/", "languageVersion": "3.3" }, { "name": "flutter", - "rootUri": "file:///home/ashu/app%20development/flutter/packages/flutter", + "rootUri": "file:///C:/src/flutter/packages/flutter", "packageUri": "lib/", - "languageVersion": "3.7" + "languageVersion": "3.8" }, { "name": "flutter_lints", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/flutter_lints-5.0.0", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_lints-5.0.0", "packageUri": "lib/", "languageVersion": "3.5" }, { "name": "flutter_test", - "rootUri": "file:///home/ashu/app%20development/flutter/packages/flutter_test", + "rootUri": "file:///C:/src/flutter/packages/flutter_test", "packageUri": "lib/", - "languageVersion": "3.7" + "languageVersion": "3.8" }, { "name": "leak_tracker", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/leak_tracker-10.0.9", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/leak_tracker-11.0.2", "packageUri": "lib/", "languageVersion": "3.2" }, { "name": "leak_tracker_flutter_testing", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/leak_tracker_flutter_testing-3.0.9", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/leak_tracker_flutter_testing-3.0.10", "packageUri": "lib/", "languageVersion": "3.2" }, { "name": "leak_tracker_testing", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/leak_tracker_testing-3.0.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/leak_tracker_testing-3.0.2", "packageUri": "lib/", "languageVersion": "3.2" }, { "name": "lints", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/lints-5.1.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/lints-5.1.1", "packageUri": "lib/", "languageVersion": "3.6" }, { "name": "matcher", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/matcher-0.12.17", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/matcher-0.12.17", "packageUri": "lib/", "languageVersion": "3.4" }, { "name": "material_color_utilities", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/material_color_utilities-0.11.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/material_color_utilities-0.11.1", "packageUri": "lib/", "languageVersion": "2.17" }, { "name": "meta", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/meta-1.16.0", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/meta-1.16.0", "packageUri": "lib/", "languageVersion": "2.12" }, { "name": "path", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/path-1.9.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/path-1.9.1", "packageUri": "lib/", "languageVersion": "3.4" }, { "name": "sky_engine", - "rootUri": "file:///home/ashu/app%20development/flutter/bin/cache/pkg/sky_engine", + "rootUri": "file:///C:/src/flutter/bin/cache/pkg/sky_engine", "packageUri": "lib/", - "languageVersion": "3.7" + "languageVersion": "3.8" }, { "name": "source_span", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/source_span-1.10.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/source_span-1.10.1", "packageUri": "lib/", "languageVersion": "3.1" }, { "name": "stack_trace", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/stack_trace-1.12.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/stack_trace-1.12.1", "packageUri": "lib/", "languageVersion": "3.4" }, { "name": "stream_channel", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/stream_channel-2.1.4", "packageUri": "lib/", "languageVersion": "3.3" }, { "name": "string_scanner", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/string_scanner-1.4.1", "packageUri": "lib/", "languageVersion": "3.1" }, { "name": "term_glyph", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/term_glyph-1.2.2", "packageUri": "lib/", "languageVersion": "3.1" }, { "name": "test_api", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/test_api-0.7.4", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/test_api-0.7.6", "packageUri": "lib/", "languageVersion": "3.5" }, { "name": "vector_math", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/vector_math-2.1.4", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/vector_math-2.2.0", "packageUri": "lib/", - "languageVersion": "2.14" + "languageVersion": "3.1" }, { "name": "vm_service", - "rootUri": "file:///home/ashu/.pub-cache/hosted/pub.dev/vm_service-15.0.0", + "rootUri": "file:///C:/Users/shrey/AppData/Local/Pub/Cache/hosted/pub.dev/vm_service-15.0.0", "packageUri": "lib/", "languageVersion": "3.3" }, @@ -171,8 +171,8 @@ } ], "generator": "pub", - "generatorVersion": "3.8.1", - "flutterRoot": "file:///home/ashu/app%20development/flutter", - "flutterVersion": "3.32.7", - "pubCache": "file:///home/ashu/.pub-cache" + "generatorVersion": "3.9.2", + "flutterRoot": "file:///C:/src/flutter", + "flutterVersion": "3.35.5", + "pubCache": "file:///C:/Users/shrey/AppData/Local/Pub/Cache" } diff --git a/.dart_tool/package_graph.json b/.dart_tool/package_graph.json index 0a2f9ea..977bb3c 100644 --- a/.dart_tool/package_graph.json +++ b/.dart_tool/package_graph.json @@ -26,28 +26,18 @@ "name": "flutter_test", "version": "0.0.0", "dependencies": [ - "async", - "boolean_selector", - "characters", "clock", "collection", "fake_async", "flutter", - "leak_tracker", "leak_tracker_flutter_testing", - "leak_tracker_testing", "matcher", - "material_color_utilities", "meta", "path", - "source_span", "stack_trace", "stream_channel", - "string_scanner", - "term_glyph", "test_api", - "vector_math", - "vm_service" + "vector_math" ] }, { @@ -72,23 +62,6 @@ "version": "5.1.1", "dependencies": [] }, - { - "name": "vm_service", - "version": "15.0.0", - "dependencies": [] - }, - { - "name": "term_glyph", - "version": "1.2.2", - "dependencies": [] - }, - { - "name": "string_scanner", - "version": "1.4.1", - "dependencies": [ - "source_span" - ] - }, { "name": "stream_channel", "version": "2.1.4", @@ -96,76 +69,19 @@ "async" ] }, - { - "name": "source_span", - "version": "1.10.1", - "dependencies": [ - "collection", - "path", - "term_glyph" - ] - }, { "name": "meta", "version": "1.16.0", "dependencies": [] }, - { - "name": "material_color_utilities", - "version": "0.11.1", - "dependencies": [ - "collection" - ] - }, - { - "name": "leak_tracker_testing", - "version": "3.0.1", - "dependencies": [ - "leak_tracker", - "matcher", - "meta" - ] - }, - { - "name": "leak_tracker", - "version": "10.0.9", - "dependencies": [ - "clock", - "collection", - "meta", - "path", - "vm_service" - ] - }, { "name": "collection", "version": "1.19.1", "dependencies": [] }, - { - "name": "characters", - "version": "1.4.0", - "dependencies": [] - }, - { - "name": "boolean_selector", - "version": "2.1.2", - "dependencies": [ - "source_span", - "string_scanner" - ] - }, - { - "name": "async", - "version": "2.13.0", - "dependencies": [ - "collection", - "meta" - ] - }, { "name": "leak_tracker_flutter_testing", - "version": "3.0.9", + "version": "3.0.10", "dependencies": [ "flutter", "leak_tracker", @@ -176,7 +92,7 @@ }, { "name": "vector_math", - "version": "2.1.4", + "version": "2.2.0", "dependencies": [] }, { @@ -217,7 +133,7 @@ }, { "name": "test_api", - "version": "0.7.4", + "version": "0.7.6", "dependencies": [ "async", "boolean_selector", @@ -234,6 +150,80 @@ "name": "sky_engine", "version": "0.0.0", "dependencies": [] + }, + { + "name": "material_color_utilities", + "version": "0.11.1", + "dependencies": [ + "collection" + ] + }, + { + "name": "characters", + "version": "1.4.0", + "dependencies": [] + }, + { + "name": "async", + "version": "2.13.0", + "dependencies": [ + "collection", + "meta" + ] + }, + { + "name": "leak_tracker_testing", + "version": "3.0.2", + "dependencies": [ + "leak_tracker", + "matcher", + "meta" + ] + }, + { + "name": "term_glyph", + "version": "1.2.2", + "dependencies": [] + }, + { + "name": "string_scanner", + "version": "1.4.1", + "dependencies": [ + "source_span" + ] + }, + { + "name": "source_span", + "version": "1.10.1", + "dependencies": [ + "collection", + "path", + "term_glyph" + ] + }, + { + "name": "boolean_selector", + "version": "2.1.2", + "dependencies": [ + "source_span", + "string_scanner" + ] + }, + { + "name": "leak_tracker", + "version": "11.0.2", + "dependencies": [ + "clock", + "collection", + "meta", + "path", + "vm_service" + ] + }, + { + "name": "vm_service", + "version": "15.0.0", + "dependencies": [] } ], "configVersion": 1 diff --git a/.dart_tool/version b/.dart_tool/version index 490717c..fe5d712 100644 --- a/.dart_tool/version +++ b/.dart_tool/version @@ -1 +1 @@ -3.32.7 \ No newline at end of file +3.35.5 \ No newline at end of file diff --git a/lib/homepage.dart b/lib/homepage.dart index 006474f..f0113cf 100644 --- a/lib/homepage.dart +++ b/lib/homepage.dart @@ -1,4 +1,4 @@ -// import 'dart:async'; +import 'dart:async'; import 'package:flappy_bird/barriers.dart'; import 'package:flappy_bird/bird.dart'; @@ -18,6 +18,8 @@ class _HomepageState extends State { bool isGameStarted = false; static double barrierx1 = 1; double barrierx2 = barrierx1 + 1.5; + Timer? gameTimer; + int score = 0; // ignore: unused_element void _showDialog() { showDialog( @@ -28,7 +30,7 @@ class _HomepageState extends State { backgroundColor: Colors.brown, title: Text('Game Over', style: TextStyle(color: Colors.white)), content: Text( - 'Your bird has fallen!', + 'Your bird has fallen!\nScore: $score', style: TextStyle(color: Colors.white), ), actions: [ @@ -43,26 +45,56 @@ class _HomepageState extends State { } void startGame() { - // TODO: Implement the game loop logic here. - // Hint: Use a Timer to periodically update the bird's position and barriers. - // Hint: Update the bird's position using physics equations. - // Hint: Check if the bird is dead and stop the game if necessary. + setState(() { + isGameStarted = true; + }); + gameTimer = Timer.periodic(Duration(milliseconds: 50), (timer) { + setState(() { + time += 0.05; + height = -4.9 * time * time + 2.8 * time; + birdY = initialPos - height; + barrierx1 -= 0.05; + barrierx2 -= 0.05; + + if (barrierx1 < -1.5) { + barrierx1 = 1.5; + score++; + } + if (barrierx2 < -1.5) { + barrierx2 = 1.5; + score++; + } + + if (birdisDead()) { + gameTimer?.cancel(); + _showDialog(); + } + }); + }); } void resetGame() { - // TODO: Reset the game state to its initial values. - // Hint: Reset birdY, initialPos, time, and isGameStarted. + setState(() { + birdY = 0.0; + initialPos = birdY; + time = 0; + height = 0; + isGameStarted = false; + barrierx1 = 1; + barrierx2 = barrierx1 + 1.5; + score = 0; + }); + gameTimer?.cancel(); + Navigator.of(context).pop(); } void jump() { - // TODO: Implement the jump logic. - // Hint: Reset the time and update the initial position of the bird. + time = 0; + initialPos = birdY; } bool birdisDead() { - // TODO: Check if the bird is out of bounds. - // Hint: Return true if birdY is greater than 1 or less than -1. - return false; // Replace this with the correct condition. + return birdY > 1 || birdY < -1; } @override @@ -87,6 +119,18 @@ class _HomepageState extends State { style: TextStyle(color: Colors.white), ), ), + if (isGameStarted) + Container( + alignment: Alignment(-0.8, -0.8), + child: Text( + 'Score: $score', + style: TextStyle( + color: Colors.white, + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ), AnimatedContainer( duration: Duration(milliseconds: 0), alignment: Alignment(barrierx1, 1), diff --git a/pubspec.lock b/pubspec.lock index 63806a4..3d7e7c6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -79,26 +79,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0" + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" url: "https://pub.dev" source: hosted - version: "10.0.9" + version: "11.0.2" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573 + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" url: "https://pub.dev" source: hosted - version: "3.0.9" + version: "3.0.10" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" lints: dependency: transitive description: @@ -188,18 +188,18 @@ packages: dependency: transitive description: name: test_api - sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.4" + version: "0.7.6" vector_math: dependency: transitive description: name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.2.0" vm_service: dependency: transitive description: @@ -209,5 +209,5 @@ packages: source: hosted version: "15.0.0" sdks: - dart: ">=3.7.2 <4.0.0" + dart: ">=3.8.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" From 707d641de61ba39473f1909b63afc1ab85eb51fd Mon Sep 17 00:00:00 2001 From: PresenceOP-Coder Date: Tue, 21 Oct 2025 17:27:09 +0530 Subject: [PATCH 2/3] feat(game): implement jump() logic for bird --- lib/homepage.dart | 66 ++++++++--------------------------------------- 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/lib/homepage.dart b/lib/homepage.dart index f0113cf..5793e77 100644 --- a/lib/homepage.dart +++ b/lib/homepage.dart @@ -1,4 +1,4 @@ -import 'dart:async'; +// import 'dart:async'; import 'package:flappy_bird/barriers.dart'; import 'package:flappy_bird/bird.dart'; @@ -18,8 +18,6 @@ class _HomepageState extends State { bool isGameStarted = false; static double barrierx1 = 1; double barrierx2 = barrierx1 + 1.5; - Timer? gameTimer; - int score = 0; // ignore: unused_element void _showDialog() { showDialog( @@ -30,7 +28,7 @@ class _HomepageState extends State { backgroundColor: Colors.brown, title: Text('Game Over', style: TextStyle(color: Colors.white)), content: Text( - 'Your bird has fallen!\nScore: $score', + 'Your bird has fallen!', style: TextStyle(color: Colors.white), ), actions: [ @@ -45,47 +43,15 @@ class _HomepageState extends State { } void startGame() { - setState(() { - isGameStarted = true; - }); - gameTimer = Timer.periodic(Duration(milliseconds: 50), (timer) { - setState(() { - time += 0.05; - height = -4.9 * time * time + 2.8 * time; - birdY = initialPos - height; - barrierx1 -= 0.05; - barrierx2 -= 0.05; - - if (barrierx1 < -1.5) { - barrierx1 = 1.5; - score++; - } - if (barrierx2 < -1.5) { - barrierx2 = 1.5; - score++; - } - - if (birdisDead()) { - gameTimer?.cancel(); - _showDialog(); - } - }); - }); + // TODO: Implement the game loop logic here. + // Hint: Use a Timer to periodically update the bird's position and barriers. + // Hint: Update the bird's position using physics equations. + // Hint: Check if the bird is dead and stop the game if necessary. } void resetGame() { - setState(() { - birdY = 0.0; - initialPos = birdY; - time = 0; - height = 0; - isGameStarted = false; - barrierx1 = 1; - barrierx2 = barrierx1 + 1.5; - score = 0; - }); - gameTimer?.cancel(); - Navigator.of(context).pop(); + // TODO: Reset the game state to its initial values. + // Hint: Reset birdY, initialPos, time, and isGameStarted. } void jump() { @@ -94,7 +60,9 @@ class _HomepageState extends State { } bool birdisDead() { - return birdY > 1 || birdY < -1; + // TODO: Check if the bird is out of bounds. + // Hint: Return true if birdY is greater than 1 or less than -1. + return false; // Replace this with the correct condition. } @override @@ -119,18 +87,6 @@ class _HomepageState extends State { style: TextStyle(color: Colors.white), ), ), - if (isGameStarted) - Container( - alignment: Alignment(-0.8, -0.8), - child: Text( - 'Score: $score', - style: TextStyle( - color: Colors.white, - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ), AnimatedContainer( duration: Duration(milliseconds: 0), alignment: Alignment(barrierx1, 1), From b82ae69d9d0f6b6d4634850ba658a2c5f278702e Mon Sep 17 00:00:00 2001 From: PresenceOP-Coder Date: Wed, 22 Oct 2025 09:03:01 +0530 Subject: [PATCH 3/3] feat(game):complete full Flappy Bird functionality --- lib/homepage.dart | 66 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/lib/homepage.dart b/lib/homepage.dart index 5793e77..f0113cf 100644 --- a/lib/homepage.dart +++ b/lib/homepage.dart @@ -1,4 +1,4 @@ -// import 'dart:async'; +import 'dart:async'; import 'package:flappy_bird/barriers.dart'; import 'package:flappy_bird/bird.dart'; @@ -18,6 +18,8 @@ class _HomepageState extends State { bool isGameStarted = false; static double barrierx1 = 1; double barrierx2 = barrierx1 + 1.5; + Timer? gameTimer; + int score = 0; // ignore: unused_element void _showDialog() { showDialog( @@ -28,7 +30,7 @@ class _HomepageState extends State { backgroundColor: Colors.brown, title: Text('Game Over', style: TextStyle(color: Colors.white)), content: Text( - 'Your bird has fallen!', + 'Your bird has fallen!\nScore: $score', style: TextStyle(color: Colors.white), ), actions: [ @@ -43,15 +45,47 @@ class _HomepageState extends State { } void startGame() { - // TODO: Implement the game loop logic here. - // Hint: Use a Timer to periodically update the bird's position and barriers. - // Hint: Update the bird's position using physics equations. - // Hint: Check if the bird is dead and stop the game if necessary. + setState(() { + isGameStarted = true; + }); + gameTimer = Timer.periodic(Duration(milliseconds: 50), (timer) { + setState(() { + time += 0.05; + height = -4.9 * time * time + 2.8 * time; + birdY = initialPos - height; + barrierx1 -= 0.05; + barrierx2 -= 0.05; + + if (barrierx1 < -1.5) { + barrierx1 = 1.5; + score++; + } + if (barrierx2 < -1.5) { + barrierx2 = 1.5; + score++; + } + + if (birdisDead()) { + gameTimer?.cancel(); + _showDialog(); + } + }); + }); } void resetGame() { - // TODO: Reset the game state to its initial values. - // Hint: Reset birdY, initialPos, time, and isGameStarted. + setState(() { + birdY = 0.0; + initialPos = birdY; + time = 0; + height = 0; + isGameStarted = false; + barrierx1 = 1; + barrierx2 = barrierx1 + 1.5; + score = 0; + }); + gameTimer?.cancel(); + Navigator.of(context).pop(); } void jump() { @@ -60,9 +94,7 @@ class _HomepageState extends State { } bool birdisDead() { - // TODO: Check if the bird is out of bounds. - // Hint: Return true if birdY is greater than 1 or less than -1. - return false; // Replace this with the correct condition. + return birdY > 1 || birdY < -1; } @override @@ -87,6 +119,18 @@ class _HomepageState extends State { style: TextStyle(color: Colors.white), ), ), + if (isGameStarted) + Container( + alignment: Alignment(-0.8, -0.8), + child: Text( + 'Score: $score', + style: TextStyle( + color: Colors.white, + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ), AnimatedContainer( duration: Duration(milliseconds: 0), alignment: Alignment(barrierx1, 1),