@@ -8,6 +8,8 @@ let status = "ready";
88let challengeMode = false ;
99let timeRemaining = 60 ;
1010let timerInterval = null ;
11+ let hardCoreMode = false ;
12+ let collisions = 0 ;
1113
1214let walls = [ ] ;
1315let gates = [ ] ;
@@ -164,6 +166,14 @@ function ballRectCollision(b, rect) {
164166 const distSq = dx * dx + dy * dy ;
165167
166168 if ( distSq < b . radius * b . radius ) {
169+ collisions ++ ;
170+ if ( hardCoreMode && collisions % 50 == 0 ) {
171+ score -- ;
172+ document . getElementById ( "score" ) . textContent = score ;
173+ if ( score < 0 ) {
174+ showVictoryModal ( ) ;
175+ }
176+ }
167177 const dist = Math . sqrt ( distSq ) || 1 ;
168178 const overlap = b . radius - dist ;
169179
@@ -248,7 +258,20 @@ function showVictoryModal() {
248258 const title = document . getElementById ( "victoryTitle" ) ;
249259 const message = document . getElementById ( "victoryMessage" ) ;
250260
251- if ( challengeMode ) {
261+ if ( hardCoreMode ) {
262+
263+ if ( score <= 0 ) {
264+ title . textContent = "Better luck next time" ;
265+ message . textContent = `You had too many collisions! Tip: Do not let the ball remain idle` ;
266+ } else {
267+ const timeTaken = 60 - timeRemaining ;
268+ score += timeRemaining ;
269+ document . getElementById ( "score" ) . textContent = score ;
270+ title . textContent = "Impeccable Victory!" ;
271+ message . textContent = `You finished Hard Core mode in ${ timeTaken } seconds and ${ collisions } collisions with a final score of ${ score } !` ;
272+ }
273+
274+ } else if ( challengeMode ) {
252275 const timeTaken = 60 - timeRemaining ;
253276 title . textContent = "Challenge Complete!" ;
254277 score += timeRemaining ;
@@ -434,18 +457,32 @@ document.querySelectorAll(".gravity-btn").forEach((btn) => {
434457
435458window . addEventListener ( "resize" , resizeCanvas ) ;
436459
460+ const challengeCheckbox = document . getElementById ( "challengeMode" ) ;
461+ const hardCoreCheckbox = document . getElementById ( "hardCoreMode" ) ;
462+
463+ challengeCheckbox . addEventListener ( "change" , ( ) => {
464+ if ( challengeCheckbox . checked ) hardCoreCheckbox . checked = false ;
465+ } ) ;
466+
467+ hardCoreCheckbox . addEventListener ( "change" , ( ) => {
468+ if ( hardCoreCheckbox . checked ) challengeCheckbox . checked = false ;
469+ } ) ;
470+
437471document . getElementById ( "startBtn" ) . addEventListener ( "click" , ( ) => {
438- challengeMode = document . getElementById ( "challengeMode" ) . checked ;
472+ challengeMode = challengeCheckbox . checked ;
473+ hardCoreMode = hardCoreCheckbox . checked ;
439474 status = "playing" ;
475+
440476 document . getElementById ( "status" ) . textContent = "Playing" ;
441477 document . getElementById ( "startBtn" ) . style . display = "none" ;
442478
443- if ( challengeMode ) {
479+ if ( challengeMode || hardCoreMode ) {
444480 document . getElementById ( "timer" ) . classList . add ( "active" ) ;
445- startTimer ( ) ;
481+ startTimer ( ) ;
446482 }
447483} ) ;
448484
485+
449486function replay ( ) {
450487 document . getElementById ( "victoryModal" ) . classList . remove ( "show" ) ;
451488 resizeCanvas ( ) ;
@@ -459,7 +496,8 @@ function replay() {
459496 setGravity ( 0 , 0.5 , "down" ) ;
460497
461498 challengeMode = document . getElementById ( "challengeMode" ) . checked ;
462- if ( challengeMode ) {
499+ hardCoreMode = document . getElementById ( "hardCoreMode" ) . checked ;
500+ if ( challengeMode || hardCoreMode ) {
463501 document . getElementById ( "timer" ) . classList . add ( "active" ) ;
464502 startTimer ( ) ;
465503 } else {
@@ -487,7 +525,7 @@ canvas.addEventListener("dblclick", () => {
487525 ball . vy = 0 ;
488526 setGravity ( 0 , 0.5 , "down" ) ;
489527
490- if ( challengeMode ) {
528+ if ( challengeMode || hardCoreMode ) {
491529 startTimer ( ) ;
492530 }
493531} ) ;
0 commit comments