Skip to content

Instantly share code, notes, and snippets.

@AlabasterAxe
Created November 10, 2020 00:15
Show Gist options
  • Save AlabasterAxe/57ef60773a92c84dd8d03d19e5431a70 to your computer and use it in GitHub Desktop.
Save AlabasterAxe/57ef60773a92c84dd8d03d19e5431a70 to your computer and use it in GitHub Desktop.
Implementation of the ground for Flutter Dino Game
Sprite groundSprite = Sprite()
..imagePath = "assets/images/ground.png"
..imageWidth = 2399
..imageHeight = 24;
class Ground extends GameObject {
// this is a logical location which is translated to pixel coordinates
final Offset location;
Ground({this.location});
@override
Rect getRect(Size screenSize, double runDistance) {
return Rect.fromLTWH(
(location.dx - runDistance) 10,
4 / 7 screenSize.height - groundSprite.imageHeight - location.dy,
groundSprite.imageWidth.toDouble(),
groundSprite.imageHeight.toDouble());
}
@override
Widget render() {
return Image.asset(
groundSprite.imagePath,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment