Pong Game Hacks
Breadcrumb: /blogsMy submission for pong game hacks
Link to game
https://whitelunarium.github.io/Aneesh_2026/pong
Changes:
- Added time limit to the game - Tanay
- We introduced a
timeLimit
(60 seconds) and atimer
variable to keep track of remaining time.
- We introduced a
-
Created an
updateTimer()
function that runs every second usingsetInterval()
. -
When the timer hits 0, it ends the game by setting
gameOver = true
.
%%js
let timeLimit = 60;
let timer = timeLimit;
let timerInterval;
function updateTimer() {
if (timer > 0) {
timer--;
} else {
clearInterval(timerInterval);
gameOver = true;
restartBtn.style.display = "inline-block";
}
}
- Added restart function after time limit ends - Aneesh
- Added a Restart button in HTML (
<button id="restartBtn">
). - When the game ends (either timer ends or someone wins), the button becomes visible.
- Clicking it resets scores, timer, paddle sizes, and game state, then starts the game again.
- Added a Restart button in HTML (
%%js
restartBtn.addEventListener("click", () => {
player1Score = 0;
player2Score = 0;
paddleHeight = 100;
timer = timeLimit;
gameOver = false;
restartBtn.style.display = "none";
clearInterval(timerInterval);
timerInterval = setInterval(updateTimer, 1000);
initBall();
});
- Added function where paddle size decreases when ball touches the paddle - Moiz
- Inside the ball collision check with paddles, we made the paddle shrink by 2 pixels each time the ball touches it.
- Also ensured it never goes below a minimum height (
minPaddleHeight = 40
).
##js
if (paddleHeight > minPaddleHeight) {
paddleHeight -= 2;
}