@@ -62,11 +62,7 @@ def on_show_view(self):
6262
6363 def on_draw (self ):
6464 """ Draw this view """
65- counter = 0
6665 self .clear ()
67- if counter == 0 :
68- top_five = query_database ()
69- counter += 1
7066 # Draw stars
7167 for star in self .star_list :
7268 x , y = star
@@ -93,7 +89,7 @@ def on_draw(self):
9389 self .ui_manager_start .draw ()
9490 arcade .draw_text ("HIGH SCORE" , constant .SCREEN_WIDTH // 2 , constant .SCREEN_HEIGHT // 1.05 , arcade .color .RED , 20 ,
9591 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
96- arcade .draw_text (str (top_five [0 ][2 ]), constant .SCREEN_WIDTH // 2 , constant .SCREEN_HEIGHT // 1.1 ,
92+ arcade .draw_text (str (self . top_five [0 ][2 ]), constant .SCREEN_WIDTH // 2 , constant .SCREEN_HEIGHT // 1.1 ,
9793 arcade .color .WHITE , 20 ,
9894 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
9995 arcade .draw_text ("3GDOWN" , constant .SCREEN_WIDTH // 2 - 245 , constant .SCREEN_HEIGHT // 1.05 ,
@@ -259,8 +255,10 @@ class LeaderboardView(arcade.View):
259255 def __init__ (self , game_view ):
260256 super ().__init__ ()
261257 # Create UI manager and star list
258+ self .top_five = None
262259 self .star_list = []
263260 self .ui_manager_leaderboard = arcade .gui .UIManager ()
261+
264262
265263 def on_show_view (self ):
266264 arcade .set_background_color (arcade .color .BLACK )
@@ -289,22 +287,26 @@ def on_show_view(self):
289287 def on_draw (self ):
290288 self .clear ()
291289 # information from the firebase database
292- top_five = query_database ()
290+ queried = False
291+
292+ if not queried :
293+ self .top_five = query_database ()
294+
293295 for star in self .star_list :
294296 x , y = star
295297 arcade .draw_circle_filled (x , y , 2 , arcade .color .WHITE )
296298 self .ui_manager_leaderboard .draw ()
297299 # Draw leaderboard
298300 arcade .draw_text ("HIGH SCORE" , constant .SCREEN_WIDTH // 2 , constant .SCREEN_HEIGHT // 1.05 , arcade .color .RED , 20 ,
299301 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
300- arcade .draw_text (str (top_five [0 ][2 ]), constant .SCREEN_WIDTH // 2 , constant .SCREEN_HEIGHT // 1.1 ,
302+ arcade .draw_text (str (self . top_five [0 ][2 ]), constant .SCREEN_WIDTH // 2 , constant .SCREEN_HEIGHT // 1.1 ,
301303 arcade .color .WHITE , 20 ,
302304 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
303305 arcade .draw_text ("3GDOWN" , constant .SCREEN_WIDTH // 2 - 245 , constant .SCREEN_HEIGHT // 1.05 ,
304306 arcade .color .YELLOW ,
305307 20 ,
306308 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
307- arcade .draw_text (str (top_five [0 ][2 ]), constant .SCREEN_WIDTH // 2 - 245 , constant .SCREEN_HEIGHT // 1.1 ,
309+ arcade .draw_text (str (self . top_five [0 ][2 ]), constant .SCREEN_WIDTH // 2 - 245 , constant .SCREEN_HEIGHT // 1.1 ,
308310 arcade .color .WHITE ,
309311 20 ,
310312 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
@@ -335,63 +337,63 @@ def on_draw(self):
335337 arcade .color .CYAN ,
336338 20 ,
337339 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
338- arcade .draw_text (str (top_five [0 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 + 125 ,
340+ arcade .draw_text (str (self . top_five [0 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 + 125 ,
339341 arcade .color .RED ,
340342 20 ,
341343 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
342- arcade .draw_text (str (top_five [1 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 + 75 ,
344+ arcade .draw_text (str (self . top_five [1 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 + 75 ,
343345 arcade .color .BARBIE_PINK ,
344346 20 ,
345347 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
346- arcade .draw_text (str (top_five [2 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 + 25 ,
348+ arcade .draw_text (str (self . top_five [2 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 + 25 ,
347349 arcade .color .YELLOW ,
348350 20 ,
349351 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
350- arcade .draw_text (str (top_five [3 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 - 25 ,
352+ arcade .draw_text (str (self . top_five [3 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 - 25 ,
351353 arcade .color .GREEN ,
352354 20 ,
353355 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
354- arcade .draw_text (str (top_five [4 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 - 75 ,
356+ arcade .draw_text (str (self . top_five [4 ][0 ]), constant .SCREEN_WIDTH // 2 - 110 , constant .SCREEN_HEIGHT // 2 - 75 ,
355357 arcade .color .CYAN ,
356358 20 ,
357359 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
358- arcade .draw_text (str (top_five [0 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 + 125 ,
360+ arcade .draw_text (str (self . top_five [0 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 + 125 ,
359361 arcade .color .RED ,
360362 20 ,
361363 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
362- arcade .draw_text (str (top_five [1 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 + 75 ,
364+ arcade .draw_text (str (self . top_five [1 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 + 75 ,
363365 arcade .color .BARBIE_PINK ,
364366 20 ,
365367 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
366- arcade .draw_text (str (top_five [2 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 + 25 ,
368+ arcade .draw_text (str (self . top_five [2 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 + 25 ,
367369 arcade .color .YELLOW ,
368370 20 ,
369371 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
370- arcade .draw_text (str (top_five [3 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 - 25 ,
372+ arcade .draw_text (str (self . top_five [3 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 - 25 ,
371373 arcade .color .GREEN ,
372374 20 ,
373375 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
374- arcade .draw_text (str (top_five [4 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 - 75 ,
376+ arcade .draw_text (str (self . top_five [4 ][1 ]), constant .SCREEN_WIDTH // 2 + 50 , constant .SCREEN_HEIGHT // 2 - 75 ,
375377 arcade .color .CYAN ,
376378 20 ,
377379 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
378- arcade .draw_text (top_five [0 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 + 125 ,
380+ arcade .draw_text (self . top_five [0 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 + 125 ,
379381 arcade .color .RED ,
380382 20 ,
381383 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
382- arcade .draw_text (top_five [1 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 + 75 ,
384+ arcade .draw_text (self . top_five [1 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 + 75 ,
383385 arcade .color .BARBIE_PINK ,
384386 20 ,
385387 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
386- arcade .draw_text (top_five [2 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 + 25 ,
388+ arcade .draw_text (self . top_five [2 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 + 25 ,
387389 arcade .color .YELLOW ,
388390 20 ,
389391 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
390- arcade .draw_text (top_five [3 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 - 25 ,
392+ arcade .draw_text (self . top_five [3 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 - 25 ,
391393 arcade .color .GREEN ,
392394 20 ,
393395 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
394- arcade .draw_text (top_five [4 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 - 75 ,
396+ arcade .draw_text (self . top_five [4 ][2 ], constant .SCREEN_WIDTH // 2 + 240 , constant .SCREEN_HEIGHT // 2 - 75 ,
395397 arcade .color .CYAN ,
396398 20 ,
397399 anchor_x = "center" , anchor_y = "center" , font_name = "Emulogic" )
0 commit comments