-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpcpool.lua
More file actions
56 lines (47 loc) · 947 Bytes
/
Copy pathnpcpool.lua
File metadata and controls
56 lines (47 loc) · 947 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
47
48
49
50
51
52
53
54
55
56
local count = 0
npcpool = {}
local np = npcpool
local meta = {} --metatable is required to prevent indexing fields with functions via 'pairs'
setmetatable(np, meta)
meta.__index = meta
meta.add = function(npc)
if count >= config.MAX_NPC then
count = 0
end
count = count + 1
np[count] = npc
end
meta.think = function(dt)
for _, v in pairs(np) do
v:think(dt)
end
end
meta.free = function()
for k, v in pairs(np) do
if v:isDead() then
v:kill()
np[k] = nil
end
end
end
meta.draw = function()
for _, v in pairs(np) do
local x, y = v:getPos()
local x1, y1 = player:getPos()
if funcs.Distance(x, y, x1, y1) < config.DRAWING_DISTANCE then
v:draw()
end
end
end
meta.collide = function(ent, x, y)
for _, v in pairs(np) do
if v ~= ent then
local x1, y1 = v:getPos()
if funcs.Distance(x1, y1, x, y) < ent:getMaxWidth() + v:getMaxWidth() then
return true
end
end
end
return false
end
return np