-- Arcade physics (FORGE.md's catalogue): a ball on a 2D body bouncing off static bricks and a -- kinematic paddle the keys move; bricks broken by collision rules. dofile("Forge/AuthorCompile.singe") local font = fontLoad("Singe/FreeSansBold.ttf", 18) fontSelect(font) fontQuality(FONT_QUALITY_BLENDED) overlaySetResolution(720, 480) dofile(authorBuild("testScripts/author/breakout.game", singeGetDataPath() .. "breakout.singe")) local gameUpdate = onOverlayUpdate local frames = 0 local shots = 0 local paddleStart = nil local GIVE_UP = 30 function onOverlayUpdate() local t = authorTime() local ball = authorEntity("ball") local paddle = authorEntity("paddle") local bx, by = authorPosition(ball) local px = authorX(paddle) frames = frames + 1 paddleStart = paddleStart or px -- The paddle chases the ball, which is what keeps it in play. if bx < px - 10 then authorKeyUp(0, SCANCODE.RIGHT.value) authorKeyDown(0, SCANCODE.LEFT.value) elseif bx > px + 10 then authorKeyUp(0, SCANCODE.LEFT.value) authorKeyDown(0, SCANCODE.RIGHT.value) end local r = gameUpdate() colorForeground(255, 255, 255, 255) fontPrint(12, 450, string.format("authored breakout, %.1fs, ball %.0f,%.0f, broken %d, lives %d", t, bx, by, AUTHOR_VARS.broken, AUTHOR_VARS.lives)) if (shots == 0 and t > 0.5) or (shots == 1 and AUTHOR_VARS.broken > 0) then shots = shots + 1 singeScreenshot() end if (AUTHOR_VARS.broken >= 2) or (t > GIVE_UP) then debugPrint(string.format("BREAKOUT RESULT broken=%d lives=%d paddleMoved=%s after=%.1fs", AUTHOR_VARS.broken, AUTHOR_VARS.lives, tostring(math.abs(px - paddleStart) > 5), t)) if AUTHOR_VARS.broken < 1 then debugPrint("BREAKOUT FAIL no brick was broken") end singeQuit() end return r end