-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84fbe88
commit 01c4e2f
Showing
16 changed files
with
656 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from "react"; | ||
import { animated, useSpring } from "react-spring"; | ||
import styles from "../styles/game-over.module.scss"; | ||
|
||
interface Props { | ||
resetGame: () => void; | ||
score: number; | ||
} | ||
|
||
export default function GameOver(props: Props) { | ||
const { resetGame, score } = props; | ||
|
||
const highscore = Number(localStorage.getItem("highscore") ?? "0"); | ||
|
||
React.useLayoutEffect(() => { | ||
if (score > highscore) { | ||
localStorage.setItem("highscore", String(score)); | ||
} | ||
}, [score, highscore]); | ||
|
||
const animProps = useSpring({ | ||
opacity: 1, | ||
from: { opacity: 0 }, | ||
config: { duration: 500 }, | ||
}); | ||
|
||
return ( | ||
<animated.div style={animProps} className={styles.gameOver}> | ||
<span className={styles.score}>Score: {score}</span> | ||
{highscore !== 0 && ( | ||
<span className={styles.highscore}>High Score: {highscore}</span> | ||
)} | ||
<button onClick={resetGame} className={styles.resetGame}> | ||
Play again | ||
</button> | ||
</animated.div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useSpring, animated } from "react-spring"; | ||
import React from "react"; | ||
import styles from "../styles/hearts.module.scss"; | ||
|
||
interface HeartProps { | ||
have: boolean; | ||
} | ||
|
||
function Heart(props: HeartProps) { | ||
const { have } = props; | ||
const { opacity } = useSpring({ | ||
opacity: have ? 1 : 0.2, | ||
config: { duration: 300 }, | ||
}); | ||
const { scale } = useSpring({ | ||
scale: have ? 1 : 0.8, | ||
config: { mass: 1, tension: 200, friction: 20, duration: 300 }, | ||
delay: 200, | ||
}); | ||
|
||
return ( | ||
<animated.img | ||
className={`${styles.heart} ${styles.used}`} | ||
style={{ opacity, scale }} | ||
src="/images/heart.svg" | ||
/> | ||
); | ||
} | ||
|
||
interface Props { | ||
lives: number; | ||
} | ||
|
||
export default function Hearts(props: Props) { | ||
const { lives } = props; | ||
|
||
return ( | ||
<div className={styles.hearts}> | ||
<Heart have={lives >= 1} /> | ||
<Heart have={lives >= 2} /> | ||
<Heart have={lives >= 3} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.