mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
The objective of this fix is to make a tap on a card more positive-feeling for the player and not to disappear silently if it is interpreted as a drag. It adds a Base Card to make an empty Stock Pile behave as a Card and use the tap and drag logic of the `Card` class. Any attempted drag on a Stock Pile card, including the Base Card, is now changed to a tap in onTapCancel() and the drag is not followed. The Base Card is rendered in outline only and does *not* take part in gameplay. In other Piles a short drag is either treated as a tap or ignored. Only the Waste and Tableau Piles allow such taps. As before in Klondike Step5, they result in the tapped card moving automatically to its Foundation Pile if it is eligible to "go out". As before in Klondike Step4 and Step5, all piles except the Stock Pile allow drags to start on them and they can finish on a Foundation Pile or a Tableau Pile. Closes #2890. When testing, try sliding the finger or mouse slightly while making a tap. --------- Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
50 lines
1.7 KiB
Dart
50 lines
1.7 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame/flame.dart';
|
|
import 'package:flame/game.dart';
|
|
|
|
import 'klondike_world.dart';
|
|
|
|
enum Action { newDeal, sameDeal, changeDraw, haveFun }
|
|
|
|
class KlondikeGame extends FlameGame<KlondikeWorld> {
|
|
static const double cardGap = 175.0;
|
|
static const double topGap = 500.0;
|
|
static const double cardWidth = 1000.0;
|
|
static const double cardHeight = 1400.0;
|
|
static const double cardRadius = 100.0;
|
|
static const double cardSpaceWidth = cardWidth + cardGap;
|
|
static const double cardSpaceHeight = cardHeight + cardGap;
|
|
static final Vector2 cardSize = Vector2(cardWidth, cardHeight);
|
|
static final cardRRect = RRect.fromRectAndRadius(
|
|
const Rect.fromLTWH(0, 0, cardWidth, cardHeight),
|
|
const Radius.circular(cardRadius),
|
|
);
|
|
|
|
/// Constant used to decide when a short drag is treated as a TapUp event.
|
|
static const double dragTolerance = cardWidth / 5;
|
|
|
|
/// Constant used when creating Random seed.
|
|
static const int maxInt = 0xFFFFFFFE; // = (2 to the power 32) - 1
|
|
|
|
// This KlondikeGame constructor also initiates the first KlondikeWorld.
|
|
KlondikeGame() : super(world: KlondikeWorld());
|
|
|
|
// These three values persist between games and are starting conditions
|
|
// for the next game to be played in KlondikeWorld. The actual seed is
|
|
// computed in KlondikeWorld but is held here in case the player chooses
|
|
// to replay a game by selecting Action.sameDeal.
|
|
int klondikeDraw = 1;
|
|
int seed = 1;
|
|
Action action = Action.newDeal;
|
|
}
|
|
|
|
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),
|
|
);
|
|
}
|