Reorganized src folder.

This commit is contained in:
2025-09-28 15:10:07 -04:00
parent c2c8d931c3
commit 023430315a
6 changed files with 7 additions and 7 deletions

46
src/utils/classes.lua Normal file
View File

@@ -0,0 +1,46 @@
------------------------------------------------------------------------------
-- Methods
------------------------------------------------------------------------------
-- Single inheritance version of the sample code from
-- http://lua-users.org/wiki/ObjectOrientationTutorial
local function make_class(BaseClass)
-- "cls" is the new class
local cls = {}
-- copy base class contents into the new class
if BaseClass ~= nil then
for k, v in pairs(BaseClass) do
cls[k] = v
end
end
-- set the class's __index, and start filling an "is_a" table that contains this class and all of its bases
-- so you can do an "instance of" check using my_instance.is_a[MyClass]
cls.__index, cls.is_a = cls, {[cls] = true}
if BaseClass ~= nil then
cls.is_a[BaseClass] = true
end
-- the class's __call metamethod
setmetatable(cls, {__call = function (c, ...)
local instance = setmetatable({}, c)
-- run the init method if it's there
local init = instance._init
if init then init(instance, ...) end
return instance
end})
-- return the new class table, that's ready to fill with methods
return cls
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return make_class

97
src/utils/fader.lua Normal file
View File

@@ -0,0 +1,97 @@
------------------------------------------------------------------------------
-- Imports
------------------------------------------------------------------------------
local love = require 'love'
local make_class = require 'src.utils.classes'
------------------------------------------------------------------------------
-- Class definitions
------------------------------------------------------------------------------
local Fader = make_class()
------------------------------------------------------------------------------
-- Class methods
------------------------------------------------------------------------------
function Fader:_init()
self.t = 0.0
self.step = 0
self.done = true
self.reverse = false
self.callback = nil
end
function Fader:_reset()
self.t = 0
self.step = 0
self.done = false
end
function Fader:fade_in(callback)
self:_reset()
self.reverse = true
self.callback = callback
end
function Fader:fade_out(callback)
self:_reset()
self.reverse = false
self.callback = callback
end
function Fader:update(dt)
if not self.done then
self.t = self.t + dt
if self.t >= 0.009 then
self.step = self.step + 1
self.t = 0.0
end
if self.step > 175 then
self.done = true
if self.callback ~= nil then
self.callback()
self.callback = nil
end
end
end
end
function Fader:draw()
local c = 0
love.graphics.setColor(0, 0, 0)
for i = 0, 16 do
for j = 0, 10 do
if not self.reverse then
if c <= self.step then
love.graphics.rectangle('fill', 20 * i, 20 * j, 20, 20)
end
else
if c <= self.step then else
love.graphics.rectangle('fill', 20 * i, 20 * j, 20, 20)
end
end
c = c + 1
end
end
love.graphics.setColor()
end
------------------------------------------------------------------------------
-- Module return
------------------------------------------------------------------------------
return Fader