@@ -236,29 +236,31 @@ function Game:draw()
236
236
-- Replay the event log
237
237
self .state = self .eventLog :play (self .time )
238
238
239
+ local player = self .state [self .playerId ]
240
+
239
241
-- Move the viewport
240
- if self . state [ self . playerId ] then
241
- self .viewport :move (self . state [ self . playerId ] .x , 300 )
242
+ if player then
243
+ self .viewport :move (player .x , 300 )
242
244
end
243
245
244
246
-- Draw the world
245
247
love .graphics .setColor ({255 ,255 ,255 ,255 })
246
248
love .graphics .draw (self .bgimage )
247
249
self .viewport :draw (self .state )
248
250
251
+ -- Draw the health bar
252
+ if player then
253
+ drawFilledBar (20 , 20 , 200 , 20 ,
254
+ player .health / player .maxHealth ,
255
+ {204 ,20 ,28 }, nil , {255 ,255 ,255 },
256
+ player .health .. " /" .. player .maxHealth )
257
+ end
258
+
249
259
-- Draw the time bar
250
260
drawFilledBar (580 , 20 , 200 , 20 ,
251
261
(self .maxTime - self .time ) / constants .playTime ,
252
- {107 ,141 ,255 }, nil , {255 ,255 ,255 })
253
-
254
- resetDraw (
255
- function ()
256
- love .graphics .setColor (255 , 255 , 255 )
257
-
258
- local str = math.ceil ((self .maxTime - self .time ) / constants .framerate )
259
- local strWidth = love .graphics .getFont ():getWidth (str )
260
- love .graphics .print (str , 680 - strWidth / 2 , 23 )
261
- end )
262
+ {107 ,141 ,255 }, nil , {255 ,255 ,255 },
263
+ math.ceil ((self .maxTime - self .time ) / constants .framerate ))
262
264
end
263
265
264
266
return Game
0 commit comments