-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
197 lines (135 loc) · 4.17 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
--variaveis-------------------------------------------------------------------
alturaTela= 480
larguraTela = 320
maxMeteoro = 5
--FIM_JOGO = false
TIME_JOG0 = 0
fase=500
fase_jogo = 0
--pausa = false
comandos="[P]Pausar [0]Fechar"
--variavel--------------------------------------------------------------------
--array-e-table------------------------------------------------------------------
meteoros = {}
aviao_14bis = {
src="image/14bis.png",
largura=55,
altura=61,
x = larguraTela/2-64/2,
y = alturaTela - 80
}
--array-e-table-------------------------------------------------------------------
--funcoes--------------------------------------------------------------------------
function destroiAviao()
aviao_14bis.src = "image/explosao_nave.png"
aviao_14bis.image = love.graphics.newImage(aviao_14bis.src)
aviao_14bis.largura= 45
aviao_14bis.altura= 53
end
function temColisao(X1, Y1, L1, A1, X2, Y2, L2, A2)
return X2 < X1 + L1 and
X1 < X2 + L2 and
Y1 < Y2 + A2 and
Y2 < Y1 + A1
end
function removeMeteoros()
for i = #meteoros, 1, -1 do
if meteoros[i].y > alturaTela then
table.remove(meteoros,i)
end
end
end
function criaMeteoro()
meteoro= {
x=math.random(larguraTela),
y=-70,
largura=48,
altura=33,
peso = math.random(2),
deslocamentoH = math.random(-1,1)
}
table.insert(meteoros, meteoro)
end
function moveMeteoro()
for k,meteoro in pairs(meteoros) do
meteoro.y = meteoro.y + meteoro.peso
meteoro.x = meteoro.x + meteoro.deslocamentoH
end
end
function move14bis()
if love.keyboard.isDown("w") then
aviao_14bis.y = aviao_14bis.y-1
end
if love.keyboard.isDown("s") then
aviao_14bis.y = aviao_14bis.y+1
end
if love.keyboard.isDown("a") then
aviao_14bis.x = aviao_14bis.x-1
end
if love.keyboard.isDown("d") then
aviao_14bis.x = aviao_14bis.x+1
end
end
function checaColisoes()
for k, meteoro in pairs(meteoros) do
if temColisao(meteoro.x, meteoro.y, meteoro.largura, meteoro.altura, aviao_14bis.x, aviao_14bis.y, aviao_14bis.largura, aviao_14bis.altura) then
destroiAviao()
FIM_JOGO=true
comandos= "[R]Reiniciar [0]Fechar"
end
end
end
--funcoes-----------------------------------------------------------------------
--core-love----------------------------------------------------------------------------------
function love.load()
math.randomseed(os.time())
love.window.setMode(larguraTela,alturaTela,{resizable = false})
love.window.setTitle("14bis vs Meteoros ")
backgound = love.graphics.newImage("image/background.png")
meteoro_img = love.graphics.newImage("image/meteoro.png")
aviao_14bis.image = love.graphics.newImage(aviao_14bis.src)
end
function love.update(dt)
if love.keyboard.isDown ("0") then
love.event.quit()
end
if love.keyboard.isDown ("p") then
pausa = not pausa
if not FIM_JOGO then
comandos= "[P]Voltar"
end
end
if not FIM_JOGO and not pausa then
comandos= "[P]Pausar [0]Fechar"
love.graphics.print(comandos, larguraTela/2/2, alturaTela-15)
removeMeteoros()
if #meteoros < maxMeteoro then
criaMeteoro()
end
moveMeteoro()
if love.keyboard.isDown("a","s","d","w") then
move14bis()
end
TIME_JOG0 = TIME_JOG0 +1
if TIME_JOG0 > fase then
fase = fase + 500
maxMeteoro = maxMeteoro +1
fase_jogo = fase_jogo+1
end
-- t = love.timer.getMicroTime(1)
checaColisoes()
end
end
function love.draw()
love.graphics.draw(backgound,0,0)
--love.graphics.setColor(0, 0.4, 0.4)
for k, meteoro in pairs(meteoros) do
love.graphics.draw(meteoro_img,meteoro.x,meteoro.y)
end
love.graphics.draw(aviao_14bis.image,aviao_14bis.x,aviao_14bis.y)
love.graphics.print("Nível:"..fase_jogo, 250, 20)
love.graphics.print(comandos, larguraTela/2/2, alturaTela-15)
--love.graphics.print(t , 200, 10)
--meteoro
end
--core--love----------------------------------------------------------------------------------