From 75096988888b513d3b3b2ee37e2847281c59fcfa Mon Sep 17 00:00:00 2001 From: Simon Brodtmann Date: Sat, 13 Dec 2025 00:33:11 +0100 Subject: [PATCH] Add class Entity --- cf-lib/data/Entity.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cf-lib/data/Entity.lua diff --git a/cf-lib/data/Entity.lua b/cf-lib/data/Entity.lua new file mode 100644 index 0000000..4a21072 --- /dev/null +++ b/cf-lib/data/Entity.lua @@ -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 \ No newline at end of file