-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.lua
More file actions
70 lines (60 loc) · 1.42 KB
/
bullet.lua
File metadata and controls
70 lines (60 loc) · 1.42 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local bullets = {}
BULLET_NORMAL = 0
BULLET_X2 = 1
function newBullet()
local b = {}
b.x = 0
b.y = 0
b.angle = 0
b.vx = 0
b.vy = 0
b.speed = 500
b.damage = 200
b.radius = 5
b.free = false
b.type = 0
b.sound = love.audio.newSource("Sons/bullet.wav", "static")
b.fire = function(x, y, angle)
b.x = x
b.y = y
b.vx = math.cos(angle) * b.speed
b.vy = math.sin(angle) * b.speed
b.sound:play()
end
b.update = function(dt)
checkIntersection(b)
if b.free == false then
checkRebound(b)
b.x = b.x + b.vx * dt
b.y = b.y + b.vy * dt
if b.x <= 0 or b.x >= SCREEN_WIDTH or b.y <= 0 or b.y >= SCREEN_WIDTH then
b.free = true
end
end
end
b.draw = function()
if b.type == BULLET_X2 then
love.graphics.setColor(1, 0, 0, 1)
end
love.graphics.circle("fill", b.x, b.y, b.radius)
love.graphics.setColor(1, 1, 1, 1)
end
table.insert(bullets, b)
return b
end
function updateBullets(dt)
for _, b in ipairs(bullets) do
b.update(dt)
end
for i = #bullets, 1, -1 do
local bullet = bullets[i]
if bullet.free == true then
table.remove(bullets, i)
end
end
end
function drawBullets(dt)
for _, b in ipairs(bullets) do
b.draw()
end
end