Skip to content

Commit

Permalink
Add win animation
Browse files Browse the repository at this point in the history
This adds a fairly simple win animation that 'blows up' stacks of cards
towards the center of the table. Single cards are grouped with other
stacks or single cards and cards removed from the table are push to the
table from the bottom.

If the device is rotated the animation will be stopped and generated
again. Similarly going back and redoing the winning move will make the
animation to start over from scratch. If page is not active, the
animation is paused.

Normal distribution is used for angle and chi-squared distribution for
radius. Parameters were experimentally figured out to give the best
general result.

Animations use game seed to generate random numbers. This way animations
are deterministic. They may still vary from device to device and from
version to version. Engine is in another thread but it should be safe to
get a copy of the seed.

Signed-off-by: Tomi Leppänen <tomi@tomin.site>
  • Loading branch information
Tomin1 committed May 1, 2023
1 parent b6c18f9 commit a4fd95b
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 6 deletions.
33 changes: 31 additions & 2 deletions qml/pages/Game.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,22 @@ Page {
message.hint = ""
}

onOrientationChanged: message.x = 0
function pauseOrResumeAnimation(pause) {
if (table.animationPlaying) {
table.animationPaused = pause
}
}

onOrientationChanged: {
message.x = 0
if (Patience.state === Patience.WonState) {
if (table.animationPlaying) {
table.animateAfterOrientationChange = true
} else {
table.playWinAnimation()
}
}
}

onActiveChanged: {
Patience.paused = !active
Expand All @@ -49,15 +64,18 @@ Page {
Patience.startNewGame()
needsGameStart = false
}
pauseOrResumeAnimation(!active)
}

Connections {
target: Qt.application
onStateChanged: {
if (Qt.application.state === Qt.ApplicationActive) {
Patience.paused = !page.active
pauseOrResumeAnimation(!page.active)
} else {
Patience.paused = true
pauseOrResumeAnimation(true)
}
resetHint()
}
Expand Down Expand Up @@ -152,6 +170,8 @@ Page {
Table {
id: table

property bool animateAfterOrientationChange

enabled: Patience.state < Patience.GameOverState && !Patience.engineFailed && !toolbar.magnify

height: Screen.height - toolbar.totalSpaceY - messageBar.height
Expand All @@ -170,7 +190,14 @@ Page {
transform: Scale { id: magnifyTransform }
doubleResolution: magnifyArea.pressed || animateShrink.running || animateGrow.running

layer.enabled: pullDownMenu.active
onAnimationPlayingChanged: {
if (!animationPlaying && animateAfterOrientationChange) {
playWinAnimation()
animateAfterOrientationChange = false
}
}

layer.enabled: pullDownMenu.active || (overlayLoader.active && !animationPlaying)

FeedbackEvent.onClicked: feedback.playEffect()
FeedbackEvent.onDropSucceeded: feedback.playEffect()
Expand Down Expand Up @@ -307,6 +334,8 @@ Page {
}
} else if (Patience.state === Patience.StartingState) {
resetHint()
} else if (Patience.state === Patience.WonState) {
table.playWinAnimation()
}
}
onHint: {
Expand Down
1 change: 1 addition & 0 deletions src/manager/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ bool Manager::handleQueued(const Action &action) {
void Manager::handleClearData()
{
m_preparing = true;
m_table->stopAnimation();
for (Slot *slot : *m_table) {
for (Card *card : slot->takeAll()) {
if (card) {
Expand Down
Loading

0 comments on commit a4fd95b

Please sign in to comment.