diff --git a/handtris/src/components/TetrisPlay.tsx b/handtris/src/components/TetrisPlay.tsx index cb8c8aa..fb270bd 100644 --- a/handtris/src/components/TetrisPlay.tsx +++ b/handtris/src/components/TetrisPlay.tsx @@ -69,6 +69,15 @@ const Home: React.FC = () => { const [isFlipping, setIsFlipping] = useState(false); const [isNextBlockDonut, setIsNextBlockDonut] = useState(false); const [showDonutWarning, setShowDonutWarning] = useState(false); + const [animationState, setAnimationState] = useState({ + opacity: 1, + y: 0, + }); + const [donutAttackToggle, setDonutAttackToggle] = useState( + tetrisGameRef.current?.isDonutAttackToggleOn + ? "/image/DropPressed.png" + : "/image/DropDefault.png", + ); const fetchRoomPlayers = useCallback(async () => { setIsLoading(true); try { @@ -911,6 +920,27 @@ const Home: React.FC = () => { } }); + useEffect(() => { + let timeoutId; + if ( + !tetrisGameRef.current?.isDonutAttackToggleOn && + tetrisGameRef.current?.linesCleared > 0 + ) { + setAnimationState({ opacity: 0, y: -500 }); + + // Change the image after 1 second if `isDonutAttackToggleOn` is false + timeoutId = setTimeout(() => { + setAnimationState({ opacity: 1, y: 0 }); + setDonutAttackToggle("/image/DropDefault.png"); + }, 1000); + } else if (tetrisGameRef.current?.linesCleared > 0) { + setAnimationState({ opacity: 1, y: 0 }); + setDonutAttackToggle("/image/DropPressed.png"); + } + + return () => clearTimeout(timeoutId); + }, [tetrisGameRef.current?.isDonutAttackToggleOn]); + const toggleShowFirstAttack = useCallback(() => { setShowFirstAttack(true); setTimeout(() => setShowFirstAttack(false), 500); @@ -1005,122 +1035,185 @@ const Home: React.FC = () => {