refactoring
This commit is contained in:
parent
bee71fe254
commit
f421771926
@ -1,4 +1,4 @@
|
|||||||
local utils = require("utils")
|
local utils = require "lib/utils"
|
||||||
|
|
||||||
---Generates an empty grid
|
---Generates an empty grid
|
||||||
---@param width number
|
---@param width number
|
||||||
|
|||||||
@ -1,5 +1,25 @@
|
|||||||
|
local utils = require "lib/utils"
|
||||||
|
local camera = require "lib/camera"
|
||||||
|
|
||||||
|
--- @class Level
|
||||||
|
--- @field characters Character[]
|
||||||
|
--- @field camera Camera
|
||||||
|
local level = {}
|
||||||
|
level.__index = level
|
||||||
|
|
||||||
local function new()
|
local function new()
|
||||||
return {
|
return setmetatable({
|
||||||
characters = {}
|
characters = {},
|
||||||
}
|
camera = camera.new()
|
||||||
|
}, level)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function level:update(dt)
|
||||||
|
utils.each(self.characters, function(el)
|
||||||
|
el:update(dt)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
new = new
|
||||||
|
}
|
||||||
|
|||||||
@ -16,8 +16,21 @@ function P.generateList(count, generator)
|
|||||||
return xs
|
return xs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the sign of a number
|
||||||
|
--- @param number number
|
||||||
|
--- @return -1 | 0 | 1
|
||||||
function P.sign(number)
|
function P.sign(number)
|
||||||
return (number > 0 and 1) or (number == 0 and 0) or -1
|
return (number > 0 and 1) or (number == 0 and 0) or -1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Applies a side effect for each element of a table
|
||||||
|
--- @generic T
|
||||||
|
--- @param table {[any] : T}
|
||||||
|
--- @param fn fun(el: T): nil
|
||||||
|
function P.each(table, fn)
|
||||||
|
for _, value in ipairs(table) do
|
||||||
|
fn(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return P
|
return P
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user