mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
When the cards are dealt at the start of a Klondike Step 5 game there are multiple occurrences of unrealistic behaviors: - Several cards being dealt may come from the middle of the Stock Pile, - Cards that are dealt early can be seen moving in front of cards that are dealt later. Each card dealt should be rendered on the top of the Stock Pile and should be seen to come from there. During the deal, later cards dealt are placed on top of earlier ones, so later cards should be seen to move in front of earlier ones when they are travelling from the Stock Pile to their positions in the layout. Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
This commit is contained in:
@ -359,20 +359,18 @@ class Card extends PositionComponent
|
|||||||
Vector2 to, {
|
Vector2 to, {
|
||||||
double speed = 10.0,
|
double speed = 10.0,
|
||||||
double start = 0.0,
|
double start = 0.0,
|
||||||
|
int startPriority = 100,
|
||||||
Curve curve = Curves.easeOutQuad,
|
Curve curve = Curves.easeOutQuad,
|
||||||
VoidCallback? onComplete,
|
VoidCallback? onComplete,
|
||||||
bool bumpPriority = true,
|
|
||||||
}) {
|
}) {
|
||||||
assert(speed > 0.0, 'Speed must be > 0 widths per second');
|
assert(speed > 0.0, 'Speed must be > 0 widths per second');
|
||||||
final dt = (to - position).length / (speed * size.x);
|
final dt = (to - position).length / (speed * size.x);
|
||||||
assert(dt > 0, 'Distance to move must be > 0');
|
assert(dt > 0, 'Distance to move must be > 0');
|
||||||
if (bumpPriority) {
|
|
||||||
priority = 100;
|
|
||||||
}
|
|
||||||
add(
|
add(
|
||||||
MoveToEffect(
|
CardMoveEffect(
|
||||||
to,
|
to,
|
||||||
EffectController(duration: dt, startDelay: start, curve: curve),
|
EffectController(duration: dt, startDelay: start, curve: curve),
|
||||||
|
transitPriority: startPriority,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
onComplete?.call();
|
onComplete?.call();
|
||||||
},
|
},
|
||||||
@ -443,3 +441,20 @@ class Card extends PositionComponent
|
|||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CardMoveEffect extends MoveToEffect {
|
||||||
|
CardMoveEffect(
|
||||||
|
super.destination,
|
||||||
|
super.controller, {
|
||||||
|
super.onComplete,
|
||||||
|
this.transitPriority = 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
final int transitPriority;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onStart() {
|
||||||
|
super.onStart(); // Flame connects MoveToEffect to EffectController.
|
||||||
|
parent?.priority = transitPriority;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class TableauPile extends PositionComponent implements Pile {
|
|||||||
_cards.add(card);
|
_cards.add(card);
|
||||||
card.doMove(
|
card.doMove(
|
||||||
nextPosition,
|
nextPosition,
|
||||||
bumpPriority: false, // Priorities have been set: don't change them.
|
startPriority: card.priority,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
nCardsToMove--;
|
nCardsToMove--;
|
||||||
if (nCardsToMove == 0) {
|
if (nCardsToMove == 0) {
|
||||||
|
|||||||
@ -114,6 +114,13 @@ class KlondikeWorld extends World with HasGameReference<KlondikeGame> {
|
|||||||
// For the "Same deal" option, re-use the previous seed, else use a new one.
|
// For the "Same deal" option, re-use the previous seed, else use a new one.
|
||||||
cards.shuffle(Random(game.seed));
|
cards.shuffle(Random(game.seed));
|
||||||
|
|
||||||
|
// Each card dealt must be seen to come from the top of the deck!
|
||||||
|
var dealPriority = 1;
|
||||||
|
for (final card in cards) {
|
||||||
|
card.priority = dealPriority++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change priority as cards take off: so later cards fly above earlier ones.
|
||||||
var cardToDeal = cards.length - 1;
|
var cardToDeal = cards.length - 1;
|
||||||
var nMovingCards = 0;
|
var nMovingCards = 0;
|
||||||
for (var i = 0; i < 7; i++) {
|
for (var i = 0; i < 7; i++) {
|
||||||
@ -121,7 +128,9 @@ class KlondikeWorld extends World with HasGameReference<KlondikeGame> {
|
|||||||
final card = cards[cardToDeal--];
|
final card = cards[cardToDeal--];
|
||||||
card.doMove(
|
card.doMove(
|
||||||
tableauPiles[j].position,
|
tableauPiles[j].position,
|
||||||
|
speed: 15.0,
|
||||||
start: nMovingCards * 0.15,
|
start: nMovingCards * 0.15,
|
||||||
|
startPriority: 100 + nMovingCards,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
tableauPiles[j].acquireCard(card);
|
tableauPiles[j].acquireCard(card);
|
||||||
nMovingCards--;
|
nMovingCards--;
|
||||||
|
|||||||
Reference in New Issue
Block a user