1 print "lua is up and running"
5 function particle
:spawn (x
,y
,vx
,vy
,maxage
)
6 local p
= {x
=x
,y
=y
,vx
=vx
,vy
=vy
,age
=0,maxage
= maxage
or 10}
7 self
.list
[#self
.list
+1] = p
11 function particle
:step()
12 for i
=#self
.list
,1,-1 do
13 local p
= self
.list
[i
]
17 if p
.think
then p
:think() end
18 if p
.age
> p
.maxage
then
19 table.remove(self
.list
,i
)
24 function particle
:draw()
25 local rect
= draw
.rect
26 for i
=#self
.list
,1,-1 do
27 local p
= self
.list
[i
]
28 if p
.draw
then p
:draw() else
29 rect(p
.x
-2,p
.y
-2,4,4,1,1,1,1)
34 function engine
.frame ()
35 draw
.rect(0,0,3,3,1,1,1,1)
36 draw
.rect(5,0,1,5,1,0,0,1)
37 draw
.rect(0,5,5,1,0,1,1,1)
39 if math
.random()>.9 then
40 local p
= particle
:spawn(200,200,(math
.random()-.5),(math
.random()-.5),math
.random(300,1000))
42 p
.vx
,p
.vy
= p
.vx
*.99,p
.vy
*.99-.002
45 local x
,y
= self
.x
,self
.y
46 local m
,a
= self
.maxage
,self
.age
49 draw
.rect(x
-s
,y
-s
,s
*2,s
*2,1,1,1,p
)
52 io
.write("\r",#particle
.list
)
56 -- draw.rect(0,0,10,10,1,1,0,1)