homepage.dart
static double birdY = 0;
double initialPos = birdY;
double height = 0;
double time = 0;
double gravity = -4.9; // how strong the gravity is
double velocity = 3.5; // how strong the jump is
double birdWidth = 0.1; // out of 2, 2 being the entire width of the screen
double birdHeight = 0.1; /
barrier.dart
class MyBarrier extends StatelessWidget {
final size;
MyBarrier({this.size});
@override
Widget build(BuildContext context) {
return Container(
width: 100,
height: size,
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(width: 10, color: Colors.greenAccent),
borderRadius: BorderRadius.circular(15)
));
}
}
homepage.dart
AnimatedContainer(
duration: Duration(milliseconds: 0),
alignment: Alignment(barrierXone, 1.1),
child: MyBarrier(
size: 200.0,
),
),
AnimatedContainer(
duration: Duration(milliseconds: 0),
alignment: Alignment(barrierXone, -1.1),
child: MyBarrier(
size: 200.0,
),
),
AnimatedContainer(
duration: Duration(milliseconds: 0),
alignment: Alignment(barrierXtwo, 1.1),
child: MyBarrier(
size: 150.0,
),
),
AnimatedContainer(
duration: Duration(milliseconds: 0),
alignment: Alignment(barrierXtwo, -1.1),
child: MyBarrier(
size: 250.0,
),
),
homepage.dart
bool birdIsDead() {
if (birdY < -1 || birdY > 1) {
return true;
}
homepage.dart
// check if bird is dead
if (birdIsDead()) {
timer.cancel();
gameHasStarted = false;
_showDialog();
}
중력과 가속도를 설정해주어 새가 정교하게 움직일 수 있게하고, Y축으로 움직이는새가 -1,1에 만났을 경우 게임이 종료된다. 방벽은 4개로 구현하고, X축을 barrierXone으로 설정해주어 방벽이 움직이게 한다.