-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParty.lua
More file actions
56 lines (54 loc) · 1.23 KB
/
Party.lua
File metadata and controls
56 lines (54 loc) · 1.23 KB
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
Party = class()
function Party:init(s)
self.x=WIDTH/2
self.y=HEIGHT/2
self.maxparts = 100
self.parts = {}
function self.draw()
local k,v
for k,v in pairs(self.parts) do
if (v.draw) then v.draw() end
end
end
function self.update()
if (# self.parts < self.maxparts) then self.emit() end
local n,k,v = {}
for k,v in pairs(self.parts) do
if (not v.dead()) then
if (v.update) then v.update() end
table.insert(n, v)
end
end
self.parts = n
end
function self.emit()
local p = Party()
p.parent = self
p.x = p.parent.x + math.random()*15-8
p.y = p.parent.y + math.random()*15-8
p.maxparts = 0 -- not an emitter
function p.draw() rect(p.x, p.y, p.scale, p.scale) end
function p.update()
local dx = (p.x - p.parent.x)
local dy = (p.y - p.parent.y)
p.x = p.x + dx*0.02
p.y = p.y + dy*0.02
p.scale = math.max(math.abs(dx), math.abs(dy))/70 +1
end
function p.dead() return Party:oob(p) end
table.insert(self.parts, p)
end
if (s) then -- passed a hash
end
end
function Party:oob(p)
if (p.x) then
if (p.x < 0) then return true end
if (p.x > WIDTH) then return true end
end
if (p.y) then
if (p.y < 0) then return true end
if (p.y > HEIGHT) then return true end
end
return false
end