/
Draw.lua
executable file
·306 lines (273 loc) · 12.6 KB
/
Draw.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
function love.draw()
local objects=objects
local floor=math.floor
local shadowOffsetX,shadowOffsetY=shadowOffsetX,shadowOffsetY
local centerX,centerY=centerX,centerY
local width,height=width,height
--love.graphics.setCanvas(canvas1X)
if graphicsScaleFactor~=1.0 then
love.graphics.setCanvas(canvas2X)
love.graphics.push()
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle('fill',0,0,2*width,2*height)
else
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle('fill',0,0,2*width+2*borderX,2*height+2*borderY)
love.graphics.translate(borderX,borderY)
end
love.graphics.scale(2,2)
if displayingTitleScreen then
drawTitleScreen()
elseif displayingControls then
drawControlScreen()
else
love.graphics.setColor(1,1,1,1)
love.graphics.draw(background,0,0)
-- draw the shadows first
if drawShadows==true then
love.graphics.setShader(shadowDitherShader)
for k,obj in ipairs(objects) do
if obj.image~=nil and obj.hasShadow then
love.graphics.draw(obj.image, floor(obj.x-obj.halfwidth+shadowOffsetX), floor(obj.y-obj.halfheight)+ShadowOffsetY)
end
end
love.graphics.setShader()
end
for k,obj in ipairs(objects) do
if obj.image~=nil then
love.graphics.draw(obj.image, floor(obj.x-obj.halfwidth), floor(obj.y-obj.halfheight))
end
end
drawStatusBar()
-- depending on state of game, we draw other messages
if gameWon then
drawWinScreen()
end
if gameLost then
drawGameOverScreen()
end
if waitingForClick==true then
love.graphics.setColor(1,1,1,1)
--love.graphics.setColorMode("modulate")
love.graphics.printf("Get ready for level "..currentLevel.."! (Press space or fire)", 0, centerY-25,width,"center")
--love.graphics.setColorMode("replace")
end
if gameIsPaused==true then
drawPauseScreen()
end
if showFPS then
love.graphics.print("FPS: "..tostring(love.timer.getFPS()),10,40)
love.graphics.print("numPassengers: "..tostring(numPassengers),10,52)
love.graphics.print("debugVariable: "..tostring(debugVariable),10,64)
end
end
if graphicsScaleFactor==1 then
--cover up the area above the top escape hole
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle('fill',0,0,2*width,-borderY)
love.graphics.scale(0.5,0.5)
love.graphics.translate(-borderX,-borderY)
else
love.graphics.setCanvas()
love.graphics.pop()
love.graphics.scale(graphicsScaleFactor,graphicsScaleFactor)
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle('fill',0,0,2*width+2*borderX+1,2*height+2*borderY+1)
love.graphics.setColor(1,1,1,1)
canvas2X:setFilter("linear","linear")
love.graphics.draw(canvas2X,borderX,borderY)
love.graphics.scale(1.0/graphicsScaleFactor,1.0/graphicsScaleFactor)
end
-- draw the virtual gamepad directly to the screen
if touching then
-- virtual gamepad button coordinates i,j (1,1) top left, (3,3) bottom right
love.graphics.setColor(1,1,1,0.5)
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
local dPadButtonSizeX = dPadButtonSizeRel*width
local dPadButtonSizeY = dPadButtonSizeX
local dPadTopLeftX=0
local dPadTopLeftY=height-3*dPadButtonSizeY
local i=0
local j=0
--for i=0,2,1 do
-- for j=0,2,1 do
-- love.graphics.rectangle("line",dPadTopLeftX+i*dPadButtonSizeX,dPadTopLeftY+j*dPadButtonSizeY,dPadButtonSizeX,dPadButtonSizeY)
-- end
--end
for i=0,3,1 do
-- horizontal lines
love.graphics.line(dPadTopLeftX+1,dPadTopLeftY+i*dPadButtonSizeY,dPadTopLeftX+3*dPadButtonSizeX-1,dPadTopLeftY+i*dPadButtonSizeY)
-- vertical lines
love.graphics.line(dPadTopLeftX+i*dPadButtonSizeX,dPadTopLeftY+1,dPadTopLeftX+i*dPadButtonSizeX,dPadTopLeftY+3*dPadButtonSizeY-1)
end
-- virtual firebutton rectangle
local fireButtonSizeX = fireButtonSizeRel*width
local fireButtonSizeY = fireButtonSizeX
local fireButtonTopLeftX=width-fireButtonSizeX
local fireButtonTopLeftY=height-fireButtonSizeY
love.graphics.rectangle("line",fireButtonTopLeftX+i*fireButtonSizeX,fireButtonTopLeftY+j*dPadButtonSizeY,fireButtonSizeX,fireButtonSizeY)
end
--[[
if gameWasPaused==true then
love.graphics.print("Starting in: "..(timeToWaitAfterPause-timeSinceUnpausing).." s", centerX-50, centerY-5)
end
--]]
end
function drawStatusBar()
love.graphics.setFont(smallFont)
--love.graphics.print("Player 1 on platform: "..tostring(objects[1].landedOnPlatform),10,80)
for i=1,#playerReferences do
xOffset=(i-1)*80
yOffset=258
love.graphics.setColor(80/255,80/255,80/255,1)
love.graphics.rectangle("fill", xOffset, 252, 78, 46 )
-- love.graphics.setColor(255,255,255,255)
love.graphics.setColor(200/255,200/255,1,1)
--love.graphics.setColorMode("modulate")
if i==5 then
love.graphics.draw(liveImages[i],xOffset+4,254-2) -- was 20
else
love.graphics.draw(liveImages[i],xOffset+20,254-2)
end
if playerReferences[i].numLives>=0 then
if i==5 then
love.graphics.print("x "..playerReferences[i].numLives,xOffset+28,255) -- was 44
else
love.graphics.print("x "..playerReferences[i].numLives,xOffset+44,255)
end
love.graphics.print("$ "..roundDollar(playerReferences[i].score),xOffset+4,266)
--if playerReferences[i].tip>0 then
love.graphics.print("Tip $ "..roundDollar(playerReferences[i].tip),xOffset+45,266)
--end
--love.graphics.print("Clients: "..passengersLeft,xOffset+4,277)
love.graphics.print("Fuel ",xOffset+4,277)
drawProgressBar(xOffset+22,278,50,6,playerReferences[i].fuel*100)
if passengersLeft<=0 then
love.graphics.printf("Go up!",xOffset,288,78,"center")
elseif playerReferences[i].passengerInside then
love.graphics.printf("Pad "..playerReferences[i].passengerInside.targetPlatform..", please! ",xOffset,288,78,"center")
end
else
love.graphics.print("Dead",xOffset+25,277)
end
--love.graphics.setColorMode("replace")
end
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill",width-30,254-2,30,12)
love.graphics.setColor(200/255,200/255,1,1)
love.graphics.draw(passengerLiveImage,width-30+2,254-1)
love.graphics.print("x "..passengersLeft,width-30+14,255)
love.graphics.setFont(bigFont)
end
function drawTitleScreen()
local floor=math.floor
love.graphics.setColor(1,1,1,1)
love.graphics.draw(background,0,0)
if drawShadows==true then
love.graphics.setShader(shadowDitherShader)
love.graphics.draw(screens[1],0+shadowOffsetX,0+shadowOffsetY)
love.graphics.setShader()
end
love.graphics.setColor(1,1,1,1)
love.graphics.draw(screens[1],0,0)
if drawShadows==true then
love.graphics.setShader(shadowDitherShaderNoTexture)
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill", floor(centerX-150+shadowOffsetX), floor(centerY-3-45+75+shadowOffsetY), 300, 88 )
love.graphics.setShader()
end
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", floor(centerX-150), floor(centerY-3-45+75), 300, 88 )
love.graphics.setColor(0,0,0,1)
love.graphics.printf("Fire or 1,2,3,4,5 - Start 1-5 player", 0, centerY-7-32+75,width,"center")
love.graphics.printf("c - Configure controls", 0, centerY-7-16+75,width,"center")
love.graphics.printf("f - Toggle fullscreen", 0, centerY-7+75,width,"center")
love.graphics.printf("t - Toggle scaling (fullscreen only)", 0, centerY-7+16+75,width,"center")
love.graphics.printf("q or Select - Quit", 0, centerY-7+32+75,width,"center")
end
function drawControlScreen()
local floor=math.floor
love.graphics.setColor(1,1,1,1)
love.graphics.draw(background,0,0)
if drawShadows==true then
love.graphics.setShader(shadowDitherShaderNoTexture)
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill", floor(centerX-150+shadowOffsetX), floor(centerY-115+shadowOffsetY), 300, 230 )
love.graphics.setShader()
end
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", floor(centerX-150), floor(centerY-115), 300, 230 )
love.graphics.setColor(0,0,0,1)
love.graphics.printf("CONTROL CONFIGURATION", centerX-150, centerY-3-100,300,"center")
love.graphics.printf("1 - P1 Controls: "..controlTypes[controls[1]], centerX-150, centerY-3-70,300,"center")
love.graphics.printf("2 - P2 Controls: "..controlTypes[controls[2]], centerX-150, centerY-3-50,300,"center")
love.graphics.printf("3 - P3 Controls: "..controlTypes[controls[3]], centerX-150, centerY-3-30,300,"center")
love.graphics.printf("4 - P4 Controls: "..controlTypes[controls[4]], centerX-150, centerY-3-10,300,"center")
love.graphics.printf("5 - P5 Controls: "..controlTypes[controls[5]], centerX-150, centerY-3+10,300,"center")
love.graphics.printf("Keyboard1 = arrow keys + right shift", centerX-150, centerY-3+80,300,"center")
love.graphics.printf("Keyboard2 = w a s d + left shift", centerX-150, centerY-3+100,300,"center")
love.graphics.printf("q - Return to Title Menu", centerX-150, centerY-3+40,300,"center")
end
function drawPauseScreen()
local floor=math.floor
if drawShadows==true then
love.graphics.setShader(shadowDitherShaderNoTexture)
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill", floor(centerX-125+shadowOffsetX), floor(centerY-40+shadowOffsetY), 250, 80 )
love.graphics.setShader()
end
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", floor(centerX-125), floor(centerY-40), 250, 80 )
love.graphics.setColor(0,0,0,1)
love.graphics.printf("Paused! Press p to continue", 0, centerY-4,width,"center")
end
function drawWinScreen()
local floor=math.floor
love.graphics.setColor(1,1,1,1)
if drawShadows==true then
love.graphics.setShader(shadowDitherShader)
love.graphics.draw(screens[2],0+shadowOffsetX,0+shadowOffsetY)
love.graphics.setShader()
end
love.graphics.draw(screens[2],0,0)
if drawShadows==true then
love.graphics.setShader(shadowDitherShaderNoTexture)
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill", floor(centerX-150+shadowOffsetX), floor(centerY+80-40+shadowOffsetY), 300, 80 )
love.graphics.setShader()
end
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", floor(centerX-150), floor(centerY+80-40), 300, 80 )
love.graphics.setColor(0,0,0,1)
love.graphics.printf("Congratulations, you won!", 0, centerY-5+80-15,width,"center")
love.graphics.printf("Press q to restart!", 0, centerY-5+80+15,width,"center")
end
function drawGameOverScreen()
local floor=math.floor
love.graphics.setColor(1,1,1,1)
if drawShadows==true then
love.graphics.setShader(shadowDitherShader)
love.graphics.draw(screens[3],0+shadowOffsetX,0+shadowOffsetY)
love.graphics.setShader()
end
love.graphics.draw(screens[3],0,0)
if drawShadows==true then
love.graphics.setShader(shadowDitherShaderNoTexture)
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle("fill", floor(centerX-100+shadowOffsetX), floor(centerY+75-40+shadowOffsetY), 200, 80 )
love.graphics.setShader()
end
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", floor(centerX-100), floor(centerY+75-40), 200, 80 )
love.graphics.setColor(0,0,0,1)
love.graphics.printf("Press Q to restart", 0, centerY-5+75,width,"center")
end
function drawProgressBar(x,y,width,height,percent)
local r,g,b,a = love.graphics.getColor()
love.graphics.setColor(0,0,64/255,1)
love.graphics.rectangle("fill",x,y,width,height)
love.graphics.setColor(r,g,b,a)
love.graphics.rectangle("fill",x+1,y+1,math.floor((width-2)*percent/100),height-2)
love.graphics.setColor(r,g,b,a)
end