mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
Update min Dart constraint to 3.8, which will enable us to use the fancier collection literals. This requires bumping the min Flutter version as well: <img width="1892" height="1122" alt="image" src="https://github.com/user-attachments/assets/7c7b07fc-4d96-4987-824d-9a7133ecfb85" />
67 lines
1.8 KiB
Dart
67 lines
1.8 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/flame.dart';
|
|
import 'package:flame/game.dart';
|
|
|
|
import 'components/foundation.dart';
|
|
import 'components/pile.dart';
|
|
import 'components/stock.dart';
|
|
import 'components/waste.dart';
|
|
|
|
class KlondikeGame extends FlameGame {
|
|
static const double cardGap = 175.0;
|
|
static const double cardWidth = 1000.0;
|
|
static const double cardHeight = 1400.0;
|
|
static const double cardRadius = 100.0;
|
|
static final Vector2 cardSize = Vector2(cardWidth, cardHeight);
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await Flame.images.load('klondike-sprites.png');
|
|
|
|
final stock = Stock()
|
|
..size = cardSize
|
|
..position = Vector2(cardGap, cardGap);
|
|
final waste = Waste()
|
|
..size = cardSize
|
|
..position = Vector2(cardWidth + 2 * cardGap, cardGap);
|
|
final foundations = List.generate(
|
|
4,
|
|
(i) => Foundation()
|
|
..size = cardSize
|
|
..position = Vector2(
|
|
(i + 3) * (cardWidth + cardGap) + cardGap,
|
|
cardGap,
|
|
),
|
|
);
|
|
final piles = List.generate(
|
|
7,
|
|
(i) => Pile()
|
|
..size = cardSize
|
|
..position = Vector2(
|
|
cardGap + i * (cardWidth + cardGap),
|
|
cardHeight + 2 * cardGap,
|
|
),
|
|
);
|
|
|
|
world.add(stock);
|
|
world.add(waste);
|
|
world.addAll(foundations);
|
|
world.addAll(piles);
|
|
|
|
camera.viewfinder.visibleGameSize = Vector2(
|
|
cardWidth * 7 + cardGap * 8,
|
|
4 * cardHeight + 3 * cardGap,
|
|
);
|
|
camera.viewfinder.position = Vector2(cardWidth * 3.5 + cardGap * 4, 0);
|
|
camera.viewfinder.anchor = Anchor.topCenter;
|
|
}
|
|
}
|
|
|
|
Sprite klondikeSprite(double x, double y, double width, double height) {
|
|
return Sprite(
|
|
Flame.images.fromCache('klondike-sprites.png'),
|
|
srcPosition: Vector2(x, y),
|
|
srcSize: Vector2(width, height),
|
|
);
|
|
}
|