-- title: simplepong -- author: infog -- desc: a simple 1 player pong clone -- script: lua -- objects ball={ x=math.random(236), y=3, r=3, speedX=1, speedY=1 } platform={ x=110, y=120, w=30, h=6 } -- functions function drawBall() circ( ball.x, ball.y, ball.r, 15 ) end function drawPlatform() rect( platform.x, platform.y, platform.w, platform.h, 10 ) end function moveBall() if not isRunning then return false end ball.x = ball.x + ball.speedX if ball.x + ball.r > 239 then ball.speedX = ball.speedX * -1 end if ball.x - ball.r < 1 then ball.speedX = ball.speedX * -1 end ball.y = ball.y + ball.speedY if ball.y + ball.r > 135 then ball.speedY = ball.speedY * -1 end if ball.y - ball.r < 1 then ball.speedY = ball.speedY * -1 end end function movePlatform() if not isRunning then return false end if btn(2) and platform.x > 0 then platform.x = platform.x - 2 end if btn(3) and platform.x + platform.w < 240 then platform.x = platform.x + 2 end end function ballHitsPlatform() if ball.y - ball.r >= platform.y - platform.h and ball.y - ball.r <= platform.y + platform.h then if ball.x - ball.r >= platform.x and ball.x + ball.r <= platform.x + platform.w then return true end end return false end function ballHitsLeftSide() if ball.x - ball.r >= platform.x and ball.x - ball.r <= platform.x + (platform.w / 2) then return true end return false end function collision() if not isRunning then return false end if ballHitsPlatform() then if ball.speedY > 0 then ball.speedY = ball.speedY * -1 if ballHitsLeftSide() then if ball.speedX < 0 then ball.speedX = ball.speedX - 0.2 else ball.speedX = (ball.speedX - 0.3) * -1 end else if ball.speedX > 0 then ball.speedX = ball.speedX + 0.2 else ball.speedX = (ball.speedX + 0.3) * -1 end end sfx(0, 10, 10) end end end function isGameOver() if ball.y + ball.r > 132 then isRunning=false print("GAME OVER", 100, 60, 14) end end function speedUp() if t%500 == 0 then if ball.speedY > 0 then ball.speedY = ball.speedY + 0.3 else ball.speedY = ball.speedY - 0.3 end end end function countAndDrawPoints() if not isRunning then return false end if t%10 == 0 then points=points+1 end print("points: " .. points) end -- main TIC t=0 points=0 isRunning=true function TIC() t=t+1 cls(0) moveBall() movePlatform() collision() drawBall() drawPlatform() countAndDrawPoints() speedUp() isGameOver() end > 02TvͫgE#2Tv2Tv 0 D$404mNJNL04e$FHuqaY}},m,Ҫm^GIF89aw! NETSCAPE2.0!, օHP`L! .dHŋ3jȱǏ !:aIEYpD cʜIM/WԙSD 'zѣHMK>:rNXjݚQOMPhӪM*t۷pʝKݻx˷߿ LÈ+^̸ǐ#KL˘3k̹ϠCMӨS^ͺװc˞M۸sͻ Nȓ+_μУKNسkνËOӫ_Ͼ˟O/v\хR5 Qu`q`>(Vhfv ($h(,0(4h8<@$DiHYbL6INFy$RV)VFeM`)di&e;