Skip to content

Commit

Permalink
update Settings
Browse files Browse the repository at this point in the history
> add new birds
> new func on database to save the background user selected
> Edit on settings
  • Loading branch information
wvzv committed Aug 31, 2022
1 parent 15d80da commit 072de45
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 281 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/pics/blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/pics/bluebird.png
Binary file not shown.
Binary file added assets/pics/greenBird.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/pics/redbird.png
Binary file not shown.
26 changes: 12 additions & 14 deletions lib/Constant/constant.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// ignore_for_file: prefer_const_constructors

import 'package:flappy_bird/Database/database.dart';
import 'package:flappy_bird/Layouts/Pages/page_settings.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_Button.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_bird.dart';
Expand Down Expand Up @@ -54,17 +57,12 @@ enum Navigation{ home, settings, leaderBord }
String about = "The game is a side-scroller where the player"
" controls a bird, attempting to fly between "
" columns of green pipes without hitting them";

late BoxDecoration gameBackground;
int indicator = 0;
String background(int index){
String image = "";
if(index == 0){
image = "assets/pics/background-day.png";
}else if(index == 1){
image = "assets/pics/background-night.png";
}else{
image = "assets/pics/background-after-night.png";
}
return image;
}
String im = "0";
BoxDecoration background(String y){
return BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/pics/$y.png"),
fit: BoxFit.fill),
);
}
String bird = "assets/pics/bird.png";
14 changes: 14 additions & 0 deletions lib/Database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ int read(int id){
return myBox.get(id);
}

void writeBackground(int id, String image){
myBox.put(0, image);
print("WriteBackground func is Activated");
}

String readBackground(int id){
print("Read func is Activated");
if(myBox.get(id) == null){
print("0 has been returned");
return "0 has been returned";
}
return myBox.get(id);
}

void delete(){
print("delete func is Activated");
}
45 changes: 19 additions & 26 deletions lib/Layouts/Pages/page_home.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// ignore_for_file: prefer_const_constructors
// ignore_for_file: prefer_const_constructors, prefer_const_constructors_in_immutables, avoid_unnecessary_containers

import 'dart:async';
import 'package:flappy_bird/Database/database.dart';
import 'package:flappy_bird/Layouts/Pages/page_start_screen.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_bird.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_score.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_barrier.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_cover.dart';
import 'package:flappy_bird/constant/constant.dart';
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
import 'package:audioplayers/audioplayers.dart';

import '../../Constant/constant.dart';

class HomePage extends StatefulWidget {
HomePage({Key? key}) : super(key: key);
Expand All @@ -20,21 +18,9 @@ class HomePage extends StatefulWidget {
}
class _HomePageState extends State<HomePage> {


String setTheme() {
if (theme == true) {
return "assets/pics/background-day.png";
}
else {
return "assets/pics/background-night.png";
}
}


@override
void initState(){
super.initState();

setAudio();

audioPlayer.onPlayerStateChanged.listen((state) {
Expand Down Expand Up @@ -69,12 +55,12 @@ class _HomePageState extends State<HomePage> {
}

@override

void dispose(){
audioPlayer.dispose();
super.dispose();

}


@override
Widget build(BuildContext context) {
Expand All @@ -85,10 +71,7 @@ class _HomePageState extends State<HomePage> {
Expanded(
flex: 3,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(setTheme()),
fit: BoxFit.cover)),
decoration: background(im),
child: Stack(
children: [
Bird(yAxis, birdWidth, birdHeight),
Expand All @@ -104,16 +87,26 @@ class _HomePageState extends State<HomePage> {
Barrier(
barrierHeight[0][1], barrierWidth, barrierX[0], false),
Barrier(barrierHeight[1][0], barrierWidth, barrierX[1], true),
Barrier(
barrierHeight[1][1], barrierWidth, barrierX[1], false),

Barrier(barrierHeight[1][1], barrierWidth, barrierX[1], false),
Positioned(
bottom: 1,
right: 1,
left: 1,
child: Container(child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text("Score : $SCORE",style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4"),), // Best TEXT
Text("Best : $TOP_SCORE",style: TextStyle(color: Colors.white,fontSize: 30,fontFamily: "Magic4")),
],
),),
),
],
),
),
),
Expanded(
flex: 1,
child: gameHasStarted ? Score() : Cover(),
child: Cover(),
),
]),
),
Expand Down Expand Up @@ -156,7 +149,6 @@ class _HomePageState extends State<HomePage> {
if (birdIsDead()) {
timer.cancel();
_showDialog();

}
time += 0.032;
});
Expand All @@ -173,6 +165,7 @@ class _HomePageState extends State<HomePage> {
write(1, TOP_SCORE);
}
SCORE++;
// print("Score : $SCORE, Best: $TOP_SCORE");
});
}
});
Expand Down
15 changes: 9 additions & 6 deletions lib/Layouts/Pages/page_leader_board.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, avoid_unnecessary_containers
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, avoid_unnecessary_containers, avoid_print

import 'package:flappy_bird/Constant/constant.dart';
import 'package:flappy_bird/Layouts/Pages/page_share_app.dart';
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';

import '../../Database/database.dart';

class LeaderBoard extends StatefulWidget {
const LeaderBoard({Key? key}) : super(key: key);

Expand All @@ -15,15 +17,16 @@ class LeaderBoard extends StatefulWidget {
class _LeaderBoardState extends State<LeaderBoard> {
@override
Widget build(BuildContext context) {
try {
TOP_SCORE = read(1);
}catch(error){
print('$error');
}
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/pics/background-day.png"),
fit: BoxFit.fill),
),
decoration: background(im),
child: Column(
children: [
Expanded(flex: 1, child: Container(
Expand Down
51 changes: 34 additions & 17 deletions lib/Layouts/Pages/page_settings.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// ignore_for_file: prefer_const_constructors, sized_box_for_whitespace
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, avoid_unnecessary_containers
import 'package:flappy_bird/Layouts/Pages/page_share_app.dart';
import 'package:flappy_bird/Database/database.dart';
import 'package:flappy_bird/Layouts/Pages/page_start_screen.dart';
import 'package:flutter/material.dart';
import '../../Constant/constant.dart';

class Settings extends StatefulWidget {
const Settings({Key? key}) : super(key: key);
Expand All @@ -16,11 +18,7 @@ class _SettingsState extends State<Settings> {
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/pics/background-day.png"),
fit: BoxFit.fill),
),
decoration: background(im),
child: Column(
children: [
Expanded(flex: 1, child: Container(
Expand Down Expand Up @@ -49,25 +47,40 @@ class _SettingsState extends State<Settings> {
child: Column(
children: [
Text("Setting",style: TextStyle(fontSize: 35,fontFamily: "Magic4")),
SizedBox(height: 50,),
SizedBox(height: 40,),
Center(child: Text("Characters",style: TextStyle(fontSize: 20,fontFamily: "Magic4")),),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Image.asset("assets/pics/bluebird.png",width: 63,height: 60,),
Image.asset("assets/pics/bluebird.png",width: 63,height: 60,),
Image.asset("assets/pics/redbird.png",width: 63,height: 60,),
GestureDetector(onTap: (){bird = "assets/pics/bird.png";},child: Container(width: 75,height: 75,child: Image.asset("assets/pics/bird.png",fit: BoxFit.cover,))),
GestureDetector(onTap: (){bird = "assets/pics/blue.png";},child: Container(width: 75,height: 75,child: Image.asset("assets/pics/blue.png",fit: BoxFit.cover,))),
GestureDetector(onTap: (){bird = "assets/pics/greenBird.png";},child: Container(width: 75,height: 75,child: Image.asset("assets/pics/greenBird.png",fit: BoxFit.cover,))),
],
),
Center(child: Text("Themes",style: TextStyle(fontSize: 20,fontFamily: "Magic4")),),
SizedBox(height: 20,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Image.asset("assets/pics/background-day.png",width: 73,height: 70,),
Image.asset("assets/pics/background-night.png",width: 73,height: 70,),
Image.asset("assets/pics/background-after-night.png",width: 63,height: 66,),
GestureDetector(onTap: (){setState(() {
setState(() {
im = "0";
background(im);
});
});},child: Image.asset("assets/pics/0.png",width: 73,height: 70,)),
GestureDetector(onTap: (){setState(() {
setState(() {
im = "1";
background(im);
});
});},child: Image.asset("assets/pics/1.png",width: 73,height: 70,)),
GestureDetector(onTap: (){
setState(() {
im = "2";
background(im);
});
},child: Image.asset("assets/pics/2.png",width: 63,height: 66,)),
],
),
SizedBox(height: 20,),
Expand All @@ -76,8 +89,12 @@ class _SettingsState extends State<Settings> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(Icons.music_note_rounded,size: 40,),
Icon(Icons.music_off_rounded,size: 40),
GestureDetector(onTap: (){
//TODO: play Music
},child: Icon(Icons.music_note_rounded,size: 40,)),
GestureDetector(onTap: (){
//TODO: play Music
},child: Icon(Icons.music_off_rounded,size: 40)),
],
),
SizedBox(height: 40,),
Expand All @@ -86,9 +103,9 @@ class _SettingsState extends State<Settings> {
primary: Colors.cyan.shade300,
),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => ShareApp(),),);
writeBackground(0, im);
Navigator.push(context, MaterialPageRoute(builder: (context) => StartScreen(),),);
}, child: Text("Apply",style: TextStyle(fontFamily: "Magic4",fontSize: 30),) ),

],
),
),
Expand Down
7 changes: 2 additions & 5 deletions lib/Layouts/Pages/page_start_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flappy_bird/Layouts/Pages/page_share_app.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_alert.dart';
import 'package:flappy_bird/Layouts/Widgets/widget_bird.dart';
import 'package:flutter/material.dart';
import '../../Database/database.dart';
import '../Widgets/widget_Button.dart';

class StartScreen extends StatefulWidget {
Expand All @@ -23,11 +24,7 @@ class _StartScreenState extends State<StartScreen> {
body: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/pics/background-day.png"),
fit: BoxFit.fill),
),
decoration: background(im),
child: Column(
children: [
Expanded(flex: 3,
Expand Down
16 changes: 2 additions & 14 deletions lib/Layouts/Widgets/widget_bird.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
// ignore_for_file: sized_box_for_whitespace, prefer_const_constructors, prefer_const_constructors_in_immutables, use_key_in_widget_constructors

import 'package:flappy_bird/Constant/constant.dart';
import 'package:flutter/material.dart';

import '../../constant/constant.dart';

class Bird extends StatelessWidget {
final double yAxis;
final double birdWidth;
final double birdHeight;

Bird(this.yAxis, this.birdWidth, this.birdHeight);
String setbird(){
if(c==Colors.yellow){
return"assets/pics/bird.png";
}
else if(c==Colors.blue){
return"assets/pics/bluebird.png";
}
else
return"assets/pics/redbird.png";
}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return AnimatedContainer(
alignment: Alignment(0, (2 * yAxis + birdHeight) / (2- birdHeight)),
duration: Duration(milliseconds: 0),
child: Image.asset(
setbird(),
child: Image.asset(bird,
width: size.width * birdWidth,
height: size.height * birdHeight,
fit: BoxFit.cover,
Expand Down
Loading

0 comments on commit 072de45

Please sign in to comment.