The game works — now make it feel good. First, make a short blip in the Sound tab (slot 0). Then we’ll play it on each hit, speed the ball up a little so long rallies get tense, remember your best score, and let you play again.
Add a best variable at the top:
let best = 0;Upgrade the paddle hit. Replace your paddle-hit block with this one:
if (bx < 10 && by > paddleY && by < paddleY + PH && bdx < 0) {
bdx = -bdx * 1.05; // bounce AND speed up 5%
hits = hits + 1;
if (hits > best) {
best = hits; // new high score!
}
sfx(0);
}Let space start a new game after you lose. Replace the if (lives <= 0) { return; } at the top of update() with:
if (lives <= 0) {
if (keyp(' ')) {
lives = 3;
hits = 0;
serve();
}
return;
}And show your best score plus a restart hint. Add print('Best: ' + best, 4, 14, 6); near the top of draw(), and add a second line to the game-over message:
if (lives <= 0) {
print('GAME OVER', 36, 56, 8);
print('space to play again', 18, 70, 7);
}best only changes when hits > best, and nothing ever resets it — so it survives across games as your high score, even when a new game zeroes hits.
That’s the finished game — save and play:
let paddleY = 54;
const PH = 20;
let bx = 64;
let by = 64;
let bdx = 1.5;
let bdy = 1;
let hits = 0;
let best = 0;
let lives = 3;
function serve() {
bx = 64;
by = 64;
bdx = 1.5;
bdy = rnd(2) - 1;
}
function update() {
if (lives <= 0) {
if (keyp(' ')) {
lives = 3;
hits = 0;
serve();
}
return;
}
if (key('ArrowUp')) {
paddleY -= 2;
}
if (key('ArrowDown')) {
paddleY += 2;
}
paddleY = mid(0, paddleY, 128 - PH);
bx += bdx;
by += bdy;
if (by < 2 || by > 125) {
bdy = -bdy;
}
if (bx > 122) {
bdx = -bdx;
}
if (bx < 10 && by > paddleY && by < paddleY + PH && bdx < 0) {
bdx = -bdx * 1.05;
hits = hits + 1;
if (hits > best) {
best = hits;
}
sfx(0);
}
if (bx < 0) {
lives = lives - 1;
serve();
}
}
function draw() {
cls(0);
rectfill(124, 0, 127, 127, 6);
print('Hits: ' + hits, 4, 4, 7);
print('Best: ' + best, 4, 14, 6);
print('Lives: ' + lives, 78, 4, 8);
rectfill(6, paddleY, 8, paddleY + PH, 7);
circfill(bx, by, 2, 7);
if (lives <= 0) {
print('GAME OVER', 36, 56, 8);
print('space to play again', 18, 70, 7);
}
}You built Wall Ball!
Every piece came from an earlier lesson — variables, keyboard input, motion and bouncing, booleans and conditions, functions, and sound. That’s how bigger games get made: small, familiar parts stacked one step at a time.
- Make it yours: a taller paddle (change
PH), a second ball, or points that count double after 10 hits. - Grab the finished project with the download link on the overview, then tweak it in the editor.