Add class Entity
This commit is contained in:
parent
cd5bdaa59f
commit
7509698888
1 changed files with 29 additions and 0 deletions
29
cf-lib/data/Entity.lua
Normal file
29
cf-lib/data/Entity.lua
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue