-- 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 > 0ÿÿÿÿÿÿÿÿ2Tv˜ºÜþïÍ«‰gE#2Tv˜ºÜþ2Tv˜ºÜþ 0 D$404mNJN…L04e$ÐFHuqaY}ÎÒ},…•¡mª,Òª™mÂÊÚÔ^ÞîÖÛGIF89aðˆw!ÿ NETSCAPE2.0!ùÿ,ðˆ‡ ÞîÖ…•¡ÿHP`€L¨!Áƒ .dH±¢Å‹3jÜȱ£Ç� !:ñaI‘E’YpáD– cÊœI³¦Mš/WÔ™S§D˜ '®z³¨Ñ£H“Mé¡K¦>:…™rêN¥X³jÝšQåO‰M¥­š°äP®hÓªM*t­Û·pãÊ�K·®Ý»xóêÝË·¯ß¿€ L¸°áÈ+^̸±ãÇ�#KžL¹²å˘3kÞ̹³çÏ C‹Mº´éÓ¨S«^ͺµë×°cËžM»¶íÛ¸sëÞÍ»·ïßÀƒ N¼¸ñãÈ“+_μ¹óçУKŸN½ºõëØ³kßν»÷ïàË¥O¾¼ùóèÓ«_Ͼ½û÷ðãËŸO¿¾ýûøóë/Ûvÿ\”þÑ…R®5 Q¢u`‚qÈ`ƒ>(á„Vhá…f¨á†vèᇠ†(âˆ$–hâ‰(¦¨âŠ,¶èâ‹0Æ(ãŒ4Öhã�8æ¨ãŽ<öèã�@Æ$À�Diä‘HYb’L6Iä’NFy$”RV)•VF‰e–Méå—`†)æ˜d–i&e;