ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî >ë:ðÿðÿÿðÿðÿÿÿÿðÿðÿÿÿðÿÿðÿÿÿÿÿÿÿÿÿÿðÿÿÿÿðÿÿÿÿðÿÿðÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿðÿðÿÿÿÿÿÿÿÿðÿÿÿÿÿÿðÿÿÿÿÿðÿÿÿÿðÿðÿÿÿÿÿÿðððððÿðÿðÿðÿðððÿðÿðÿÿðððÿÿðÿððÿÿÿÿÿððððÿðÿðÿðÿðððÿðÿðÿÿðððÿÿðÿðÿÿÿÿÿðÿðÿðÿðÿðÿðÿÿÿÿÿÿðÿÿðÿðÿÿÿððÿÿÿÿÿððÿÿÿÿÿÿÿÿÿÿÀ ÌÌÀ Ì ÌÌÌÌÀ À ÀÀÌÌÌÌÌÌÌ ÀÌ ÀÌÀ ÀÀ ÀÀÌ ÌÌÌ ÀÌ À Ì ÌÌÀÌÌÌ ÌÌÀÌ ÀÌÀ ÀÀ ÀÀ ÌÌÀÌ ÌÌÀÌÌÀÌÀÌÀ ÌÀ ÀÀÌÀ À ÀÀ ÀÀÌÀ ÀÀ ÀÀ À ÌÀÌÌÀ ÌÀÌÀ ÀÀÌÀÌÌÀ ÀÀÌÌÀÌÀ ÀÀÌÀÀÀÀÌÀÌÀÌÀ ÀÌÌÀ ÀÀ ÀÀ ÀÌÀ ÀÀ À À ÀÌÀÌÌÀÌÀÌÀ ÀÌÌÀ ÀÀ ÀÀÀÀÀÌÀ ÀÀÌÀ ÀÀÌÌÌÌÌ ÀÌ ÌÌ Ì À ÀÌ Ì À À À Ì ÀÌ ÀÌÌ ÌÌÀÌ ÌÀ ÀÌ ÀÀÀÌÌÀ ÀÀÌ À Ì Ì -- title: Pong - Made by Cursor. Tested by Humans. -- author: txgruppi -- desc: Classic Pong. Keyboard: Q/Z left paddle up/down, O/M right paddle up/down, Space to start or restart. Made by Cursor. Tested by Humans. -- script: lua -- input: keyboard -- Constants W, H = 240, 136 PADDLE_W, PADDLE_H = 4, 24 PADDLE_SPEED = 3 PADDLE_L_X = 8 PADDLE_R_X = W - 8 - PADDLE_W BALL_SIZE = 4 BALL_SPEED_X, BALL_SPEED_Y = 2, 1 MARGIN_TOP, MARGIN_BOT = 8, H - 8 KEY_LEFT_UP, KEY_LEFT_DOWN = 17, 26 -- Q, Z KEY_RIGHT_UP, KEY_RIGHT_DOWN = 15, 13 -- O, M WIN_SCORE = 5 PADDLE_Y_MIN, PADDLE_Y_MAX = 8, H - 8 - PADDLE_H -- Game state (set by resetGame / resetBall) paddle_ly, paddle_ry = 0, 0 ball_x, ball_y = W / 2 - BALL_SIZE / 2, H / 2 - BALL_SIZE / 2 ball_vx, ball_vy = BALL_SPEED_X, 0 score1, score2 = 0, 0 state = "menu" function initMenu() score1, score2 = 0, 0 paddle_ly = H / 2 - PADDLE_H / 2 paddle_ry = H / 2 - PADDLE_H / 2 state = "menu" end function resetBall() ball_x = W / 2 - BALL_SIZE / 2 ball_y = H / 2 - BALL_SIZE / 2 ball_vx = (math.random(0, 1) * 2 - 1) * BALL_SPEED_X ball_vy = (math.random(0, 1) * 2 - 1) * BALL_SPEED_Y end function resetGame() score1, score2 = 0, 0 paddle_ly = H / 2 - PADDLE_H / 2 paddle_ry = H / 2 - PADDLE_H / 2 state = "play" resetBall() end function updatePaddles() if key(KEY_LEFT_UP) then paddle_ly = paddle_ly - PADDLE_SPEED end if key(KEY_LEFT_DOWN) then paddle_ly = paddle_ly + PADDLE_SPEED end paddle_ly = math.max(PADDLE_Y_MIN, math.min(PADDLE_Y_MAX, paddle_ly)) if key(KEY_RIGHT_UP) then paddle_ry = paddle_ry - PADDLE_SPEED end if key(KEY_RIGHT_DOWN) then paddle_ry = paddle_ry + PADDLE_SPEED end paddle_ry = math.max(PADDLE_Y_MIN, math.min(PADDLE_Y_MAX, paddle_ry)) end function checkWallCollision() if ball_y <= 0 then ball_vy = -ball_vy ball_y = 0 end if ball_y + BALL_SIZE >= H then ball_vy = -ball_vy ball_y = H - BALL_SIZE end end function checkPaddleCollision() if ball_x + BALL_SIZE < PADDLE_L_X then return "left" end if ball_x > PADDLE_R_X + PADDLE_W then return "right" end -- Left paddle hit (ball moving left, overlapping paddle) if ball_vx < 0 and ball_x <= PADDLE_L_X + PADDLE_W and ball_x + BALL_SIZE >= PADDLE_L_X then if ball_y + BALL_SIZE >= paddle_ly and ball_y <= paddle_ly + PADDLE_H then ball_vx = -ball_vx ball_x = PADDLE_L_X + PADDLE_W -- Nudge vy based on hit position local cy = ball_y + BALL_SIZE / 2 - (paddle_ly + PADDLE_H / 2) ball_vy = math.max(-BALL_SPEED_Y * 2, math.min(BALL_SPEED_Y * 2, cy / 4)) return nil end end -- Right paddle hit if ball_vx > 0 and ball_x + BALL_SIZE >= PADDLE_R_X and ball_x <= PADDLE_R_X + PADDLE_W then if ball_y + BALL_SIZE >= paddle_ry and ball_y <= paddle_ry + PADDLE_H then ball_vx = -ball_vx ball_x = PADDLE_R_X - BALL_SIZE local cy = ball_y + BALL_SIZE / 2 - (paddle_ry + PADDLE_H / 2) ball_vy = math.max(-BALL_SPEED_Y * 2, math.min(BALL_SPEED_Y * 2, cy / 4)) return nil end end return nil end function onGoal(scoredSide) if scoredSide == "left" then score2 = score2 + 1 else score1 = score1 + 1 end if score1 >= WIN_SCORE or score2 >= WIN_SCORE then state = "gameover" end resetBall() end function updateBall() ball_x = ball_x + ball_vx ball_y = ball_y + ball_vy checkWallCollision() local goal = checkPaddleCollision() if goal then onGoal(goal) end end function drawCenterLine() local cx = W / 2 - 1 for y = 0, H - 1, 8 do rect(cx, y, 2, 4, 15) end end function drawPaddles() rect(PADDLE_L_X, paddle_ly, PADDLE_W, PADDLE_H, 15) rect(PADDLE_R_X, paddle_ry, PADDLE_W, PADDLE_H, 15) end function drawBall() rect(ball_x, ball_y, BALL_SIZE, BALL_SIZE, 15) end function drawScores() print(tostring(score1), W / 2 - 24, 8, 15) print(tostring(score2), W / 2 + 8, 8, 15) end function drawGameOver() local msg = (score1 >= WIN_SCORE) and "P1 WINS" or "P2 WINS" local tw = print(msg, -999, -999, 15) print(msg, W / 2 - tw / 2, H / 2 - 8, 15) tw = print("press space", -999, -999, 15) print("press space", W / 2 - tw / 2, H / 2 + 4, 15) end function drawMenu() local tw = print("PONG", -999, -999, 15) print("PONG", W / 2 - tw / 2, H / 2 - 16, 15) tw = print("press space to start", -999, -999, 15) print("press space to start", W / 2 - tw / 2, H / 2 + 4, 15) tw = print("Made by Cursor. Tested by Humans.", -999, -999, 12) print("Made by Cursor. Tested by Humans.", W / 2 - tw / 2, H - 16, 12) end function BOOT() initMenu() end function TIC() if state == "play" then updatePaddles() updateBall() elseif state == "menu" then if keyp(48) then state = "play" resetBall() end elseif state == "gameover" then if keyp(48) then resetGame() end end cls(0) if state == "play" then drawCenterLine() end drawPaddles() if state == "play" then drawBall() end drawScores() if state == "menu" then drawMenu() elseif state == "gameover" then drawGameOver() end end