Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .dart_tool/package_graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions lib/barriers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 25 additions & 19 deletions lib/homepage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';

import 'package:flappy_bird/barriers.dart';
import 'package:flappy_bird/bird.dart';
import 'package:flutter/material.dart';
Expand All @@ -20,23 +19,23 @@ class _HomepageState extends State<Homepage> {
double barrierx2 = barrierx1 + 1.5;
Timer? gameTimer;
int score = 0;
// ignore: unused_element

void _showDialog() {
showDialog(
context: context,
barrierDismissible: false,
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)),
),
],
);
Expand All @@ -48,14 +47,18 @@ class _HomepageState extends State<Homepage> {
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++;
Expand All @@ -64,7 +67,9 @@ class _HomepageState extends State<Homepage> {
barrierx2 = 1.5;
score++;
}
// Score incremented by 1 for each barrier passed

// Check if bird is dead
if (birdisDead()) {
gameTimer?.cancel();
_showDialog();
Expand All @@ -83,7 +88,8 @@ class _HomepageState extends State<Homepage> {
barrierx1 = 1;
barrierx2 = barrierx1 + 1.5;
score = 0;
});
}); // reset the game variables to their initial values

gameTimer?.cancel();
Navigator.of(context).pop();
}
Expand Down Expand Up @@ -113,43 +119,43 @@ class _HomepageState extends State<Homepage> {
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,
),
),
),
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),
),
],
),
Expand Down
Loading