Blame view

game/scene4.lua 4.19 KB
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
154
155
156
157
158
159
160
161
162
  function scene4_load()

  	backgroundwhite = 0

  	staralpha = 1

  	asteroids = {}

  	bullets = {}

  	love.audio.play(bgmusic)

  	

  	starttimer = 0

  	alerttimer = 0

  	flyingquad = 3

  	

  	pspeedx = 0

  	pspeedy = 0

  	

  	playerx = nil

  	

  	flyanimationtimer = 0

  end

  

  function scene4_update(dt)

  	if secondtimer then

  		secondtimer = secondtimer + dt

  	end

  	for i, v in pairs(stars) do

  		v:update(dt)

  	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

  	

  	if rockets[1] then

  		rockets[1]:update(dt)

  	end

  	

  	if (starttimer > 0 and starttimer < 3) or alerttimer > 0.1 then

  		alerttimer = math.mod(alerttimer + dt*7, math.pi*2)

  	end

  	

  	if jumped then

  		if rockets[1] then

  			rockets[1].x = rockets[1].x - dt*3

  		end

  		

  		if rockets[1] and secondtimer > 2 and secondtimer - dt <= 2 then

  			for i = 1, 20 do

  				if explosions then

  					table.insert(explosions, explosion:new(rockets[1].x-16+math.random(16)-8, rockets[1].y-20+math.random(16)-8))

  				end

  			end

  			starmover = math.pi

  			rockets[1] = nil

  		end

  		

  		playerx = playerx + pspeedx*dt

  		playery = playery + pspeedy*dt

  		

  		if pspeedx > 0 then

  			pspeedx = pspeedx - dt*5

  		end

  		

  		if playery >= 20 then

  			playery = 20

  			pspeedy = 0

  		end

  		

  		if playerx >= 50 then

  			pspeedx = 0

  			playerx = 50

  		end

  	

  		if secondtimer > 2 then

  			local i = math.max(0, (1-(secondtimer-2)/2))

  			staralpha = math.max(0, (1-(secondtimer-2)/2))*i

  			love.graphics.setBackgroundColor(153*(1-i), 217*(1-i), 234*(1-i))

  			

  			if shakeamount < 5 then

  				shakeamount = math.min(5, shakeamount+dt*3)

  			elseif shakeamount > 5 then

  				shakeamount = math.max(5, shakeamount-dt*3)

  			end

  		end

  		

  		if secondtimer > 4 then

  			changegamestate("scene5")

  		end

  	end

  	

  	if starttimer >= 4.3 and starttimer - dt < 4.3 then

  		playerx = rockets[1].x+4

  		playery = rockets[1].y

  	end

  	

  	if jumped then

  		flyanimationtimer = flyanimationtimer + dt

  		while flyanimationtimer > 0.1 do

  			flyanimationtimer = flyanimationtimer - 0.1

  			if flyingquad == 3 then

  				flyingquad = 4

  			else

  				flyingquad = 3

  			end

  		end

  	end

  end

  

  function scene4_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

  	

  	

  	if playerx then

  		local off = 0

  		if rockets[1] then

  			off = rockets[1].startingoffset

  		end

  		love.graphics.drawq(playerimg, playerquad[flyingquad], (playerx+off)*scale, playery*scale, 0, scale, scale, 13, 6)

  	end

  	

  	if rockets[1] then

  		rockets[1]:draw()

  	end

  	for i, v in pairs(explosions) do

  		v:draw()

  	end

  	

  	if (starttimer > 0 and starttimer < 3) or alerttimer > 0.1 then

  		local i = math.abs(math.sin(alerttimer))

  		love.graphics.setColor(255, 0, 0, i*100)

  		love.graphics.rectangle("fill", 0, 0, 100*scale, 80*scale)

  		love.graphics.setColor(255, 0, 0, i*255)

  		draw(alertimg, 50+math.random(5)-3, 40+math.random(5)-3, (math.random()*2-1)*0.1, i*0.5+0.6, i*0.5+0.6, 54, 15)

  		draw(randomshitimg, 50+math.random(20)-10, 40+math.random(20)-10, 0, 1, 1, 50, 42)

  	end

  	

  	if starttimer > 4 and not jumped then

  		love.graphics.setColor(255, 0, 0, math.random(255))

57f5b105   Geoffrey PREUD'HOMME   Tout traduit en f...
163
  		properprint("saute!!", 0, 40, scale*2)

ca0e8212   Geoffrey PREUD'HOMME   Code original
164
165
166
167
168
169
170
171
172
173
  	end

  end

  

  function scene4_action()

  	if starttimer > 4.3 and not jumped then

  		jumped = true

  		secondtimer = 0

  		pspeedx = 20

  		pspeedy = 2

  	end

57f5b105   Geoffrey PREUD'HOMME   Tout traduit en f...
174
  end