diff --git a/.dart_tool/package_graph.json b/.dart_tool/package_graph.json index 977bb3c..cb3fdff 100644 --- a/.dart_tool/package_graph.json +++ b/.dart_tool/package_graph.json @@ -180,6 +180,17 @@ "meta" ] }, + { + "name": "leak_tracker", + "version": "11.0.2", + "dependencies": [ + "clock", + "collection", + "meta", + "path", + "vm_service" + ] + }, { "name": "term_glyph", "version": "1.2.2", @@ -209,17 +220,6 @@ "string_scanner" ] }, - { - "name": "leak_tracker", - "version": "11.0.2", - "dependencies": [ - "clock", - "collection", - "meta", - "path", - "vm_service" - ] - }, { "name": "vm_service", "version": "15.0.0", diff --git a/lib/barriers.dart b/lib/barriers.dart index 10c9308..e3e447e 100644 --- a/lib/barriers.dart +++ b/lib/barriers.dart @@ -5,6 +5,7 @@ class MyBarrier extends StatelessWidget { const MyBarrier({super.key, this.size}); @override + //successfully implemented the barrier code Widget build(BuildContext context) { return Container( width: 100, diff --git a/lib/homepage.dart b/lib/homepage.dart index f0113cf..e3b09fc 100644 --- a/lib/homepage.dart +++ b/lib/homepage.dart @@ -1,5 +1,4 @@ import 'dart:async'; - import 'package:flappy_bird/barriers.dart'; import 'package:flappy_bird/bird.dart'; import 'package:flutter/material.dart'; @@ -20,7 +19,7 @@ class _HomepageState extends State { double barrierx2 = barrierx1 + 1.5; Timer? gameTimer; int score = 0; - // ignore: unused_element + void _showDialog() { showDialog( context: context, @@ -28,15 +27,15 @@ class _HomepageState extends State { builder: (context) { return AlertDialog( backgroundColor: Colors.brown, - title: Text('Game Over', style: TextStyle(color: Colors.white)), + title: const Text('Game Over', style: TextStyle(color: Colors.white)), content: Text( 'Your bird has fallen!\nScore: $score', - style: TextStyle(color: Colors.white), + style: const TextStyle(color: Colors.white), ), actions: [ TextButton( onPressed: resetGame, - child: Text('Restart', style: TextStyle(color: Colors.white)), + child: const Text('Restart', style: TextStyle(color: Colors.white)), ), ], ); @@ -48,14 +47,18 @@ class _HomepageState extends State { setState(() { isGameStarted = true; }); - gameTimer = Timer.periodic(Duration(milliseconds: 50), (timer) { + + gameTimer = Timer.periodic(const Duration(milliseconds: 50), (timer) { setState(() { time += 0.05; height = -4.9 * time * time + 2.8 * time; birdY = initialPos - height; + + // Move barriers barrierx1 -= 0.05; barrierx2 -= 0.05; + // Reposition barriers and increase score if (barrierx1 < -1.5) { barrierx1 = 1.5; score++; @@ -64,7 +67,9 @@ class _HomepageState extends State { barrierx2 = 1.5; score++; } + // Score incremented by 1 for each barrier passed + // Check if bird is dead if (birdisDead()) { gameTimer?.cancel(); _showDialog(); @@ -83,7 +88,8 @@ class _HomepageState extends State { barrierx1 = 1; barrierx2 = barrierx1 + 1.5; score = 0; - }); + }); // reset the game variables to their initial values + gameTimer?.cancel(); Navigator.of(context).pop(); } @@ -113,18 +119,18 @@ class _HomepageState extends State { children: [ MyBird(birdY: birdY), Container( - alignment: Alignment(0, -0.5), + alignment: const Alignment(0, -0.5), child: Text( isGameStarted ? '' : 'T A P T O P L A Y', - style: TextStyle(color: Colors.white), + style: const TextStyle(color: Colors.white), ), ), if (isGameStarted) Container( - alignment: Alignment(-0.8, -0.8), + alignment: const Alignment(-0.8, -0.8), child: Text( 'Score: $score', - style: TextStyle( + style: const TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold, @@ -132,24 +138,24 @@ class _HomepageState extends State { ), ), AnimatedContainer( - duration: Duration(milliseconds: 0), + duration: const Duration(milliseconds: 0), alignment: Alignment(barrierx1, 1), - child: MyBarrier(size: 50.0), + child: const MyBarrier(size: 50.0), ), AnimatedContainer( - duration: Duration(milliseconds: 0), + duration: const Duration(milliseconds: 0), alignment: Alignment(barrierx1, -1), - child: MyBarrier(size: 200.0), + child: const MyBarrier(size: 200.0), ), AnimatedContainer( - duration: Duration(milliseconds: 0), + duration: const Duration(milliseconds: 0), alignment: Alignment(barrierx2, 1), - child: MyBarrier(size: 150.0), + child: const MyBarrier(size: 150.0), ), AnimatedContainer( - duration: Duration(milliseconds: 0), + duration: const Duration(milliseconds: 0), alignment: Alignment(barrierx2, -1), - child: MyBarrier(size: 50.0), + child: const MyBarrier(size: 50.0), ), ], ),