Z PP Z UYUPP Z UZUUYUPP Z Z ZUUYP Y ZZ PPP P UPUPP P UYUUPUPP  [ P P [UXU P P [[P ZUXU[P YPP ZUPUPP 0C40DD0C4@@C433   """"""""   """""""""" DDB4C$B4C$B4C$B4C$ DD""                 <>????????????????????????????     ;?????????????????????????????? 3 0D CD4 3D3 D D0D03            P  P U  UPU PZ  PZPUPP  PP ఈ    ົZZ ົ[UUUXUYUXU[PPP P P ఈ    ົ ົ[Z [ఈ[PPP P P  ఈ    ࠠ   ࠚ ࠙  ࠪ ົ࠙   ົ࠙Y  ࠙ ఈ ZYࠩZY  ZZ  ఈ    ົ ົ[Z [ఈ[PPP P P ఈ    ົZZ ົ[UUUXUYUXU[PPP P P     Z  ZU UPUPPPPPUPPPP    "  " "  "  "    "" "   """ """"""" """ """ """ """""" """"""""""""""""""""/"""""""/"""""/"/""" /"""""/"/" /"""""/"/"""/""""/"""""""""""""""""""""")}-- title: Incrementower -- author: Sava -- desc: Yet another incremental. Inspired by Nodebuster -- license: MIT License -- version: 0.1 -- script: lua -- input: mouse debugMode=false w=240 h=136 notation=pmem(0) notNames={"Standard", "Scientific", "Hexadecimal", "Raw float (why)"} FIRE_CH=0 HIT_CH=1 HPLOSE_CH=2 BUTTON_CH=3 COLLECT_CH=2 dropCols={9, 2} function round(n) return n%1 > 0.5 and math.floor(n)+1 or math.floor(n) end function formatN(n) return (n%1 < 0.0001 or n%1 > 0.99999) and string.format("%d", round(n)) or string.format("%.2f", n) end local suffixes = {"K", "M", "B", "T", "Q"} function numb(n) if notation == 1 then if n >= 1000 then return string.format("%.2e", n) else return formatN(n) end elseif notation == 2 then return string.format("%x", math.floor(n))..(n%1 < 0.0001 and "" or "."..string.format("%x", math.floor(n%1*100))) elseif notation == 3 then local p, b = string.pack("f", n), "" for i=1, #p do local byte = string.byte(p, i) for j=7, 0, -1 do b=b..((byte>>j)&1) end end return b:reverse() else if n >= 1000 then local p = math.floor(math.log(n, 10)/3) return string.format("%.2f", n/math.pow(10, p*3))..suffixes[p] else return formatN(n) end end end upgrades={ {con=0, x=0, y=0, grph=2, multi=1, name="Orb", cost={}, desc=function() return "Conjure up a small orb of energy\n\nStats:\nDamage: "..((attacks["orb"] and numb(attacks["orb"].damage)) or numb(50)).."\nMana cost: "..((attacks["orb"] and numb(attacks["orb"].mana)) or numb(10)).."\nCooldown: "..((attacks["orb"] and numb(attacks["orb"].cd/60)) or numb(3)).." sec" end, onBuy=function() attacks["orb"]={last=-math.huge, cd=180, grph=2, mana=10, damage=50, trigger=function(i) sfx(0, 48, -1, FIRE_CH, volume) local dx, dy = norm(mx-w/2, my-h/2) proj[#proj+1]={x=w/2, y=h/2, dx=dx, dy=dy, spd=0.5, from=1, damage=attacks[i].damage, rad=2, life=600, col=9, onTick=function(p) if t%15 == 0 then part[#part+1]={x=p.x, y=p.y, dx=0, dy=0, spd=0, life=60, col=8, rad=1} end end, onHit=function(p) sfx(1, 48, -1, HIT_CH, volume) for j=1, 10 do local dx, dy = rotate(1, 0, math.random()*math.pi*2) part[#part+1]={x=p.x, y=p.y, dx=dx, dy=dy, spd=math.random()*0.5+0.5, life=math.random()*30+30, col=math.random(8, 10), rad=math.random(1, 3)} end end} end} end, bought=0}, {con=1, x=0, y=9, grph=3, multi=5, name="Smaller cooldown", cost={10}, desc=function() return "Applied to Orb\n"..numb(attacks["orb"].cd/60).." sec -> "..numb((attacks["orb"].cd-30)/60).." sec" end, onBuy=function(u) attacks["orb"].cd=attacks["orb"].cd-30 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["orb"].cd/60).." sec" end end end, bought=0}, {con=2, x=0, y=18, grph=4, multi=5, name="Smaller cooldown", cost={100}, desc=function() return "Applied to Orb\n"..numb(attacks["orb"].cd/60).." sec -> "..numb((attacks["orb"].cd-5)/60).." sec" end, onBuy=function(u) attacks["orb"].cd=attacks["orb"].cd-5 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["orb"].cd/60).." sec" end end end, bought=0}, {con=1, x=0, y=-9, grph=3, multi=5, name="More damage", cost={15}, desc=function() return "Applied to Orb\n"..numb(attacks["orb"].damage).." -> "..numb(attacks["orb"].damage+25) end, onBuy=function(u) attacks["orb"].damage=attacks["orb"].damage+25 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["orb"].damage) end end end, bought=0}, {con=4, x=0, y=-18, grph=4, multi=5, name="More damage", cost={100}, desc=function() return "Applied to Orb\n"..numb(attacks["orb"].damage).." -> "..numb(attacks["orb"].damage+25) end, onBuy=function(u) attacks["orb"].damage=attacks["orb"].damage+25 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["orb"].damage) end end end, bought=0}, {con=1, x=-9, y=0, grph=7, multi=5, name="More resources", cost={30}, desc=function() return numb(resourceMult).."x -> "..numb(resourceMult+0.5).."x" end, onBuy=function(u) resourceMult=resourceMult+0.5 if u.bought == u.multi-1 then u.desc=function() return numb(resourceMult).."x" end end end, bought=0}, {con=6, x=-18, y=0, grph=7, multi=5, name="More resources", cost={120}, desc=function() return numb(resourceMult).."x -> "..numb(resourceMult+0.5).."x" end, onBuy=function(u) resourceMult=resourceMult+0.5 if u.bought == u.multi-1 then u.desc=function() return numb(resourceMult).."x" end end end, bought=0}, {con=7, x=-27, y=0, grph=7, multi=5, name="More resources", cost={200}, desc=function() return numb(resourceMult).."x -> "..numb(resourceMult+1).."x" end, onBuy=function(u) resourceMult=resourceMult+1 if u.bought == u.multi-1 then u.desc=function() return numb(resourceMult).."x" end end end, bought=0}, {con=1, x=9, y=0, grph=8, multi=5, name="Faster mana recharge", cost={30}, desc=function() return numb(manaSpd*60).."/sec -> "..numb((manaSpd+0.01)*60).."/sec" end, onBuy=function(u) manaSpd=manaSpd+0.01 if u.bought == u.multi-1 then u.desc=function() return numb(manaSpd*60).."/sec" end end end, bought=0}, {con=9, x=18, y=0, grph=8, multi=5, name="Faster mana recharge", cost={100}, desc=function() return numb(manaSpd*60).."/sec -> "..numb((manaSpd+0.01)*60).."/sec" end, onBuy=function(u) manaSpd=manaSpd+0.01 if u.bought == u.multi-1 then u.desc=function() return numb(manaSpd*60).."/sec" end end end, bought=0}, {con=10, x=27, y=0, grph=8, multi=5, name="Faster mana recharge", cost={350}, desc=function() return numb(manaSpd*60).."/sec -> "..numb((manaSpd+0.02)*60).."/sec" end, onBuy=function(u) manaSpd=manaSpd+0.02 if u.bought == u.multi-1 then u.desc=function() return numb(manaSpd*60).."/sec" end end end, bought=0}, {con=5, x=0, y=-27, grph=9, multi=1, name="Splitter", cost={0, 1}, desc=function() return "Orbs now split into multiple\nprojectiles upon impact\n\nStats:\nAmount: "..(hooks["splitter"] and numb(hooks["splitter"].amount) or numb(3)).."\nDamage: "..(hooks["splitter"] and numb(hooks["splitter"].damage) or numb(50)) end, onBuy=function() hooks["splitter"]={hook=1, damage=50, amount=3, func=function(hook, p) local sang = math.random()*math.pi*2 for i=1, hook.amount do local dx, dy = rotate(1, 0, (i-1)/hook.amount*math.pi*2+sang) proj[#proj+1]={x=p.x, y=p.y, dx=dx, dy=dy, from=0, spd=0.3, damage=hook.damage, rad=2, life=600, col=11, onTick=function() end, onHit=function(p) sfx(1, 48, -1, HIT_CH, volume) for j=1, 5 do local dx, dy = rotate(1, 0, math.random()*math.pi*2) part[#part+1]={x=p.x, y=p.y, dx=dx, dy=dy, spd=math.random()*0.5+0.5, life=math.random()*30+30, col=math.random(8, 11), rad=math.random(0, 2)} end end} end end} end, bought=0}, {con=12, x=9, y=-27, grph=10, multi=5, name="Splitter damage", cost={300}, desc=function() return numb(hooks["splitter"].damage).." -> "..numb(hooks["splitter"].damage+10) end, onBuy=function(u) hooks["splitter"].damage=hooks["splitter"].damage+10 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["splitter"].damage) end end end, bought=0}, {con=13, x=18, y=-27, grph=11, multi=5, name="Splitter damage", cost={500}, desc=function() return numb(hooks["splitter"].damage).." -> "..numb(hooks["splitter"].damage+10) end, onBuy=function(u) hooks["splitter"].damage=hooks["splitter"].damage+10 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["splitter"].damage) end end end, bought=0}, {con=12, x=-9, y=-27, grph=10, multi=5, name="Splitter amount", cost={300}, desc=function() return numb(hooks["splitter"].amount).." -> "..numb(hooks["splitter"].amount+2) end, onBuy=function(u) hooks["splitter"].amount=hooks["splitter"].amount+2 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["splitter"].amount) end end end, bought=0}, {con=15, x=-18, y=-27, grph=11, multi=6, name="Splitter amount", cost={500}, desc=function() return numb(hooks["splitter"].amount).." -> "..numb(hooks["splitter"].amount+2) end, onBuy=function(u) hooks["splitter"].amount=hooks["splitter"].amount+2 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["splitter"].amount) end end end, bought=0}, {con=11, x=36, y=0, grph=13, multi=1, name="Mana burst", cost={0, 1}, desc=function() return "Every once in a while you get a mana buff\n\nStats:\nBoost: "..(attacks["mana"] and numb(-attacks["mana"].mana) or numb(10)).."\nCooldown: "..(attacks["mana"] and numb(attacks["mana"].cd/60) or numb(10)).." sec" end, onBuy=function() attacks["mana"]={last=-math.huge, cd=600, grph=13, mana=-10, damage=0, trigger=function() sfx(8, 48, -1, HIT_CH, volume) end} end, bought=0}, {con=17, x=36, y=-9, grph=14, multi=5, name="Burst power", cost={500}, desc=function() return numb(-attacks["mana"].mana).." -> "..numb(-(attacks["mana"].mana-10)) end, onBuy=function(u) attacks["mana"].mana=attacks["mana"].mana-10 if u.bought == u.multi-1 then u.desc=function() return numb(-attacks["mana"].mana) end end end, bought=0}, {con=18, x=36, y=-18, grph=15, multi=4, name="Burst power", cost={1200}, desc=function() return numb(-attacks["mana"].mana).." -> "..numb(-(attacks["mana"].mana-10)) end, onBuy=function(u) attacks["mana"].mana=attacks["mana"].mana-10 if u.bought == u.multi-1 then u.desc=function() return numb(-attacks["mana"].mana) end end end, bought=0}, {con=17, x=36, y=9, grph=14, multi=5, name="Burst cooldown", cost={1000}, desc=function() return numb(attacks["mana"].cd/60).." -> "..numb((attacks["mana"].cd-45)/60) end, onBuy=function(u) attacks["mana"].cd=attacks["mana"].cd-45 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["mana"].cd/60) end end end, bought=0}, {con=20, x=36, y=18, grph=15, multi=8, name="Burst cooldown", cost={5000}, desc=function() return numb(attacks["mana"].cd/60).." -> "..numb((attacks["mana"].cd-45)/60) end, onBuy=function(u) attacks["mana"].cd=attacks["mana"].cd-45 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["mana"].cd/60) end end end, bought=0}, {con=8, x=-36, y=0, grph=16, multi=1, name="Shockwaves", cost={0, 1}, desc=function() return "When collecting resources\nyou release a damaging shockwave\n\nStats:\nCooldown: "..(hooks["shockwave"] and numb(hooks["shockwave"].cd) or numb(100)).." drops/shockwave\nDamage: "..(hooks["shockwave"] and numb(hooks["shockwave"].damage*100) or numb(10)).."% of left enemy hp" end, onBuy=function() hooks["shockwave"]={hook=function(h) if resources[1]-stats.startResources[1] >= h.cd*h.timesT then h.timesT=h.timesT+1 return true end return false end, timesT=1, damage=0.1, cd=100, func=function(hook) for i=#enemies, 1, -1 do dealDamage(i, enemies[i].hp*hook.damage) end for i=1, 360 do local dx, dy = rotate(1, 0, i/360*math.pi*2) part[#part+1]={x=w/2, y=h/2, dx=dx, dy=dy, spd=3, rad=4, life=300, col=11} end end} end, bought=0}, {con=22, x=-36, y=9, grph=17, multi=5, name="Shockwave cooldown", cost={2000}, desc=function() return numb(hooks["shockwave"].cd).." drops -> "..numb(hooks["shockwave"].cd-10).." drops" end, onBuy=function(u) hooks["shockwave"].cd=hooks["shockwave"].cd-10 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["shockwave"].cd).." drops" end end end, bought=0}, {con=23, x=-36, y=18, grph=18, multi=4, name="Shockwave cooldown", cost={5000}, desc=function() return numb(hooks["shockwave"].cd).." drops -> "..numb(hooks["shockwave"].cd-10).." drops" end, onBuy=function(u) hooks["shockwave"].cd=hooks["shockwave"].cd-10 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["shockwave"].cd).." drops" end end end, bought=0}, {con=22, x=-36, y=-9, grph=17, multi=4, name="Shockwave damage", cost={2000}, desc=function() return numb(hooks["shockwave"].damage*100).."% -> "..numb(hooks["shockwave"].damage*100+10).."%" end, onBuy=function(u) hooks["shockwave"].damage=hooks["shockwave"].damage+0.1 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["shockwave"].damage*100).."%" end end end, bought=0}, {con=25, x=-36, y=-18, grph=18, multi=4, name="Shockwave damage", cost={5000}, desc=function() return numb(hooks["shockwave"].damage*100).."% -> "..numb(hooks["shockwave"].damage*100+10).."%" end, onBuy=function(u) hooks["shockwave"].damage=hooks["shockwave"].damage+0.1 if u.bought == u.multi-1 then u.desc=function() return numb(hooks["shockwave"].damage*100).."%" end end end, bought=0}, {con=3, x=0, y=27, grph=19, multi=1, name="Minigun", cost={0, 1}, desc=function() return "yes\n\nStats:\nDamage: "..((attacks["minigun"] and numb(attacks["minigun"].damage)) or numb(5)).."\nCooldown: "..((attacks["minigun"] and numb(attacks["minigun"].cd/60)) or numb(20/60)).." sec" end, onBuy=function() attacks["minigun"]={last=-math.huge, cd=20, grph=2, mana=0, damage=5, trigger=function(i) sfx(9, 48, -1, FIRE_CH, volume) local dx, dy = norm(mx-w/2, my-h/2) dx, dy = rotate(dx, dy, (math.random()-0.5)*math.pi/4) proj[#proj+1]={x=w/2, y=h/2, dx=dx, dy=dy, spd=0.5, from=1, damage=attacks[i].damage, rad=1, life=600, col=9, onTick=function(p) end, onHit=function(p) sfx(1, 48, -1, HIT_CH, volume) for j=1, 3 do local dx, dy = rotate(1, 0, math.random()*math.pi*2) part[#part+1]={x=p.x, y=p.y, dx=dx, dy=dy, spd=math.random()*0.5+0.5, life=math.random()*30+30, col=math.random(8, 10), rad=math.random(1, 3)} end end} end} end, bought=0}, {con=27, x=-9, y=27, grph=20, multi=5, name="Smaller cooldown", cost={300}, desc=function() return "Applied to Minigun\n"..numb(attacks["minigun"].cd/60).." sec -> "..numb((attacks["minigun"].cd-3)/60).." sec" end, onBuy=function(u) attacks["minigun"].cd=attacks["minigun"].cd-3 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["minigun"].cd/60).." sec" end end end, bought=0}, {con=28, x=-18, y=27, grph=21, multi=2, name="Smaller cooldown", cost={1000}, desc=function() return "Applied to Minigun\n"..numb(attacks["minigun"].cd/60).." sec -> "..numb((attacks["minigun"].cd-2)/60).." sec" end, onBuy=function(u) attacks["minigun"].cd=attacks["minigun"].cd-2 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["minigun"].cd/60).." sec" end end end, bought=0}, {con=27, x=9, y=27, grph=20, multi=5, name="More damage", cost={150}, desc=function() return "Applied to Minigun\n"..numb(attacks["minigun"].damage).." -> "..numb(attacks["minigun"].damage+3) end, onBuy=function(u) attacks["minigun"].damage=attacks["minigun"].damage+3 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["minigun"].damage) end end end, bought=0}, {con=30, x=18, y=27, grph=21, multi=5, name="More damage", cost={300}, desc=function() return "Applied to Minigun\n"..numb(attacks["minigun"].damage).." -> "..numb(attacks["minigun"].damage+3) end, onBuy=function(u) attacks["minigun"].damage=attacks["minigun"].damage+3 if u.bought == u.multi-1 then u.desc=function() return numb(attacks["minigun"].damage) end end end, bought=0}, } function AAAAAAAAAAAAAAA() end uX, uY = 0, 0 usX, usY = 0, 0 enemies={} attacks={} proj={} part={} hooks={} drops={{},{}} stats={damage=0, maxdamage=0, killed=0, startResources={}} statDisp={ function() return "Total damage dealt: "..numb(stats.damage) end, function() return "Max damage dealt: "..numb(stats.maxdamage) end, function() return "Enemies killed: "..numb(stats.killed) end, function() return "Seconds lived: "..numb(t//60) end, } resources={0,0} reservedMem=3 volume=pmem(1) firstL=pmem(2)==0 maxLevelR=pmem(3) battle=false settings=false deleteSave=false over=false win=false baseDifficulty={spawnRate=180, rateSpd=0.002, types=1, hpSpd=0.001, hp=1, damage=1, speed=1, length=3600} difficulty={spawnRate=180, rateSpd=0.002, types=1, hpSpd=0.001, hp=1, damage=1, speed=1, length=3600} difficultyInc={spawnRate=-10, rateSpd=0.002, types=0.5, hpSpd=0.001, hp=0.5, damage=0.5, speed=0.5, length=0} levelIdx=maxLevelR levelTmr=0 levelLen=15000 maxLevel=4 hp=100 maxHp=100 mana=50 manaSpd=0.02 maxMana=50 resourceMult=1 function BOOT() trace("start") --for i=0, 255 do --pmem(i, 0) --end if debugMode then for i,r in ipairs(resources) do pmem(i+reservedMem, 1000000000) end end trace(firstL) if firstL then pmem(1, 15) volume=15 pmem(2, 1) end for i=1, #resources do resources[i] = pmem(i+reservedMem) end for i,u in ipairs(upgrades) do for i=1, pmem(i+#resources+reservedMem) do u.onBuy(u) for i=1, #u.cost do u.cost[i]=u.cost[i]*1.2 end u.bought=u.bought+1 end end end t=0 leftp, lefts = false, false leftrWait = true rigthp, rights = false, false function TIC() mx, my, left, _, right = mouse() leftp, rightp = false, false if left and not lefts then lefts = true leftp = true usX, usY = mx-uX, my-uY end if not left and lefts then lefts = false end if right and not rights then rights = true rightp = true end if not right and rights then rights = false end if not left then leftrWait = false end if leftrWait then left = false leftp = false end if left and not battle and not settings then uX, uY = mx-usX, my-usY end if battle and not over then difficulty.spawnRate=difficulty.spawnRate-difficulty.rateSpd difficulty.hp=difficulty.hp+difficulty.hpSpd if t%difficulty.spawnRate < 1 then local edge = math.random(1, 4) local size = math.random(5, 10) local x, y = 0, 0 if edge == 1 then x, y = math.random(0, w), -size*root2 elseif edge == 2 then x, y = math.random(0, w), h+size*root2 elseif edge == 3 then x, y = -size*root2, math.random(0, h) elseif edge == 4 then x, y = w+size*root2, math.random(0, h) end enemies[#enemies+1]={x=x, y=y, ang=math.random()*math.pi*2, rotSpd=math.random()*0.03+0.01, size=size, hp=50*difficulty.hp, maxHp=50*difficulty.hp, damage=size*3*difficulty.damage, loot={10}, spd=(math.random()*0.1+0.05)*difficulty.speed, col=2, onDeath=function() end} end if difficulty.length-t < 1 then difficulty.length=math.huge local edge = math.random(1, 4) local size = math.random(25, 30) local x, y = 0, 0 if edge == 1 then x, y = math.random(0, w), -size*root2 elseif edge == 2 then x, y = math.random(0, w), h+size*root2 elseif edge == 3 then x, y = -size*root2, math.random(0, h) elseif edge == 4 then x, y = w+size*root2, math.random(0, h) end enemies[#enemies+1]={x=x, y=y, ang=math.random()*math.pi*2, rotSpd=math.random()*0.003+0.003, size=size, hp=500*difficulty.hp, maxHp=500*difficulty.hp, damage=size*30*difficulty.damage, loot={50}, spd=(math.random()*0.01+0.03)*difficulty.speed, col=2, onDeath=function() resources[2]=resources[2]+1 win=true over=true maxLevelR=math.max(maxLevelR, levelIdx+1) pmem(3, maxLevelR) for i=1, #drops do resources[i]=resources[i]+#drops[i] drops[i]={} leftrWait=true left=false end end} end mana=math.min(mana+manaSpd, maxMana) for i,a in pairs(attacks) do if left and t-a.last >= a.cd and mana > a.mana then mana=mana-a.mana a.last=t a.trigger(i) end end for k,h in pairs(hooks) do if type(h.hook) == "function" and h.hook(h) then h.func(h) end end for i=#proj, 1, -1 do local p = proj[i] p.x, p.y = p.x+p.dx*p.spd, p.y+p.dy*p.spd p.onTick(p) p.life=p.life-1 if p.life <= 0 then remove(proj, i) end end for i=#part, 1, -1 do local p = part[i] p.x, p.y = p.x+p.dx*p.spd, p.y+p.dy*p.spd p.life=p.life-1 if p.life <= 0 then remove(part, i) end end for i=#enemies, 1, -1 do local e = enemies[i] local dx, dy = norm(w/2-e.x, h/2-e.y) e.x, e.y = e.x+dx*e.spd, e.y+dy*e.spd e.ang=(e.ang+e.rotSpd)%(math.pi*2) for j=#proj, 1, -1 do local p = proj[j] local coll = circCollSq(p.x, p.y, p.rad, e.x, e.y, e.ang, e.size) if coll then p.onHit(p) for k,h in pairs(hooks) do if type(h.hook) == "number" and p.from == h.hook then h.func(h, p) end end dealDamage(i, p.damage) if not enemies[i] then break end remove(proj, j) end end end end vbank(1) cls(0) vbank(0) cls(0) if settings then print("Tip: Press F6 to toggle CRT filter", w/2-89, 5) rect(w/2-43, h/2-31, 86, 7, 14) print("Change notation", w/2-42, h/2-30) if mx >= w/2-43 and mx < w/2+43 and my >= h/2-31 and my < h/2-24 then rect(w/2-43, h/2-31, 86, 7, 13) print(notNames[notation+1], w/2-42, h/2-30) if leftp then notation=(notation+1)%#notNames pmem(0, notation) sfx(5, 48, -1, BUTTON_CH, volume) end end print("Volume: "..numb(math.floor(volume)), w/2-print("Volume: "..numb(math.floor(volume)), w+2, h+2)//2, h/2-23, 14) line(w/2-43, h/2-15, w/2+42, h/2-15, 15) if mx >= w/2-43 and mx < w/2+43 and my >= h/2-17 and my < h/2-11 then line(w/2-43, h/2-15, w/2+42, h/2-15, 14) circ(lerp(w/2-43, w/2+42, volume/15), h/2-15, 2, 14) if left then volume = round((mx-w/2+43)/85*15) pmem(1, volume) end end circ(lerp(w/2-43, w/2+42, volume/15), h/2-15, 1, 14) rect(w-64, h-7, 64, 7, 2) print(deleteSave and "You sure?" or "Delete save", w-63, h-6) if mx >= w-64 and my >= h-7 then rectb(w-64, h-7, 64, 7, 12) if leftp then if not deleteSave then deleteSave = true else deleteSave = false for i=0, 255 do pmem(i, 0) end firstL=true reset() end sfx(5, 48, -1, BUTTON_CH, volume) end end spr(48, 1, h-9, 0) if mx < 9 and my >= h-9 then rectb(1, h-9, 8, 8, 2) if leftp then settings=not settings deleteSave = false sfx(5, 48, -1, BUTTON_CH, volume) end end return end if battle then if over then if win and levelIdx == 4 then cls(0) print("Congratulations!\nYou finished the game!", w/2-print("Congratulations!\nYou finished the game!", w+2, h+2)/2, h/2-6, time()//150%15) return end local t = win and "You won!" or "You're dead!" local size = 0 for i,s in ipairs(statDisp) do local s = print(s(), w+2, h+2)+3 if s > size then size = s end end rect(w/2-size/2, h/2-60, size, 120, 15) rectb(w/2-size/2, h/2-60, size, 120, 14) print(t, w/2-print(t, w+2, h+2)//2, h/2-58, 12) for i,s in ipairs(statDisp) do print(s(), w/2-size/2+2, i*7+h/2-57, 13) end print("Resources gained:", w/2-46, h/2-57+(#statDisp+1)*7, 12) for i,s in ipairs(stats.startResources) do local size = print(numb(resources[i]-s), w/2, h/2)+8 print(numb(resources[i]-s), w/2-size/2, i*9+h/2-57+(#statDisp+1)*7, 12) spr(i+31, w/2+size/2-8, i*9+h/2-57+(#statDisp+1)*7-2, 0) end print("(click anywhere\nto continue)", w/2-size/2+2, h/2+47, 14) if left then over = false win = false battle = false leftrWait = true for i=1, #resources do pmem(i+reservedMem, resources[i]) end return end return end spr(1, w/2-4, h/2-4, 0) for i=#part, 1, -1 do local p=part[i] circ(p.x, p.y, p.rad, p.col) end for i=#proj, 1, -1 do local p=proj[i] circ(p.x, p.y, p.rad, p.col) end for i=#enemies, 1, -1 do local e = enemies[i] drawSq(e.x, e.y, e.ang, e.size, e.hp/e.maxHp, e.col) local coll = AABBCollSq(w/2, h/2, 4, e.x, e.y, e.ang, e.size) if coll then hp=hp-e.damage if hp <= 0 then over=true leftrWait=true for i=1, #drops do resources[i]=resources[i]+#drops[i] drops[i]={} end end sfx(4, 48, -1, HPLOSE_CH, volume) remove(enemies, i) end end local c = false for i=1, #drops do for j=#drops[i], 1, -1 do local d=drops[i][j] if d then local dx, dy = norm(w/2-d.x, h/2-d.y) d.x, d.y = d.x+dx*d.spd, d.y+dy*d.spd d.spd = d.spd+0.01 local nx, ny = d.x+dx*d.spd*5, d.y+dy*d.spd*5 line(d.x, d.y, nx, ny, dropCols[i]) if dist(d.x, d.y, w/2, h/2) < 8 then resources[i]=resources[i]+1 remove(drops[i], j) if not c then c=true sfx(7, 48, -1, COLLECT_CH, volume) end end end end end COLLECT_CH=3-COLLECT_CH+2 line(0, 0, lerp(0, w, hp/maxHp), 0, 2) line(lerp(0, w, hp/maxHp), 0, w, 0, 1) line(0, 1, lerp(0, w, mana/maxMana), 1, 10) line(lerp(0, w, mana/maxMana), 1, w, 1, 8) line(lerp(0, w, mana/maxMana), 1, lerp(0, w, (mana-(attacks["orb"] and attacks["orb"].mana or 0))/maxMana), 1, 9) line(0, 2, lerp(0, w, t/difficulty.length), 2, 4) local i = 1 for _,a in pairs(attacks) do spr(a.grph, i*9-8, h-9, 0) line(i*9-8, h-1, lerp(i*9-8, i*9-1, math.min((t-a.last)/a.cd, 1)), h-1, 14) i=i+1 end rect(w-40, h-7, 40, 7, 2) print("Exit", w-39, h-6) if mx >= w-40 and my >= h-7 then rectb(w-40, h-7, 40, 7, 12) if leftp then over=true leftrWait=true sfx(5, 48, -1, BUTTON_CH, volume) end end else for i,u in ipairs(upgrades) do if u.con == 0 or upgrades[u.con].bought >= upgrades[u.con].multi then local posX, posY = u.x+w/2+uX, u.y+h/2+uY if u.bought >= u.multi then rectb(posX-5, posY-5, 10, 10, 14) end spr(u.grph, posX-4, posY-4, 0) if mx >= posX-4 and my >= posY-4 and mx < posX+4 and my < posY+4 then vbank(1) rectb(posX-5, posY-5, 10, 10, 2) u.w = math.max(print(u.name, w+2, h+2), print(u.desc(), w+2, h+2))+3 _, u.h = u.desc():gsub("\n", "\n") u.h = u.h*6+17+12 local infoX, infoY = posX-u.w/2, posY-u.h-6 rect(infoX, infoY, u.w, u.h, 15) rectb(infoX, infoY, u.w, u.h, 14) print(u.name, posX-print(u.name, w+2, h+2)//2, infoY+2, 12) line(infoX, infoY+8, infoX+u.w-2, infoY+8, 14) print(u.desc(), posX-print(u.desc(), w+2, h+2)//2, infoY+10, 12) line(infoX, infoY+u.h-13, infoX+u.w-2, infoY+u.h-13, 14) local buyable = true if u.bought >= u.multi then print("Bought!", posX-19, infoY+u.h-9, 12) elseif #u.cost == 0 then print("Free!", posX-13, infoY+u.h-9, 12) else local s = -2 for i,c in ipairs(u.cost) do if c ~= 0 then s=s+print(numb(c), w+2, h+2)+10 end end local cs = 0 for i,c in ipairs(u.cost) do if c ~= 0 then if resources[i] < c then buyable = false end cs=cs+print(numb(c), posX-s/2+cs, infoY+u.h-9, resources[i] < c and 1+t//15%2 or 12) spr(i+31, posX-s/2+cs, infoY+u.h-11, 0) cs=cs+10 end end end for i=1, u.multi do local l = (i-1)/u.multi pix(posX+lerp(-u.w/2+1, u.w/2-2, l), posY-8, 12) line(posX+lerp(-u.w/2+1, u.w/2-2, l)+1, posY-8, posX+lerp(-u.w/2+1, u.w/2-2, l+1/u.multi), posY-8, u.bought>=i and 2 or 1) end pix(posX+u.w/2-2, posY-8, 12) if leftp then if buyable and u.bought < u.multi then for i,c in ipairs(u.cost) do resources[i]=resources[i]-c end u.onBuy(u) for i=1, #u.cost do u.cost[i]=u.cost[i]*1.2 end u.bought=u.bought+1 pmem(i+#resources+reservedMem, u.bought) for i=1, #resources do pmem(i+reservedMem, resources[i]) end sfx(3, 48, -1, FIRE_CH, volume) else sfx(2, 48, -1, FIRE_CH, volume) end end vbank(0) end end end rect(w-40, h-7, 40, 7, 2) print("Battle!", w-39, h-6) if mx >= w-40 and my >= h-7 then rectb(w-40, h-7, 40, 7, 12) if leftp then difficulty=copy(baseDifficulty) difficulty.spawnRate=difficulty.spawnRate+levelIdx*difficultyInc.spawnRate difficulty.hp=difficulty.hp+levelIdx*difficultyInc.hp difficulty.hpSpd=difficulty.hpSpd+levelIdx*difficultyInc.hpSpd difficulty.damage=difficulty.damage+levelIdx*difficultyInc.damage difficulty.speed=difficulty.speed+levelIdx*difficultyInc.speed hp=maxHp mana=maxMana hooks["shockwave"].timesT = 1 enemies={} proj={} part={} for i,a in pairs(attacks) do a.last = -math.huge end stats={damage=0, maxdamage=0, killed=0, startResources=icopy(resources)} t=0 battle=true leftrWait=true sfx(6, 48, -1, BUTTON_CH, volume) end end spr(49, w-9, h-16, 0) if mx >= w-9 and mx <= w-1 and my >= h-16 and my <= h-8 then rectb(w-10, h-17, 10, 10, 2) if leftp then levelIdx=math.min(math.min(levelIdx+1, maxLevel), maxLevelR) sfx(5, 48, -1, BUTTON_CH, volume) end end spr(50, w-39, h-16, 0) if mx >= w-39 and mx <= w-31 and my >= h-16 and my <= h-8 then rectb(w-40, h-17, 10, 10, 2) if leftp then levelIdx=math.max(levelIdx-1, 0) sfx(5, 48, -1, BUTTON_CH, volume) end end print("Level "..(levelIdx+1), w-39, h-22, 2) --levelIdx spr(48, 1, h-9, 0) if mx < 9 and my >= h-9 then rectb(1, h-9, 8, 8, 2) if leftp then settings=not settings sfx(5, 48, -1, BUTTON_CH, volume) end end end for i=1, #resources do local s = print(numb(resources[i]), 1, i*9-4, 12) spr(i+31, s+1, i*9-5, 0) end t=t+1 end function dealDamage(i, damage) local e = enemies[i] e.hp=e.hp-damage if damage > stats.maxdamage then stats.maxdamage = damage end stats.damage=stats.damage+damage if e.hp <= 0 then stats.killed=stats.killed+1 for i=1, #e.loot do local s = #drops[i] drops[i][s+e.loot[i]*resourceMult]={} for j=1, e.loot[i]*resourceMult do local x, y = pointInSq(0, 0, e.ang, e.size) drops[i][s+j]={x=e.x+x, y=e.y+y, spd=0} end end e.onDeath(e) remove(enemies, i) end end function norm(x, y) local d = math.sqrt(x*x+y*y) return x/d, y/d end function dist(x, y, x1, y1) return math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)) end function sqDist(x, y, x1, y1) return (x-x1)*(x-x1)+(y-y1)*(y-y1) end root2 = math.sqrt(2) function collSq(px, py, x, y, ang, size) local cx, cy = rotate(px-x, py-y, -ang) return math.abs(cx) < size and math.abs(cy) < size end function circCollSq(px, py, rad, x, y, ang, size) px, py = px-x, py-y x, y = 0, 0 if px*px+py*py > size*root2*size*root2 then return false end local cx, cy = rotate(px-x, py-y, -ang) return math.abs(cx) < size+rad and math.abs(cy) < size+rad end function AABBCollSq(x, y, size, x1, y1, ang, size1) x1, y1 = x1-x, y1-y x, y = 0, 0 if x1*x1+y1*y1 > ((size+size1)*root2)*((size+size1)*root2) then return false end local rx, ry = rotate(x-x1, y-y1, -ang+math.pi) rx, ry = rx+x1, ry+y1 local trx, try = rotate(size*root2, 0, -ang) local tlx, tly = try, -trx return collSq(x+size, y+size, x1, y1, ang, size1) or collSq(x-size, y+size, x1, y1, ang, size1) or collSq(x+size, y-size, x1, y1, ang, size1) or collSq(x-size, y-size, x1, y1, ang, size1) or collSq(rx+trx, ry+try, x1, y1, 0, size1) or collSq(rx+tlx, ry+tly, x1, y1, 0, size1) or collSq(rx-trx, ry-try, x1, y1, 0, size1) or collSq(rx-tlx, ry-tly, x1, y1, 0, size1) end function drawSq(x, y, ang, size, fill, col) local trx, try = rotate(size*root2, 0, ang-math.pi/4) local tlx, tly = try, -trx tri(trx+x, try+y, tlx+x, tly+y, -trx+x, -try+y, col) tri(-trx+x, -try+y, -tlx+x, -tly+y, trx+x, try+y, col) local trx, try = rotate((size-1)*root2, 0, ang-math.pi/4) local tlx, tly = try, -trx tri(trx+x, try+y, tlx+x, tly+y, -trx+x, -try+y, 0) tri(-trx+x, -try+y, -tlx+x, -tly+y, trx+x, try+y, 0) local trx, try = rotate(size*root2, 0, ang-math.pi/4) local tlx, tly = try, -trx local try1, trx1 = lerp(-tly, try, fill), lerp(-tlx, trx, fill) local tly1, tlx1 = lerp(-try, tly, fill), lerp(-trx, tlx, fill) tri(trx1+x, try1+y, tlx1+x, tly1+y, -trx+x, -try+y, col) tri(-trx+x, -try+y, -tlx+x, -tly+y, trx1+x, try1+y, col) end function icopy(arr) local c = {} for i,e in ipairs(arr) do if type(e) == "table" then c[i]=copy(e) else c[i]=e end end return c end function copy(arr) local c = {} for i,e in pairs(arr) do if type(e) == "table" then c[i]=copy(e) else c[i]=e end end return c end function lerp(a, b, t) return a+(b-a)*t end function rotate(x, y, ang) return x*math.cos(ang)-y*math.sin(ang), y*math.cos(ang)+x*math.sin(ang) end function pointInSq(x, y, ang, size) local fx, fy = rotate(size, 0, ang) local lx, ly = fy, -fx local sx, sy = lx-fx, ly-fy fx, fy = fx*2, fy*2 lx, ly = lx*2, ly*2 local r1 = math.random() local r2 = math.random() local p1x, p1y = sx+fx*r1, sy+fy*r1 local p2x, p2y = p1x-lx*r2, p1y-ly*r2 return p2x, p2y end function remove(arr, e) if #arr == e then arr[e] = nil return end arr[e], arr[#arr] = arr[#arr], nil end