-- Forge milestone 4, genre two: tower defence. Creeps walk a lane on the navigation mesh in -- waves, turrets are placed by clicks on the floor -- the pointer put where a lane point projects -- -- and fire projectiles that collide with them. dofile("Forge/AuthorCompile.singe") local font = fontLoad("Singe/FreeSansBold.ttf", 18) fontSelect(font) fontQuality(FONT_QUALITY_BLENDED) dofile(authorBuild("testScripts/author/towerdefence.game", singeGetDataPath() .. "towerdefence.singe")) local gameUpdate = onOverlayUpdate local frames = 0 local shots = 0 local placed = 0 local maxCreeps = 0 local GIVE_UP = 45 local function place(x, y, z) local sx, sy, _, inFront = sceneProject(x, y, z) if inFront then authorSetPointer(1, sx, sy, true) authorSwitchDown(SWITCH_BUTTON3) authorSwitchUp(SWITCH_BUTTON3) placed = placed + 1 end end function onOverlayUpdate() local t = authorTime() frames = frames + 1 -- Two turrets beside the lane, once the scene has drawn so projection works. if frames == 10 then place(0, 0, -3.5) elseif frames == 12 then place(10, 0, 0) end maxCreeps = math.max(maxCreeps, authorCount("creep")) local r = gameUpdate() colorForeground(255, 255, 255, 255) fontPrint(12, 450, string.format("authored tower defence, %.1fs, creeps %d, turrets %d, killed %d, gold %d, lives %d", t, authorCount("creep"), authorCount("turret"), AUTHOR_VARS.killed, AUTHOR_VARS.gold, AUTHOR_VARS.lives)) if (shots == 0 and t > 3) or (shots == 1 and AUTHOR_VARS.killed > 0) or (shots == 2 and t > 20) then shots = shots + 1 singeScreenshot() end local hive = authorEntity("hive") if (t > 8 and hive and hive.vars.made >= 10 and authorCount("creep") == 0) or (t > GIVE_UP) then debugPrint(string.format("TD RESULT turrets=%d killed=%d gold=%d lives=%d maxCreeps=%d after=%.1fs", authorCount("turret"), AUTHOR_VARS.killed, AUTHOR_VARS.gold, AUTHOR_VARS.lives, maxCreeps, t)) if authorCount("turret") < 2 then debugPrint("TD FAIL the clicks did not place two turrets") end if AUTHOR_VARS.killed == 0 then debugPrint("TD FAIL no creep was killed") end if maxCreeps < 3 then debugPrint("TD FAIL the waves never had three creeps walking") end singeQuit() end return r end