-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example_-_class bullet list.lua
46 lines (33 loc) · 1.02 KB
/
Example_-_class bullet list.lua
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
-- Bullet List
bullet = class()
function bullet:init(x,y)
self.x = x
self.y = y
self.incx = math.random()*2-1
self.incy = math.random()*2-1
end
bullets = {}
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
for i=0,10 do
bullets[i] = bullet(320,200)
end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
for i=0,#bullets do
bullets[i].x=bullets[i].x+bullets[i].incx
bullets[i].y=bullets[i].y+bullets[i].incy
if bullets[i].x < 0 then bullets[i] = bullet(320,200) end
if bullets[i].x > WIDTH then bullets[i] = bullet(320,200) end
if bullets[i].y < 0 then bullets[i] = bullet(320,200) end
if bullets[i].y > HEIGHT then bullets[i] = bullet(320,200) end
rect(bullets[i].x,bullets[i].y,32,32)
end
-- Do your drawing here
end