From 9c9865f1497b0babdeca591a17c7a138d7d9ffac Mon Sep 17 00:00:00 2001 From: Yewon Date: Sun, 18 May 2025 23:20:32 +0900 Subject: [PATCH] Editing initTargets function - unsubscribe&resubscribe --- src/main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 621e8ae..8170479 100644 --- a/src/main.js +++ b/src/main.js @@ -54,9 +54,9 @@ function keyPressed() { // reset score and targets gun.remainingShots = TOT_SHOTS; score.shotLeft = TOT_SHOTS; - score.score = 0; + initTargets(); } } @@ -65,8 +65,14 @@ function initTargets() { // Create new targets from the factory // Remember to unsubscribe the previous targets and to subscribe the new ones const factory = TargetFactory.getInstance(); + gun.unsubscribeAll(); targets = factory.getRandomTargets(MAX_TARGETS, TARGET_WIDTH, 200); + gun.subscribe(score); + for (let target of targets) { + gun.subscribe(target); + target.subscribe(score); + } } // Do not touch these