This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void jump() { | |
| if (state != DinoState.jumping) { | |
| velY = 650; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum DinoState { | |
| running, | |
| jumping, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text(widget.title), | |
| ), | |
| body: GestureDetector( | |
| behavior: HitTestBehavior.translucent, | |
| onTap: () { | |
| dino.jump(); | |
| }, | |
| child: Stack( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void jump() { | |
| velY = 650; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @override | |
| void update(Duration lastTime, Duration elapsedTime) { | |
| double elapsedSeconds = | |
| ((elapsedTime.inMilliseconds - lastTime.inMilliseconds) / 1000); | |
| dispY += velY * elapsedSeconds; | |
| if (dispY <= 0) { | |
| dispY = 0; | |
| velY = 0; | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @override | |
| Rect getRect(Size screenSize, double _) { | |
| return Rect.fromLTWH( | |
| screenSize.width / 10, | |
| 4 / 7 * screenSize.height - dino.imageHeight - dispY, | |
| dino.imageWidth.toDouble(), | |
| dino.imageHeight.toDouble()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text(widget.title), | |
| ), | |
| body: Stack( | |
| alignment: Alignment.center, | |
| children: [ | |
| AnimatedBuilder( | |
| animation: worldController, | |
| builder: (context, child) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @override | |
| void initState() { | |
| super.initState(); | |
| worldController = | |
| AnimationController(vsync: this, duration: Duration(days: 99)); | |
| worldController.addListener(_update); | |
| worldController.forward(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Dino extends GameObject { | |
| int frame = 1; | |
| @override | |
| Widget render() { | |
| return Image.asset( | |
| "assets/images/dino/dino_$frame.png", | |
| gaplessPlayback: true, | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Duration lastUpdateCall = Duration(); | |
| @override | |
| void initState() { | |
| super.initState(); | |
| worldController = | |
| AnimationController(vsync: this, duration: Duration(days: 99)); | |
| worldController.addListener(_update); | |
| } |