-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmines.lua
79 lines (72 loc) · 2.84 KB
/
mines.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
mines = {}
function CreeMines( typeMines )
for i=1,28 do
local mine = {
x = math.random(largeurEcran),
y = math.random(hauteurEcran),
dx = math.random(-40,40),
dy = math.random(-40,40),
r = 5,
type = string.sub(typeMines,math.fmod(i,4)+1,math.fmod(i,4)+1), -- "A:float", "B:fireball, "C:magnetic", "D:magfire"
active = (i<5), -- active les 4 premières mines à la création
score = 100
}
if (i<13) then
mine.r = 10
mine.score = 200
end
if (i<5) then
mine.r = 15
mine.score = 300
end
table.insert(mines,mine)
end
end
function DessineMines()
for i=1,#mines do
if mines[i].active then
if mines[i].type=="A" then
love.graphics.setColor(0,1,0)
love.graphics.circle("fill",mines[i].x,mines[i].y,mines[i].r,3)
end
if mines[i].type=="B" then
love.graphics.setColor(0,1,0)
love.graphics.circle("fill",mines[i].x,mines[i].y,mines[i].r,4) -- adapter le dessin selon le type
end
if mines[i].type=="C" then
love.graphics.setColor(0,1,0)
love.graphics.circle("fill",mines[i].x,mines[i].y,mines[i].r,5) -- adapter le dessin selon le type
end
if mines[i].type=="D" then
love.graphics.setColor(0,1,0)
love.graphics.circle("fill",mines[i].x,mines[i].y,mines[i].r,6) -- adapter le dessin selon le type
end
else
love.graphics.setColor(1,1,0)
love.graphics.circle("fill",mines[i].x,mines[i].y,1)
end
end
end
function DeplaceMines( dt )
for i=1,#mines do
if mines[i].active then
-- Déplacement
mines[i].x = mines[i].x + mines[i].dx * dt
mines[i].y = mines[i].y + mines[i].dy * dt
-- Ecran traversable
if mines[i].x<0 then mines[i].x=largeurEcran end
if mines[i].x>largeurEcran then mines[i].x=0 end
if mines[i].y<0 then mines[i].y=hauteurEcran end
if mines[i].y>hauteurEcran then mines[i].y=0 end
-- Mines magnetiques
if mines[i].type=="B" or mines[i].type=="D" then
sensX = 1
if VaisseauX<mines[i].x then sensX=-1 end
sensY = 1
if VaisseauY<mines[i].y then sensY=-1 end
mines[i].dx = sensX * math.max(math.abs(math.ceil(VaisseauX - mines[i].x)) / 5,math.abs(mines[i].dx))
mines[i].dy = sensY * math.max(math.abs(math.ceil(VaisseauY - mines[i].y)) / 5,math.abs(mines[i].dy))
end
end
end
end