diff options
author | Federico Igne <git@federicoigne.com> | 2023-03-05 21:20:21 +0000 |
---|---|---|
committer | Federico Igne <git@federicoigne.com> | 2023-03-05 21:20:21 +0000 |
commit | 15245aff28022c167b5384f164ad3bf6f5cf60b4 (patch) | |
tree | 5c7c32bc14371b01a58ce66661a23031f3de815c | |
parent | a140a82cf417aec63fbe4f2430a8e272f4d5a254 (diff) | |
download | raccoon-15245aff28022c167b5384f164ad3bf6f5cf60b4.tar.gz raccoon-15245aff28022c167b5384f164ad3bf6f5cf60b4.zip |
docs: add missing function docs
-rw-r--r-- | raccoon.lua | 25 |
1 files 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 @@ | |||
5 | -- input: keyboard | 5 | -- input: keyboard |
6 | 6 | ||
7 | -- TODO | 7 | -- TODO |
8 | -- Enemies move (quite fast) towards target (FixedPOI, MovingPOI) and have health (hitpoints) | ||
9 | -- Enemies fly when hit (out of screen when killed) | ||
10 | -- DrawManager should only draw those entities that are on screen (or is it not necessary?) | ||
11 | -- Add width/height to Pos component | 8 | -- Add width/height to Pos component |
12 | -- Extend to 4 action buttons | 9 | -- Extend to 4 action buttons |
10 | -- Call math.randomseed (x) in an init function | ||
13 | 11 | ||
14 | --- Utility functions | 12 | --- Utility functions |
15 | -- @section Utility functions | 13 | -- @section Utility functions |
@@ -20,6 +18,9 @@ local util = { | |||
20 | } | 18 | } |
21 | } | 19 | } |
22 | 20 | ||
21 | --- Returns the sign of an integer | ||
22 | -- @param n the input integer | ||
23 | -- @return -1 if negative, 1 if positive, 0 if 0 | ||
23 | function util.signum(n) | 24 | function util.signum(n) |
24 | if n < 0 then | 25 | if n < 0 then |
25 | return -1 | 26 | return -1 |
@@ -30,12 +31,19 @@ function util.signum(n) | |||
30 | end | 31 | end |
31 | end | 32 | end |
32 | 33 | ||
34 | --- Returns the number of entries in a table | ||
35 | -- @param t the input table | ||
33 | function util.size(t) | 36 | function util.size(t) |
34 | local count = 0 | 37 | local count = 0 |
35 | for _,_ in pairs(t) do count = count + 1 end | 38 | for _,_ in pairs(t) do count = count + 1 end |
36 | return count | 39 | return count |
37 | end | 40 | end |
38 | 41 | ||
42 | --- Returns the euclidean distance between 2D points | ||
43 | -- @param p1 the first point | ||
44 | -- @param p2 the second point | ||
45 | -- @return the euclidean distance between the points | ||
46 | -- @return the vector of differences in the 2 axes | ||
39 | function util.distance(p1,p2) | 47 | function util.distance(p1,p2) |
40 | local vec = { p2.x - p1.x, p2.y - p1.y } | 48 | local vec = { p2.x - p1.x, p2.y - p1.y } |
41 | return math.sqrt(math.pow(vec[1], 2) + math.pow(vec[2], 2)), vec | 49 | return math.sqrt(math.pow(vec[1], 2) + math.pow(vec[2], 2)), vec |
@@ -187,7 +195,6 @@ function System:init(...) | |||
187 | end | 195 | end |
188 | if selected then | 196 | if selected then |
189 | local rm, cmps = self:exec(entity, ...) | 197 | local rm, cmps = self:exec(entity, ...) |
190 | -- TODO: handle entity/component removal | ||
191 | if rm then | 198 | if rm then |
192 | if cmps then | 199 | if cmps then |
193 | -- Remove components from entity | 200 | -- Remove components from entity |
@@ -631,6 +638,14 @@ local game = { | |||
631 | } | 638 | } |
632 | } | 639 | } |
633 | 640 | ||
641 | local Debug = { t = 0 } | ||
642 | function Debug:print(game) | ||
643 | self.t = self.t + 1 | ||
644 | if self.t % 60 == 0 then | ||
645 | trace("Entities: " .. util.size(game.entities)) | ||
646 | end | ||
647 | end | ||
648 | |||
634 | function TIC() | 649 | function TIC() |
635 | cls(0) | 650 | cls(0) |
636 | 651 | ||
@@ -644,6 +659,8 @@ function TIC() | |||
644 | LevelSystem:run(game.levels, game) | 659 | LevelSystem:run(game.levels, game) |
645 | 660 | ||
646 | DrawingSystem:draw(game) | 661 | DrawingSystem:draw(game) |
662 | |||
663 | --Debug:print(game) | ||
647 | end | 664 | end |
648 | 665 | ||
649 | --- TIC-80 resources. | 666 | --- TIC-80 resources. |