From 15245aff28022c167b5384f164ad3bf6f5cf60b4 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sun, 5 Mar 2023 21:20:21 +0000 Subject: docs: add missing function docs --- raccoon.lua | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/raccoon.lua b/raccoon.lua index 3b6f233..0ada342 100644 --- a/raccoon.lua +++ b/raccoon.lua @@ -5,11 +5,9 @@ -- input: keyboard -- TODO --- Enemies move (quite fast) towards target (FixedPOI, MovingPOI) and have health (hitpoints) --- Enemies fly when hit (out of screen when killed) --- DrawManager should only draw those entities that are on screen (or is it not necessary?) -- Add width/height to Pos component -- Extend to 4 action buttons +-- Call math.randomseed (x) in an init function --- Utility functions -- @section Utility functions @@ -20,6 +18,9 @@ local util = { } } +--- Returns the sign of an integer +-- @param n the input integer +-- @return -1 if negative, 1 if positive, 0 if 0 function util.signum(n) if n < 0 then return -1 @@ -30,12 +31,19 @@ function util.signum(n) end end +--- Returns the number of entries in a table +-- @param t the input table function util.size(t) local count = 0 for _,_ in pairs(t) do count = count + 1 end return count end +--- Returns the euclidean distance between 2D points +-- @param p1 the first point +-- @param p2 the second point +-- @return the euclidean distance between the points +-- @return the vector of differences in the 2 axes function util.distance(p1,p2) local vec = { p2.x - p1.x, p2.y - p1.y } return math.sqrt(math.pow(vec[1], 2) + math.pow(vec[2], 2)), vec @@ -187,7 +195,6 @@ function System:init(...) end if selected then local rm, cmps = self:exec(entity, ...) - -- TODO: handle entity/component removal if rm then if cmps then -- Remove components from entity @@ -631,6 +638,14 @@ local game = { } } +local Debug = { t = 0 } +function Debug:print(game) + self.t = self.t + 1 + if self.t % 60 == 0 then + trace("Entities: " .. util.size(game.entities)) + end +end + function TIC() cls(0) @@ -644,6 +659,8 @@ function TIC() LevelSystem:run(game.levels, game) DrawingSystem:draw(game) + + --Debug:print(game) end --- TIC-80 resources. -- cgit v1.2.3