reworked spinner loading and removal

This commit is contained in:
PossiblyAxolotl 2022-05-08 11:52:50 -06:00
parent c336d45261
commit 3f7b1b18e6

View file

@ -45,16 +45,17 @@ function loadSpins(_spins)
s.middle:moveTo(s.x,s.y)
s.middle:add()
local sb = {speed=s.speed,arms=s.arms,armlen=s.armlen,blades={},mid=s.middle,time=0}
local sb = {speed=s.speed,arms={},mid=s.middle,time=0}
for i = 1, s.arms, 1 do
sb.arms[i] = {}
for p = 1, s.armlen, 1 do
local degrees = (360 / s.arms) * i
local position = {x=math.sin(math.rad(degrees)) * 20 * p,y=math.cos(math.rad(degrees)) * 20 * p}
sb.blades[#sb.blades+1] = gfx.sprite.new(imgSaw)
sb.blades[#sb.blades]:moveTo(s.x + position.x, s.y + position.y)
sb.blades[#sb.blades]:setCollideRect(0,0,16,16)
sb.blades[#sb.blades]:add()
sb.arms[i][p] = gfx.sprite.new(imgSaw)
sb.arms[i][p]:moveTo(s.x + position.x, s.y + position.y)
sb.arms[i][p]:setCollideRect(0,0,16,16)
sb.arms[i][p]:add()
end
end
spinblades[#spinblades+1] = sb
@ -76,18 +77,7 @@ function updateSaws()
end
end
for spinner = 1, #spinblades, 1 do
for arm = 1, spinblades[spinner].arms do
for armlen = 1, spinblades[spinner].armlen do
for blade = 1, #spinblades[spinner].blades do
spinblades[spinner].time += spinblades[spinner].speed
local degrees = spinblades[spinner].time / 360 * arm
local newpos = {x=math.sin(math.rad(degrees)) * 20 * armlen,y=math.cos(math.rad(degrees)) * 20 * armlen}
spinblades[spinner].blades[blade]:moveTo(spinblades[spinner].mid.x + newpos.x, spinblades[spinner].mid.y + newpos.y)
end
end
end
end
printTable(spinblades)
end
function killBlades()
@ -100,8 +90,10 @@ function killBlades()
for i = 1, #spinblades, 1 do
spinblades[i].mid:remove()
for b = 1, #spinblades[i].blades do
spinblades[i].blades[b]:remove()
for arm = 1, #spinblades[i].arms do
for blade = 1, #spinblades[i].arms[arm] do
spinblades[i].arms[arm][blade]:remove()
end
end
end