-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.lua
280 lines (237 loc) · 7.97 KB
/
index.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
timer = Timer.new()
timer:start()
dofile("eslib.lua")
Mp3.load("Dixvague.mp3", 0)
Mp3.play(true, 0)
Ogg.load("laser shot.ogg", 0)
Ogg.load("explosion.ogg", 1)
System.setCpuSpeed(333)
blanc = Color.new(255,255,255)
vert = Color.new(0,255,0)
jaune = Color.new(255,255,0)
rouge = Color.new(255,0,0)
noir = Color.new(0,0,0)
missiles = {}
cooldown = Timer.new()
level = 1
asteroids = {}
spaceship = {lifes = 5,x = 240,y = 136,angle = 0}
boucliers = 0
elan = 0
direction = 0
pi = math.pi
ltn_1 = IntraFont.load("flash0:/font/ltn0.pgf", 0);
function initLevel()
if level / 5 == math.floor(level/5) then
boucliers = boucliers + 1
end
for i = 1, level do
asteroids[i] = {x = math.random(0,480),y = math.random(0,272),size = 32,angle = math.random(0,360)}
while object.collision({x = asteroids[i].x,y = asteroids[i].y,radius = asteroids[i].size},{x = spaceship.x,y = spaceship.y,radius = 30}) do
asteroids[i] = {x = math.random(0,480),y = math.random(0,272),size = 32,angle = math.random(0,360)}
end
end
for i = 1, 255 do
System.draw()
screen:clear()
background(0)
for j = 1, #asteroids do
screen.circle(asteroids[j].x,asteroids[j].y,asteroids[j].size,Color.new(i,i,i))
end
screen:drawLine(spaceship.x-10*math.cos(math.rad(-90-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-90-spaceship.angle)),spaceship.x-10*math.cos(math.rad(-210-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-210-spaceship.angle)),vert)
screen:drawLine(spaceship.x-10*math.cos(math.rad(-90-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-90-spaceship.angle)),spaceship.x-10*math.cos(math.rad(-330-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-330-spaceship.angle)),vert)
screen:drawLine(spaceship.x,spaceship.y,spaceship.x-10*math.cos(math.rad(-210-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-210-spaceship.angle)),vert)
screen:drawLine(spaceship.x,spaceship.y,spaceship.x-10*math.cos(math.rad(-330-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-330-spaceship.angle)),vert)
ltn_1:setStyle(1.0,Color.new(0,255,0,255-i),noir,IntraFont.ALIGN_CENTER)
ltn_1:print(240, 136, "Level "..level)
System.endDraw()
screen.flip()
end
missiles = {}
end
function pauseMenu()
oldpad = pad
while 1 do
System.draw()
screen:clear()
pad = Controls.readPeek()
background(0)
ltn_1:setStyle(1.0,Color.new(0,255,0),noir,IntraFont.ALIGN_CENTER)
ltn_1:print(240, 20, "PAUSE")
ltn_1:print(240, 240, "Press START to continue playing")
ltn_1:print(240, 260, "Press HOME to quit")
if pad:start() and not oldpad:start() then
oldpad = pad
break
end
if pad:home() then System.quit() end
System.endDraw()
screen.flip()
oldpad = pad
end
end
function gameOver()
System.msgDialog("Spaceship destroyed!",1)
asteroids = {}
level = 1
spaceship = {lifes = 5,x = 240,y = 136,angle = 0}
elan = 0
direction = 0
initLevel()
end
etoiles = {}
for i = 1, 30 do
etoiles[i] = {x =math.random(0,480),y =math.random(0,272)}
end
function background(anim)
for i = 1, # etoiles do
screen.safePixel(etoiles[i].x,etoiles[i].y,blanc)
if anim == 1 then
etoiles[i].x,etoiles[i].y = object.move(direction+180,elan/2,etoiles[i].x,etoiles[i].y)
if etoiles[i].x > 480 then
etoiles[i].x = 0
elseif etoiles[i].x < 0 then
etoiles[i].x = 480
end
if etoiles[i].y > 272 then
etoiles[i].y = 0
elseif etoiles[i].y < 0 then
etoiles[i].y = 272
end
end
end
end
initLevel()
while 1 do
System.draw()
screen:clear()
pad = Controls.readPeek()
background(1)
if #asteroids == 0 then
level = level + 1
initLevel()
end
for i = 1, #asteroids do
if asteroids[i] ~= nil then
asteroids[i].x,asteroids[i].y = object.move(asteroids[i].angle,1.5,asteroids[i].x,asteroids[i].y)
screen.circle(asteroids[i].x,asteroids[i].y,asteroids[i].size,blanc)
if asteroids[i].x > (480 + asteroids[i].size) then
asteroids[i].x = 0 - asteroids[i].size
elseif asteroids[i].y > (272 + asteroids[i].size) then
asteroids[i].y = 0 - asteroids[i].size
elseif asteroids[i].x < (0 - asteroids[i].size) then
asteroids[i].x = 480 - asteroids[i].size
elseif asteroids[i].y < (0 - asteroids[i].size) then
asteroids[i].y = 272 - asteroids[i].size
end
if object.collision({x = asteroids[i].x,y = asteroids[i].y,radius = asteroids[i].size},{x = spaceship.x,y = spaceship.y,radius = 10}) then
if boucliers ~= 0 then
if asteroids[i].size > 16 then
asteroids[i].size = asteroids[i].size / 2
asteroids[i].angle = math.random(0,360)
asteroids[#asteroids +1] = {x = asteroids[i].x,y = asteroids[i].y,size = asteroids[i].size,angle = math.random(0,360)}
else
table.remove(asteroids,i)
end
boucliers = boucliers -1
else
gameOver()
end
end
end
end
for i = 1, #missiles do
if missiles[i] ~= nil then
missiles[i].x,missiles[i].y = object.move(missiles[i].angle,6,missiles[i].x,missiles[i].y)
screen.circle(missiles[i].x,missiles[i].y,3,jaune)
if missiles[i].x < 0 or missiles[i].y < 0 or missiles[i].x > 480 or missiles[i].y > 272 then
table.remove(missiles,i)
else
for j = 1, #asteroids do
if asteroids[j] ~= nil then
if missiles[i] ~= nil then
if object.collision({x = asteroids[j].x,y = asteroids[j].y,radius = asteroids[j].size},{x = missiles[i].x,y = missiles[i].y,radius = 3}) then
Ogg.play(false,1)
if asteroids[j].size > 16 then
asteroids[j].size = asteroids[j].size / 2
asteroids[j].angle = math.random(0,360)
asteroids[#asteroids +1] = {x = asteroids[j].x,y = asteroids[j].y,size = asteroids[j].size,angle = math.random(0,360)}
else
table.remove(asteroids,j)
end
table.remove(missiles,i)
end
end
end
end
end
end
end
if pad:r() or pad:right() then
spaceship.angle = spaceship.angle + 4
end
if pad:l() or pad:left() then
spaceship.angle = spaceship.angle - 4
end
if spaceship.angle > 356 then
spaceship.angle = 0
elseif spaceship.angle < 4 then
spaceship.angle = 356
end
if cooldown:time() >= 500 then
cooldown:stop()
cooldown:reset()
end
if pad:square() or pad:circle() or pad:triangle() then
if cooldown:time() == 0 or cooldown:time() >= 500-(level*10) then
if #missiles ~= nil then
missiles[#missiles + 1] = {x = spaceship.x,y = spaceship.y,angle = spaceship.angle}
else
missiles[1] = {x = spaceship.x,y = spaceship.y,angle = spaceship.angle}
end
Ogg.play(false,0)
cooldown:reset()
cooldown:start()
end
end
if pad:cross() then
if elan < 5 then
elan = elan + 0.1
end
direction = spaceship.angle
spaceship.x,spaceship.y = object.move(direction,elan,spaceship.x,spaceship.y)
else
if elan > 0 then
elan = elan - 0.05
spaceship.x,spaceship.y = object.move(direction,elan,spaceship.x,spaceship.y)
end
end
if spaceship.x > 490 then
spaceship.x = -10
elseif spaceship.y > 282 then
spaceship.y = -10
elseif spaceship.x < -10 then
spaceship.x = 490
elseif spaceship.y < -10 then
spaceship.y = 282
end
-- Don't ask me how, but it works
for i = 1, boucliers do
screen.circle(spaceship.x,spaceship.y,10 + i * 2,rouge)
end
screen:drawLine(spaceship.x-10*math.cos(math.rad(-90-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-90-spaceship.angle)),spaceship.x-10*math.cos(math.rad(-210-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-210-spaceship.angle)),vert)
screen:drawLine(spaceship.x-10*math.cos(math.rad(-90-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-90-spaceship.angle)),spaceship.x-10*math.cos(math.rad(-330-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-330-spaceship.angle)),vert)
screen:drawLine(spaceship.x,spaceship.y,spaceship.x-10*math.cos(math.rad(-210-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-210-spaceship.angle)),vert)
screen:drawLine(spaceship.x,spaceship.y,spaceship.x-10*math.cos(math.rad(-330-spaceship.angle)),spaceship.y+10*math.sin(math.rad(-330-spaceship.angle)),vert)
-- End of the unhuman sequence
if pad:start() and not oldpad:start() then pauseMenu() end
while timer:time() < 33 do
--cap the Framerate to aprox. 30FPS
end
System.endDraw()
System.showFPS()
screen.flip()
oldpad = pad
timer:reset(0)
timer:start()
end