Rocket-Bytes/Source/Saws.lua

200 lines
5.9 KiB
Lua
Raw Normal View History

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 = {}
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)
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]
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)
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}
--local sb = {speed=s.speed,arms=s.arms,armlen=s.armlen,saws = {},arcs = {},time=0}
2022-07-07 21:49:56 +00:00
2022-07-08 03:18:08 +00:00
--[[for len = 1, s.armlen, 1 do
local arc = playdate.geometry.arc.new(s.x,s.y, 20 * len, -720, 720)
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()
sb.saws[#sb.saws+1] = saw
end
sb.arcs[#sb.arcs+1] = arc
2022-07-08 03:18:08 +00:00
end]]
2022-07-07 21:49:56 +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)
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
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()
fuels[i]:moveTo(fuel.x+15,fuel.y+15)
2022-05-15 00:31:57 +00:00
fuels[i]:setGroups({2})
fuels[i]:setCollidesWithGroups({3})
2022-05-15 00:31:57 +00:00
fuels[i].active = true
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)
for len = 1, s.armlen, 1 do
local arc = s.arcs[len]
for arm = 1, s.arms, 1 do
2022-07-08 03:18:08 +00:00
local sawPos = arc:pointOnArc(arc:length() / 4 / s.arms * arm + (s.time * len))
if s.time > 125 * s.arms or s.time < -125 * s.arms then s.time = 0 end
2022-07-07 21:49:56 +00:00
2022-07-08 03:18:08 +00:00
s.saws[arm+((len)*(arm-1))]: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
local degrees = (360 / #spinblades[spinner].arms * arm + spinblades[spinner].time)
2022-06-16 23:24:35 +00:00
if degrees % 360 == 0 then spinblades[spinner].time = 0 end
2022-05-08 20:44:59 +00:00
local position = {x=math.sin(math.rad(degrees)) * 20 * blade,y=math.cos(math.rad(degrees)) * 20 * blade}
2022-05-14 16:34:53 +00:00
spinblades[spinner].arms[arm][blade]:setImage(loopSaws:image())
2022-05-08 20:44:59 +00:00
spinblades[spinner].arms[arm][blade]:moveTo(spinblades[spinner].mid.x + position.x, spinblades[spinner].mid.y + position.y)
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