add current stuff yeha
This commit is contained in:
parent
2744423cda
commit
ae65683e44
81 changed files with 962 additions and 0 deletions
84
lib/assets.lua
Normal file
84
lib/assets.lua
Normal file
|
@ -0,0 +1,84 @@
|
|||
local assets = {}
|
||||
|
||||
function assets.clear()
|
||||
print("ℹ️ clearing assets")
|
||||
|
||||
sprites = {}
|
||||
sound_path = {}
|
||||
music_path = {}
|
||||
end
|
||||
|
||||
function assets.load(base)
|
||||
print("ℹ️ loading " .. base)
|
||||
|
||||
assets.addSprites(base)
|
||||
print("✓ added sprites")
|
||||
|
||||
assets.addAudio(base)
|
||||
print("✓ added audio")
|
||||
end
|
||||
|
||||
function assets.addSprites(base, d)
|
||||
local dir = base.."/sprites"
|
||||
if d then
|
||||
dir = dir .. "/" .. d
|
||||
end
|
||||
local files = love.filesystem.getDirectoryItems(dir)
|
||||
for _,file in ipairs(files) do
|
||||
if string.sub(file, -4) == ".png" then
|
||||
local spritename = string.sub(file, 1, -5)
|
||||
local sprite = love.graphics.newImage(dir .. "/" .. file)
|
||||
if d then
|
||||
spritename = d .. "/" .. spritename
|
||||
end
|
||||
sprites[spritename] = sprite
|
||||
--print(colr.cyan("ℹ️ added sprite "..spritename))
|
||||
elseif love.filesystem.getInfo(dir .. "/" .. file).type == "directory" then
|
||||
--print(colr.cyan("ℹ️ found sprite dir: " .. file))
|
||||
local newdir = file
|
||||
if d then
|
||||
newdir = d .. "/" .. newdir
|
||||
end
|
||||
assets.addSprites(base, newdir)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function assets.addAudio(base, d, type)
|
||||
local dir = base.."/audio"
|
||||
if d then
|
||||
dir = dir .. "/" .. d
|
||||
end
|
||||
local files = love.filesystem.getDirectoryItems(dir)
|
||||
for _,file in ipairs(files) do
|
||||
if love.filesystem.getInfo(dir .. "/" .. file).type == "directory" then
|
||||
local newdir = file
|
||||
if d then
|
||||
newdir = d .. "/" .. newdir
|
||||
end
|
||||
assets.addAudio(base, newdir, type or file)
|
||||
else
|
||||
local audioname = file
|
||||
if file:ends(".wav") then audioname = file:sub(1, -5) end
|
||||
if file:ends(".mp3") then audioname = file:sub(1, -5) end
|
||||
if file:ends(".ogg") then audioname = file:sub(1, -5) end
|
||||
if file:ends(".flac") then audioname = file:sub(1, -5) end
|
||||
if file:ends(".xm") then audioname = file:sub(1, -4) end
|
||||
--[[if d then
|
||||
audioname = d .. "/" .. audioname
|
||||
end]]
|
||||
if type == "sfx" then
|
||||
sound_path[audioname] = dir .. "/" .. file
|
||||
|
||||
if sounds and sounds[audioname] then
|
||||
registerSound(audioname, sounds[audioname].volume)
|
||||
end
|
||||
elseif type == "bgm" then
|
||||
music_path[audioname] = dir .. "/" .. file
|
||||
end
|
||||
--print("ℹ️ audio "..audioname.." added")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return assets
|
88
lib/benchmark.lua
Normal file
88
lib/benchmark.lua
Normal file
|
@ -0,0 +1,88 @@
|
|||
local this = {}
|
||||
|
||||
local updateLimit = 50
|
||||
|
||||
local benchmarkingThings = {}
|
||||
|
||||
local latestBenchmark = {}
|
||||
local doneBench = {}
|
||||
|
||||
local function shrt(num)
|
||||
return math.floor(num * 10000) / 10000
|
||||
end
|
||||
|
||||
this.update = function()
|
||||
doneBench = {}
|
||||
end
|
||||
|
||||
this.startBenchmark = function(name)
|
||||
latestBenchmark[name] = love.timer.getTime()
|
||||
end
|
||||
|
||||
this.stopBenchmark = function(name)
|
||||
if not benchmarkingThings[name] then benchmarkingThings[name] = {} end
|
||||
|
||||
if doneBench[name] then
|
||||
local tbl = benchmarkingThings[name]
|
||||
tbl[#tbl] = tbl[#tbl] + love.timer.getTime() - latestBenchmark[name]
|
||||
else
|
||||
table.insert(benchmarkingThings[name], love.timer.getTime() - latestBenchmark[name])
|
||||
end
|
||||
|
||||
doneBench[name] = true
|
||||
if #benchmarkingThings[name] > updateLimit then table.remove(benchmarkingThings[name], 1) end
|
||||
end
|
||||
|
||||
this.getAverage = function(name)
|
||||
local things
|
||||
if name then
|
||||
things = benchmarkingThings[name]
|
||||
else
|
||||
things = {}
|
||||
for key in pairs(this.benchmarks) do
|
||||
for _,n in ipairs(benchmarkingThings[key]) do
|
||||
table.insert(things, n)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local total = 0
|
||||
for _,n in ipairs(things) do
|
||||
total = total + n
|
||||
end
|
||||
|
||||
return total / #things
|
||||
end
|
||||
|
||||
this.renderBenchmark = function()
|
||||
local font = love.graphics.getFont()
|
||||
local result = ''
|
||||
local rowNum = 0
|
||||
|
||||
local averages = {}
|
||||
local max = 0
|
||||
|
||||
for n,_ in pairs(this.benchmarks) do
|
||||
local average = this.getAverage(n)
|
||||
max = math.max(average, max)
|
||||
averages[n] = average
|
||||
end
|
||||
for n,_ in pairs(this.benchmarks) do
|
||||
local average = averages[n]
|
||||
result = result .. '\n' .. shrt(average) .. 'ms' .. ' ' .. n
|
||||
rowNum = rowNum + 1
|
||||
|
||||
local yoff = rowNum * font:getHeight()
|
||||
|
||||
love.graphics.setColor(1, 1, 1, 0.7)
|
||||
|
||||
love.graphics.rectangle('fill', 0, yoff, average * 1/max * love.graphics.getWidth(), font:getHeight())
|
||||
end
|
||||
|
||||
love.graphics.setColor(0, 0, 0)
|
||||
love.graphics.print(result)
|
||||
end
|
||||
|
||||
this.benchmarks = benchmarkingThings
|
||||
|
||||
return this
|
140
lib/ease.lua
Normal file
140
lib/ease.lua
Normal file
|
@ -0,0 +1,140 @@
|
|||
local this = {}
|
||||
|
||||
local sqrt = math.sqrt
|
||||
local sin = math.sin
|
||||
local cos = math.cos
|
||||
local pow = math.pow
|
||||
local exp = math.exp
|
||||
local pi = math.pi
|
||||
local abs = math.abs
|
||||
|
||||
function this.linear(t) return t end
|
||||
function this.inQuad(t) return t * t end
|
||||
function this.outQuad(t) return -t * (t - 2) end
|
||||
function this.inOutQuad(t)
|
||||
t = t * 2
|
||||
if t < 1 then
|
||||
return 0.5 * t ^ 2
|
||||
else
|
||||
return 1 - 0.5 * (2 - t) ^ 2
|
||||
end
|
||||
end
|
||||
function this.inCubic(t) return t * t * t end
|
||||
function this.outCubic(t) return 1 - (1 - t) ^ 3 end
|
||||
function this.inOutCubic(t)
|
||||
t = t * 2
|
||||
if t < 1 then
|
||||
return 0.5 * t ^ 3
|
||||
else
|
||||
return 1 - 0.5 * (2 - t) ^ 3
|
||||
end
|
||||
end
|
||||
function this.inQuart(t) return t * t * t * t end
|
||||
function this.outQuart(t) return 1 - (1 - t) ^ 4 end
|
||||
function this.inOutQuart(t)
|
||||
t = t * 2
|
||||
if t < 1 then
|
||||
return 0.5 * t ^ 4
|
||||
else
|
||||
return 1 - 0.5 * (2 - t) ^ 4
|
||||
end
|
||||
end
|
||||
function this.inQuint(t) return t ^ 5 end
|
||||
function this.outQuint(t) return 1 - (1 - t) ^ 5 end
|
||||
function this.inOutQuint(t)
|
||||
t = t * 2
|
||||
if t < 1 then
|
||||
return 0.5 * t ^ 5
|
||||
else
|
||||
return 1 - 0.5 * (2 - t) ^ 5
|
||||
end
|
||||
end
|
||||
function this.inExpo(t) return 1000 ^ (t - 1) - 0.001 end
|
||||
function this.outExpo(t) return 0.999 - 1000 ^ -t end
|
||||
function this.inOutExpo(t)
|
||||
t = t * 2
|
||||
if t < 1 then
|
||||
return 0.5 * 1000 ^ (t - 1) - 0.0005
|
||||
else
|
||||
return 0.9995 - 0.5 * 1000 ^ (1 - t)
|
||||
end
|
||||
end
|
||||
function this.inCirc(t) return 1 - sqrt(1 - t * t) end
|
||||
function this.outCirc(t) return sqrt(-t * t + 2 * t) end
|
||||
function this.inOutCirc(t)
|
||||
t = t * 2
|
||||
if t < 1 then
|
||||
return 0.5 - 0.5 * sqrt(1 - t * t)
|
||||
else
|
||||
t = t - 2
|
||||
return 0.5 + 0.5 * sqrt(1 - t * t)
|
||||
end
|
||||
end
|
||||
|
||||
function this.inElastic(t)
|
||||
t = t - 1
|
||||
return -(pow(2, 10 * t) * sin((t - 0.075) * (2 * pi) / 0.3))
|
||||
end
|
||||
function this.outElastic(t)
|
||||
return pow(2, -10 * t) * sin((t - 0.075) * (2 * pi) / 0.3) + 1
|
||||
end
|
||||
function this.inOutElastic(t)
|
||||
t = t * 2 - 1
|
||||
if t < 0 then
|
||||
return -0.5 * pow(2, 10 * t) * sin((t - 0.1125) * 2 * pi / 0.45)
|
||||
else
|
||||
return pow(2, -10 * t) * sin((t - 0.1125) * 2 * pi / 0.45) * 0.5 + 1
|
||||
end
|
||||
end
|
||||
|
||||
function this.inBack(t) return t * t * (2.70158 * t - 1.70158) end
|
||||
function this.outBack(t)
|
||||
t = t - 1
|
||||
return (t * t * (2.70158 * t + 1.70158)) + 1
|
||||
end
|
||||
function this.inOutBack(t)
|
||||
t = t * 2
|
||||
if t < 1 then
|
||||
return 0.5 * (t * t * (3.5864016 * t - 2.5864016))
|
||||
else
|
||||
t = t - 2
|
||||
return 0.5 * (t * t * (3.5864016 * t + 2.5864016) + 2)
|
||||
end
|
||||
end
|
||||
|
||||
function this.outBounce(t)
|
||||
if t < 1 / 2.75 then
|
||||
return 7.5625 * t * t
|
||||
elseif t < 2 / 2.75 then
|
||||
t = t - 1.5 / 2.75
|
||||
return 7.5625 * t * t + 0.75
|
||||
elseif t < 2.5 / 2.75 then
|
||||
t = t - 2.25 / 2.75
|
||||
return 7.5625 * t * t + 0.9375
|
||||
else
|
||||
t = t - 2.625 / 2.75
|
||||
return 7.5625 * t * t + 0.984375
|
||||
end
|
||||
end
|
||||
function this.inBounce(t) return 1 - this.outBounce(1 - t) end
|
||||
function this.inOutBounce(t)
|
||||
if t < 0.5 then
|
||||
return this.inBounce(t * 2) * 0.5
|
||||
else
|
||||
return this.outBounce(t * 2 - 1) * 0.5 + 0.5
|
||||
end
|
||||
end
|
||||
|
||||
function this.inSine(x)
|
||||
return 1 - cos(x * (pi * 0.5))
|
||||
end
|
||||
|
||||
function this.outSine(x)
|
||||
return sin(x * (pi * 0.5))
|
||||
end
|
||||
|
||||
function this.inOutSine(x)
|
||||
return 0.5 - 0.5 * cos(x * pi)
|
||||
end
|
||||
|
||||
return this
|
Loading…
Add table
Add a link
Reference in a new issue