Add class Entity

This commit is contained in:
Simon Brodtmann 2025-12-13 00:33:11 +01:00
parent cd5bdaa59f
commit 7509698888

29
cf-lib/data/Entity.lua Normal file
View file

@ -0,0 +1,29 @@
--- Utility class for entity prototype definitions
--- @class Entity
local Entity = {}
--- Generates a selection box definition using width and height of the entity in tiles.
--- @param width number The width of the entity in tiles
--- @param height number The height of the entity in tiles
--- @return table A table containing the selection box definition
Entity.selectionBox = function(width, height)
return {
{ -width / 2, -height / 2 },
{ width / 2, height / 2 }
}
end
--- Generates a collision box definition using width and height of the entity in tiles.
--- @param width number The width of the entity in tiles
--- @param height number The height of the entity in tiles
--- @param margin number The margin to apply to the collision box compared to the selection box (default: 0.3)
--- @return table A table containing the collision box definition
Entity.collisionBox = function(width, height, margin)
margin = margin or 0.1
return {
{ -width / 2 + margin, -height / 2 + margin },
{ width / 2 - margin, height / 2 - margin }
}
end
return Entity