-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
60 lines (50 loc) · 2.01 KB
/
README
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
57
58
59
Party - A particle system for Codea
The Party class creates a new object, a "Party", that can act as
a particle emitter, a particle, or both - indeed, you can have an
emitter that emits emitters, and so on. In most uses, the emitter will
emit non-emitter particles, and acts as a regular particle system.
Parties have the following properties - most are optional
or have reasonable defaults:
x, y = location
dx, dy = delta x and y, or 'velocity'
mass
gravity
emit() = routine to decide to emit (or not) a particle. nil for particles
draw() = routine to draw the party (often nil for an emitter)
update() = updates state of party (usually based on the properties above)
dead() = boolean to decide if a particle is dead and should be culled
The user of the Party class simply needs to add the following calls
to the appropriate places in their main.lua:
in setup(): one or more "e=Party()" calls, perhaps with some followup
configuration: ("e.x = WIDTH/2 e.y=HEIGHT").
in draw(): Calls to update() and draw() (which will trigger cascading
calls to particle children of the emitter - so a call to update() an
emitter will trigger calls by that emitter to update() it's children,
and their children, and so on down the line). The update() routine also
tends to be the correct place to call emit().
After an emitter updates all of their particles, it culls the list, removing
any particle where dead() returns true.
example:
fire = Party() -- a torch
fire.x=WIDTH/2
fire.y=0
fire.maxp = 100
-- no fire.draw() - the default is to do draw() on all it's particles
-- no fire.update() - default for emitter is to do particle() if # list < maxp
function fire.particle
ember = Party()
ember.x = self.x
ember.y = self.y
ember.alpha = 255
function ember.update()
self.y = self.y + rand(3)+1
self.alpha = self.alpha - rand()
end
function ember.dead() return (self.y>HEIGHT) end
function ember.draw()
stroke(255, 100, 0, self.alpha)
rect(self.x, self.y, 1)
end
table.add(self.list, ember)
end
end