@@ -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
@@ -244,13 +254,30 @@ function showVictoryModal() {
244254 timerInterval = null ;
245255 }
246256
257+ collisions = 0 ;
258+
247259 const modal = document . getElementById ( "victoryModal" ) ;
248260 const title = document . getElementById ( "victoryTitle" ) ;
249261 const message = document . getElementById ( "victoryMessage" ) ;
250262
251- if ( challengeMode ) {
263+ if ( hardCoreMode ) {
264+
265+ if ( score <= 0 ) {
266+ title . textContent = "Better luck next time" ;
267+ message . textContent = `You had too many collisions! Tip: Do not let the ball remain idle` ;
268+ } else {
269+ const timeTaken = 60 - timeRemaining ;
270+ score += timeRemaining ;
271+ document . getElementById ( "score" ) . textContent = score ;
272+ title . textContent = "Impeccable Victory!" ;
273+ message . textContent = `You finished Hard Core mode in ${ timeTaken } seconds and ${ collisions } collisions with a final score of ${ score } !` ;
274+ }
275+
276+ } else if ( challengeMode ) {
252277 const timeTaken = 60 - timeRemaining ;
253278 title . textContent = "Challenge Complete!" ;
279+ score += timeRemaining ;
280+ document . getElementById ( "score" ) . textContent = score ;
254281 message . textContent = `You finished in ${ timeTaken } seconds with a score of ${ score } !` ;
255282 } else {
256283 title . textContent = "Victory!" ;
@@ -432,18 +459,32 @@ document.querySelectorAll(".gravity-btn").forEach((btn) => {
432459
433460window . addEventListener ( "resize" , resizeCanvas ) ;
434461
462+ const challengeCheckbox = document . getElementById ( "challengeMode" ) ;
463+ const hardCoreCheckbox = document . getElementById ( "hardCoreMode" ) ;
464+
465+ challengeCheckbox . addEventListener ( "change" , ( ) => {
466+ if ( challengeCheckbox . checked ) hardCoreCheckbox . checked = false ;
467+ } ) ;
468+
469+ hardCoreCheckbox . addEventListener ( "change" , ( ) => {
470+ if ( hardCoreCheckbox . checked ) challengeCheckbox . checked = false ;
471+ } ) ;
472+
435473document . getElementById ( "startBtn" ) . addEventListener ( "click" , ( ) => {
436- challengeMode = document . getElementById ( "challengeMode" ) . checked ;
474+ challengeMode = challengeCheckbox . checked ;
475+ hardCoreMode = hardCoreCheckbox . checked ;
437476 status = "playing" ;
477+
438478 document . getElementById ( "status" ) . textContent = "Playing" ;
439479 document . getElementById ( "startBtn" ) . style . display = "none" ;
440480
441- if ( challengeMode ) {
481+ if ( challengeMode || hardCoreMode ) {
442482 document . getElementById ( "timer" ) . classList . add ( "active" ) ;
443- startTimer ( ) ;
483+ startTimer ( ) ;
444484 }
445485} ) ;
446486
487+
447488function replay ( ) {
448489 document . getElementById ( "victoryModal" ) . classList . remove ( "show" ) ;
449490 resizeCanvas ( ) ;
@@ -457,7 +498,8 @@ function replay() {
457498 setGravity ( 0 , 0.5 , "down" ) ;
458499
459500 challengeMode = document . getElementById ( "challengeMode" ) . checked ;
460- if ( challengeMode ) {
501+ hardCoreMode = document . getElementById ( "hardCoreMode" ) . checked ;
502+ if ( challengeMode || hardCoreMode ) {
461503 document . getElementById ( "timer" ) . classList . add ( "active" ) ;
462504 startTimer ( ) ;
463505 } else {
@@ -485,7 +527,7 @@ canvas.addEventListener("dblclick", () => {
485527 ball . vy = 0 ;
486528 setGravity ( 0 , 0.5 , "down" ) ;
487529
488- if ( challengeMode ) {
530+ if ( challengeMode || hardCoreMode ) {
489531 startTimer ( ) ;
490532 }
491533} ) ;
0 commit comments