ca0e8212
Geoffrey PREUD'HOMME
Code original
|
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
|
function scene3_load()
backgroundwhite = 0
staralpha = 1
asteroids = {}
bullets = {}
asteroidtimer = 0
rockets = {rocket:new()}
love.audio.play(bgmusic)
rockets[1].x = 50
rockets[1].y = 70
rockets[1].ground = false
rockets[1].inflight = true
table.insert(asteroids, asteroid:new())
if #stars == 0 then
for i = 1, 10 do
table.insert(stars, star:new())
end
end
lastexplosion = {50, 40}
pressedkeys = {}
starttimer = 0
warningtimer = 0
end
function scene3_update(dt)
realasteroiddelay = math.max(0.05, 8/starttimer)
backgroundwhite = math.max(0, backgroundwhite - dt)
love.graphics.setBackgroundColor(math.random(127)*backgroundwhite, math.random(127)*backgroundwhite, math.random(127)*backgroundwhite)
if starttimer < 35 then
asteroidtimer = asteroidtimer + dt
while asteroidtimer > realasteroiddelay do
asteroidtimer = asteroidtimer - realasteroiddelay
table.insert(asteroids, asteroid:new())
end
end
for i, v in pairs(stars) do
v:update(dt)
end
--ASTEROIDS
local delete = {}
for i, v in pairs(asteroids) do
if v:update(dt) == true then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(asteroids, v) --remove
end
--BULLETS
local delete = {}
for i, v in pairs(bullets) do
if v:update(dt) == true then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(bullets, v) --remove
end
--EXPLOSION
local delete = {}
for i, v in pairs(explosions) do
if v:update(dt) == true then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(explosions, v) --remove
end
rockets[1]:update(dt)
if (starttimer > 38 and starttimer < 40) or warningtimer > 0.1 then
warningtimer = math.mod(warningtimer + dt*7, math.pi*2)
end
if starttimer >= 40 and starttimer - dt < 40 then
rockets[1]:wheatleyattack()
end
end
function scene3_draw()
local r, g, b = love.graphics.getColor()
love.graphics.setColor(math.random(255), math.random(255), math.random(255), 255*(1-scoreanim))
for i = 1, backgroundstripes, 2 do
local alpha = math.rad((i/backgroundstripes + math.mod(sunrot/100, 1)) * 360)
local point1 = {lastexplosion[1]*scale+200*scale*math.cos(alpha), lastexplosion[2]*scale+200*scale*math.sin(alpha)}
local alpha = math.rad(((i+1)/backgroundstripes + math.mod(sunrot/100, 1)) * 360)
local point2 = {lastexplosion[1]*scale+200*scale*math.cos(alpha), lastexplosion[2]*scale+200*scale*math.sin(alpha)}
love.graphics.polygon("fill", lastexplosion[1]*scale, lastexplosion[2]*scale, point1[1], point1[2], point2[1], point2[2])
end
love.graphics.setColor(r, g, b, 255)
for i,v in pairs(stars) do
v:draw()
end
for i,v in pairs(asteroids) do
v:draw()
end
rockets[1]:draw()
for i,v in pairs(bullets) do
v:draw()
end
for i, v in pairs(explosions) do
v:draw()
end
if (starttimer > 38 and starttimer < 40) or warningtimer > 0.1 then
love.graphics.setColor(255, 0, 0, math.abs(math.sin(warningtimer))*255)
draw(warningimg, -3+math.random(5)-3, 20+math.random(5)-3)
end
end
function scene3_keypressed(key)
if key ~= "left" and key ~= "up" and key ~= "right" and key ~= "down" then
table.insert(pressedkeys, key)
end
end
function scene3_keyreleased(key)
for i = 1, #pressedkeys do
if pressedkeys[i] == key then
table.remove(pressedkeys, i)
break
end
end
end
|