Skip to content

Commit

Permalink
optimize block remove animation
Browse files Browse the repository at this point in the history
  • Loading branch information
canalun committed Feb 17, 2024
1 parent b1cb998 commit 7c5f644
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/game/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getBlockElements } from "./getBlockElements"

// A block is "remained" until the ball hits it,
// and then it's "removed" when remove animation is done.
export type Block = {
uuid: string
element: Element
Expand All @@ -10,6 +12,7 @@ export type Block = {
right: number
}
remain: boolean
removed: boolean
}

export function getBlocks(): Block[] {
Expand All @@ -23,7 +26,8 @@ function convertElementToBlock(element: Element): Block {
uuid: Math.random().toString(36).slice(-8),
element,
rect: getRectOfBlock(element),
remain: true
remain: true,
removed: false
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/game/updateBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function startBlockAndScoreUpdate(
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i]
if (!block.remain) {
removeBlockAndUpdateBlocksPosition(block, blocks)
!block.removed && removeBlockAndUpdateBlocksPosition(block, blocks)
scoreboard && score++
}
}
Expand Down Expand Up @@ -56,6 +56,8 @@ function removeBlockAndUpdateBlocksPosition(block: Block, blocks: Block[]) {
}

function removeBlock(block: Block) {
block.removed = true

const element = block.element

if (isFrameElement(element)) {
Expand Down

0 comments on commit 7c5f644

Please sign in to comment.