-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtirs.lua
46 lines (40 loc) · 1.25 KB
/
tirs.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
tirs = {}
VitesseTir = 500
DelaiTir = 0
function AjouteTir( xinit, yinit, dxinit, dyinit )
if DelaiTir<0 then
local tir = {
x = xinit,
y = yinit,
dx = dxinit + VitesseTir * math.sin(VaisseauAngle),
dy = dyinit + VitesseTir * math.cos(VaisseauAngle+math.pi),
vie = 1 -- duree de vie d'un tir (1 sec)
}
table.insert(tirs,tir)
DelaiTir = 0.2
end
end
function DeplaceTirs( dt )
for i=#tirs, 1, -1 do
tirs[i].vie = tirs[i].vie - dt
if tirs[i].vie<0 then
table.remove(tirs,i)
else
-- Déplacement
tirs[i].x = tirs[i].x + tirs[i].dx * dt
tirs[i].y = tirs[i].y + tirs[i].dy * dt
-- Ecran traversable
if tirs[i].x<0 then tirs[i].x=largeurEcran end
if tirs[i].x>largeurEcran then tirs[i].x=0 end
if tirs[i].y<0 then tirs[i].y=hauteurEcran end
if tirs[i].y>hauteurEcran then tirs[i].y=0 end
end
end
DelaiTir = DelaiTir - dt
end
function DessineTirs()
for i=1, #tirs do
love.graphics.setColor(1,0,0)
love.graphics.circle("fill", tirs[i].x, tirs[i].y, 4)
end
end