2022-04-24 18:15:38 +00:00
|
|
|
import "CoreLibs/animator"
|
2022-05-14 16:34:53 +00:00
|
|
|
import "CoreLibs/animation"
|
2022-04-24 05:03:32 +00:00
|
|
|
local gfx <const> = playdate.graphics
|
|
|
|
|
2022-05-14 16:34:53 +00:00
|
|
|
local imgSaw = gfx.imagetable.new("gfx/sawblades")
|
2022-05-15 00:31:57 +00:00
|
|
|
local imgFuel = gfx.imagetable.new("gfx/fuel")
|
2022-04-24 05:03:32 +00:00
|
|
|
local imgTarget = gfx.image.new("gfx/target")
|
|
|
|
assert(imgSaw)
|
|
|
|
assert(imgTarget)
|
|
|
|
|
2022-05-14 16:34:53 +00:00
|
|
|
local loopSaws = gfx.animation.loop.new(200, imgSaw)
|
2022-05-15 00:31:57 +00:00
|
|
|
local loopFuel = gfx.animation.loop.new(400, imgFuel)
|
2022-05-14 16:34:53 +00:00
|
|
|
|
2022-04-24 05:03:32 +00:00
|
|
|
local blades = {}
|
2022-05-03 01:59:37 +00:00
|
|
|
local spinblades = {}
|
2022-05-15 00:31:57 +00:00
|
|
|
local fuels = {}
|
2022-04-24 05:03:32 +00:00
|
|
|
|
2022-07-03 19:44:11 +00:00
|
|
|
local sfxCollect = playdate.sound.sampleplayer.new("sfx/collect")
|
|
|
|
|
2022-04-24 05:03:32 +00:00
|
|
|
function loadBlades(_blades)
|
|
|
|
for i = 1, #_blades,1 do
|
|
|
|
local b = _blades[i]
|
2022-06-12 03:08:20 +00:00
|
|
|
b.start = playdate.geometry.point.new(b.start.x+8,b.start.y+8)
|
|
|
|
b.ends = playdate.geometry.point.new(b.ends.x+8,b.ends.y+8)
|
2022-05-14 16:34:53 +00:00
|
|
|
b.saw = gfx.sprite.new(loopSaws:image())
|
2022-04-24 05:03:32 +00:00
|
|
|
b.saw:moveTo(b.start)
|
2022-06-13 04:51:48 +00:00
|
|
|
b.saw:setZIndex(1)
|
2022-04-24 05:03:32 +00:00
|
|
|
b.saw:setCollideRect(0,0,16,16)
|
|
|
|
b.saw:add()
|
|
|
|
|
2022-04-24 18:15:38 +00:00
|
|
|
local a = gfx.animator.new(b.speed*1000, b.start, b.ends)
|
|
|
|
|
|
|
|
b.saw:setAnimator(a)
|
|
|
|
|
2022-04-24 05:03:32 +00:00
|
|
|
b.t1 = gfx.sprite.new(imgTarget)
|
|
|
|
b.t1:moveTo(b.start)
|
|
|
|
b.t2 = gfx.sprite.new(imgTarget)
|
|
|
|
b.t2:moveTo(b.ends)
|
|
|
|
b.t1:add()
|
|
|
|
b.t2:add()
|
|
|
|
blades[i] = b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-27 02:40:39 +00:00
|
|
|
function loadSpins(_spins)
|
|
|
|
for i = 1, #_spins, 1 do
|
|
|
|
local s = _spins[i]
|
2022-07-01 00:27:18 +00:00
|
|
|
s.x+= 8
|
|
|
|
s.y+= 8
|
2022-07-07 21:49:56 +00:00
|
|
|
|
|
|
|
s.middle = gfx.sprite.new(loopSaws:image())
|
|
|
|
s.middle:setCollideRect(0,0,16,16)
|
|
|
|
|
2022-04-27 02:40:39 +00:00
|
|
|
s.middle:moveTo(s.x,s.y)
|
2022-06-13 04:51:48 +00:00
|
|
|
s.middle:setZIndex(1)
|
2022-04-27 02:40:39 +00:00
|
|
|
s.middle:add()
|
2022-05-01 18:04:14 +00:00
|
|
|
|
2022-07-08 03:18:08 +00:00
|
|
|
local sb = {speed=s.speed,arms={},mid=s.middle,time=0}
|
2022-07-10 07:45:39 +00:00
|
|
|
--[[local sb = {speed=s.speed,layers={},time=0}
|
2022-07-07 21:49:56 +00:00
|
|
|
|
2022-07-10 07:45:39 +00:00
|
|
|
for len = 1, s.armlen, 1 do
|
2022-07-08 03:18:08 +00:00
|
|
|
local arc = playdate.geometry.arc.new(s.x,s.y, 20 * len, -720, 720)
|
2022-07-10 07:45:39 +00:00
|
|
|
|
|
|
|
sb.layers[#sb.layers+1] = {curve=arc,saws={}}
|
2022-07-07 21:49:56 +00:00
|
|
|
|
|
|
|
for arm = 1, s.arms, 1 do
|
|
|
|
local saw = gfx.sprite.new(loopSaws:image())
|
2022-07-07 22:03:18 +00:00
|
|
|
local sawPos = arc:pointOnArc(360 / s.arms * arm)
|
2022-07-07 21:49:56 +00:00
|
|
|
|
|
|
|
saw:moveTo(sawPos.x,sawPos.y)
|
|
|
|
saw:add()
|
|
|
|
|
2022-07-10 07:45:39 +00:00
|
|
|
sb.layers[#sb.layers].saws[#sb.layers[#sb.layers].saws+1] = saw
|
2022-07-07 21:49:56 +00:00
|
|
|
end
|
2022-07-10 07:45:39 +00:00
|
|
|
end
|
2022-07-07 21:49:56 +00:00
|
|
|
|
2022-07-10 07:45:39 +00:00
|
|
|
spinblades[#spinblades+1] = sb]]
|
2022-07-07 21:49:56 +00:00
|
|
|
|
2022-07-10 07:45:39 +00:00
|
|
|
|
2022-07-08 03:18:08 +00:00
|
|
|
for i = 1, s.arms, 1 do
|
2022-05-08 17:52:50 +00:00
|
|
|
sb.arms[i] = {}
|
2022-05-01 18:04:14 +00:00
|
|
|
for p = 1, s.armlen, 1 do
|
2022-05-01 18:15:05 +00:00
|
|
|
local degrees = (360 / s.arms) * i
|
|
|
|
local position = {x=math.sin(math.rad(degrees)) * 20 * p,y=math.cos(math.rad(degrees)) * 20 * p}
|
2022-05-01 18:04:14 +00:00
|
|
|
|
2022-05-14 16:34:53 +00:00
|
|
|
sb.arms[i][p] = gfx.sprite.new(loopSaws:image())
|
2022-05-08 17:52:50 +00:00
|
|
|
sb.arms[i][p]:moveTo(s.x + position.x, s.y + position.y)
|
|
|
|
sb.arms[i][p]:setCollideRect(0,0,16,16)
|
2022-06-13 04:51:48 +00:00
|
|
|
sb.arms[i][p]:setZIndex(1)
|
2022-05-08 17:52:50 +00:00
|
|
|
sb.arms[i][p]:add()
|
2022-05-01 18:04:14 +00:00
|
|
|
end
|
2022-07-08 03:18:08 +00:00
|
|
|
end
|
2022-05-03 01:59:37 +00:00
|
|
|
spinblades[#spinblades+1] = sb
|
2022-04-27 02:40:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-15 00:31:57 +00:00
|
|
|
function loadFuel(_fuel)
|
|
|
|
|
|
|
|
for i = 1, #_fuel, 1 do
|
|
|
|
local fuel = _fuel[i]
|
|
|
|
fuels[i] = gfx.sprite.new()
|
2022-05-29 05:53:46 +00:00
|
|
|
fuels[i]:moveTo(fuel.x+15,fuel.y+15)
|
2022-05-15 00:31:57 +00:00
|
|
|
fuels[i]:setGroups({2})
|
2022-05-29 05:53:46 +00:00
|
|
|
fuels[i]:setCollidesWithGroups({3})
|
2022-05-15 00:31:57 +00:00
|
|
|
fuels[i].active = true
|
2022-06-13 04:51:48 +00:00
|
|
|
fuels[i]:setZIndex(2)
|
2022-05-18 05:09:02 +00:00
|
|
|
fuels[i]:setCollideRect(-6,-6 ,30,30)
|
2022-05-15 00:31:57 +00:00
|
|
|
fuels[i]:add()
|
|
|
|
|
|
|
|
totalEnergy += 1
|
|
|
|
showEnergy = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-24 18:15:38 +00:00
|
|
|
function updateSaws()
|
2022-05-18 05:09:02 +00:00
|
|
|
local ox, oy = gfx.getDrawOffset()
|
2022-05-15 00:31:57 +00:00
|
|
|
for fuel = 1, #fuels, 1 do
|
|
|
|
fuels[fuel]:setImage(loopFuel:image())
|
2022-05-18 05:09:02 +00:00
|
|
|
if #fuels[fuel]:overlappingSprites() > 0 and fuels[fuel].active then
|
2022-05-15 00:31:57 +00:00
|
|
|
fuels[fuel].active = false
|
2022-07-02 05:03:59 +00:00
|
|
|
miniExplode(fuels[fuel].x,fuels[fuel].y)
|
2022-05-15 00:31:57 +00:00
|
|
|
fuels[fuel]:remove()
|
|
|
|
energy += 1
|
2022-07-02 05:03:59 +00:00
|
|
|
table.remove(fuels,fuel)
|
2022-07-03 19:44:11 +00:00
|
|
|
sfxCollect:play()
|
2022-07-02 05:03:59 +00:00
|
|
|
break
|
2022-05-15 00:31:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-24 18:15:38 +00:00
|
|
|
for b=1, #blades, 1 do
|
|
|
|
b = blades[b]
|
2022-05-14 16:34:53 +00:00
|
|
|
b.saw:setImage(loopSaws:image())
|
2022-04-24 18:15:38 +00:00
|
|
|
local pos = playdate.geometry.point.new(b.saw:getPosition())
|
|
|
|
if pos == b.start then
|
|
|
|
local a = gfx.animator.new(b.speed*1000, b.start, b.ends)
|
|
|
|
|
|
|
|
b.saw:setAnimator(a)
|
|
|
|
elseif pos == b.ends then
|
|
|
|
local a = gfx.animator.new(b.speed*1000, b.ends, b.start)
|
|
|
|
|
|
|
|
b.saw:setAnimator(a)
|
|
|
|
end
|
|
|
|
end
|
2022-05-08 17:31:53 +00:00
|
|
|
|
2022-07-07 21:49:56 +00:00
|
|
|
--{speed=s.speed,arms=s.arms,armlen=s.armlen,saws = {},arcs = {},time=0}
|
2022-07-08 03:18:08 +00:00
|
|
|
--[[for spinner = 1, #spinblades, 1 do
|
2022-07-07 21:49:56 +00:00
|
|
|
local s = spinblades[spinner]
|
|
|
|
|
|
|
|
s.time += s.speed
|
|
|
|
print(s.time)
|
|
|
|
|
2022-07-10 07:45:39 +00:00
|
|
|
for len = 1, #s.layers, 1 do
|
|
|
|
local arc = s.layers[len].curve
|
2022-07-07 21:49:56 +00:00
|
|
|
|
2022-07-10 07:45:39 +00:00
|
|
|
for arm = 1, #s.layers[len].saws, 1 do
|
|
|
|
local sawPos = arc:pointOnArc(arc:length() / 4 / #s.layers[len].saws * arm + (s.time * len))
|
|
|
|
if s.time > 125 * #s.layers[len].saws or s.time < -125 * #s.layers[len].saws then s.time = 0 end
|
2022-07-07 21:49:56 +00:00
|
|
|
|
2022-07-10 07:45:39 +00:00
|
|
|
s.layers[len].saws[arm]:moveTo(sawPos.x,sawPos.y)
|
2022-07-07 21:49:56 +00:00
|
|
|
end
|
|
|
|
end
|
2022-07-08 03:18:08 +00:00
|
|
|
end]]
|
|
|
|
for spinner = 1, #spinblades, 1 do
|
2022-05-08 20:44:59 +00:00
|
|
|
for arm = 1, #spinblades[spinner].arms do
|
|
|
|
for blade = 1, #spinblades[spinner].arms[arm] do
|
2022-05-09 04:31:57 +00:00
|
|
|
|
2022-05-08 20:44:59 +00:00
|
|
|
spinblades[spinner].time += spinblades[spinner].speed
|
2022-05-09 04:31:57 +00:00
|
|
|
|
2022-05-08 20:50:34 +00:00
|
|
|
local degrees = (360 / #spinblades[spinner].arms * arm + spinblades[spinner].time)
|
2022-07-08 06:01:15 +00:00
|
|
|
--if degrees % 360 == 0 then spinblades[spinner].time = 0 end
|
|
|
|
|
2022-05-14 16:34:53 +00:00
|
|
|
spinblades[spinner].arms[arm][blade]:setImage(loopSaws:image())
|
2022-07-08 06:01:15 +00:00
|
|
|
spinblades[spinner].arms[arm][blade]:moveTo(spinblades[spinner].mid.x + math.sin(math.rad(degrees)) * 20 * blade, spinblades[spinner].mid.y + math.cos(math.rad(degrees)) * 20 * blade)
|
2022-05-08 20:44:59 +00:00
|
|
|
end
|
|
|
|
end
|
2022-07-08 03:18:08 +00:00
|
|
|
end
|
2022-04-24 18:15:38 +00:00
|
|
|
end
|
|
|
|
|
2022-04-24 05:03:32 +00:00
|
|
|
function killBlades()
|
2022-05-15 00:31:57 +00:00
|
|
|
for fuel = 1, #fuels, 1 do
|
|
|
|
fuels[fuel]:remove()
|
|
|
|
end
|
|
|
|
fuels = {}
|
|
|
|
|
2022-04-24 05:03:32 +00:00
|
|
|
for i = 1, #blades, 1 do
|
|
|
|
blades[i].t1:remove()
|
|
|
|
blades[i].t2:remove()
|
|
|
|
blades[i].saw:remove()
|
|
|
|
end
|
|
|
|
blades = {}
|
2022-05-08 05:40:21 +00:00
|
|
|
|
|
|
|
for i = 1, #spinblades, 1 do
|
|
|
|
spinblades[i].mid:remove()
|
2022-05-08 17:52:50 +00:00
|
|
|
for arm = 1, #spinblades[i].arms do
|
|
|
|
for blade = 1, #spinblades[i].arms[arm] do
|
|
|
|
spinblades[i].arms[arm][blade]:remove()
|
|
|
|
end
|
2022-05-08 05:40:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
spinblades = {}
|
2022-04-24 05:03:32 +00:00
|
|
|
end
|