From 69ced394965ac98893c4cc25093b43e58a3b0b03 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 23 Jan 2022 19:41:49 +0800 Subject: [PATCH] add animations --- src/Game.vue | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/Game.vue b/src/Game.vue index 8dc3f80..7d0ab7b 100644 --- a/src/Game.vue +++ b/src/Game.vue @@ -21,6 +21,7 @@ const board = $ref( let message = $ref('') let allowInput = true let currentRowIndex = $ref(0) +let shakeRowIndex = $ref(-1) const currentRow = $computed(() => board[currentRowIndex]) // keep track of revealed letter state for the keyboard @@ -68,6 +69,7 @@ function completeRow() { if (currentRow.every((tile) => tile.letter)) { const word = currentRow.map((tile) => tile.letter).join('') if (!allWords.includes(word) && word !== answer) { + shake() showMessage(`Not in word list`) return } @@ -106,6 +108,7 @@ function completeRow() { showMessage(answer.toUpperCase()) } } else { + shake() showMessage('Not enough letters') } } @@ -116,6 +119,13 @@ function showMessage(msg: string) { message = '' }, 1000) } + +function shake() { + shakeRowIndex = currentRowIndex + setTimeout(() => { + shakeRowIndex = -1 + }, 1000) +}