-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup.lua
More file actions
executable file
·46 lines (33 loc) · 740 Bytes
/
group.lua
File metadata and controls
executable file
·46 lines (33 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Group = class('Group')
function Group:initialize()
self.items = {}
self.size = 0
self.activeCount = 0
end
function Group:add(item)
self.size = self.size + 1
self.items[self.size] = item
if item.active and item.active == true then
self.activeCount = self.activeCount + 1
end
end
function Group:call(func, ...)
for k,item in ipairs(self.items) do
local callback = item[func]
if(type(callback)=='function') then
callback(item, ...)
end
end
end
function Group:update(dt)
self.activeCount = 0
for k,item in ipairs(self.items) do
item:update(dt)
if item.active and item.active == true then
self.activeCount = self.activeCount + 1
end
end
end
function Group:draw()
self:call('draw')
end