From f7de6972701ad715b2d6777a94eec114fd54aad8 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Sat, 4 Nov 2023 17:45:46 +0000 Subject: [PATCH] Step 5 --- App.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/App.js b/App.js index b9b6a99..7e67f10 100644 --- a/App.js +++ b/App.js @@ -44,6 +44,9 @@ const Game = () => { targetBorderWidth: TARGET_BORDER_WIDTH, }); + // Start with a score of 0 + const [score, setScore] = React.useState(0); + // Start with the ball in the center of the playable screen area const ballAnimation = useSharedValue(getCenterPosition()); @@ -98,6 +101,16 @@ const Game = () => { // And vibrate Haptics.notificationAsync(); + + // And update the score by 1 + setScore((score) => { + const newScore = score + 1; + + // Announce the updated score + Speech.speak(newScore.toString()); + + return newScore; + }); } }); @@ -108,6 +121,19 @@ const Game = () => { + + + Score: {score} + + setScore(0)} + style={({ pressed }) => ({ + opacity: pressed ? 0.5 : 1, + })} + > + Reset + + ); }; @@ -132,4 +158,12 @@ const styles = StyleSheet.create({ borderWidth: TARGET_BORDER_WIDTH, borderColor: "blue", }, + scoreContainer: { position: "absolute", bottom: 20, left: 20 }, + scoreText: { + fontSize: 40, + fontWeight: "bold", + }, + resetText: { + fontSize: 20, + }, });