def drawTimer(screen): dur = (datetime.datetime.now() - settings.startTime).total_seconds() dur = math.floor(dur) negative = False if dur < 0: dur = dur * -1 negative = True tmp1 = datetime.timedelta(seconds=math.floor(dur)) delta = str(tmp1).split(" day") initialHours = 0 extraHours="" if len(delta)==1: extraHours = delta[0] elif len(delta)==2: days = delta[0] days = int(days) initialHours = days * 24 if delta[1][0]=="s": extraHours = delta[1][3:] elif delta[1][0]==",": extraHours = delta[1][2:] finalTime = extraHours.split(":") finalHours = int(finalTime[0]) + initialHours cur_time = str(finalHours)+":"+finalTime[1]+":"+finalTime[2] if negative: cur_time = "-"+cur_time #print(cur_time) r = pygame.Rect([0,0,400,100]) r.center = (1277,84) pygame.draw.rect(screen, (40, 40, 40), r) timer = settings.getFont(65).render(cur_time, 1, (200,200,200)) timer_r = timer.get_rect(center=(1277,84))#topright=, etc screen.blit(timer, timer_r) pygame.display.update(r) return cur_time
def draw(screen, playerLookup, sortedRacers, page): screen.blit(pygame.transform.scale(background, (1600, 900)), (0, 0)) timer.drawTimer(screen) if (settings.mode == "246") or (settings.mode == "sandbox"): page = 1 if page == 2: slot = 0 for i, r in enumerate(sortedRacers): if 2 < i < 28: playerLookup[r].corner = slots[len(slots) - 1] continue if slot >= len(slots): playerLookup[r].corner = slots[len(slots) - 1] else: playerLookup[r].corner = slots[slot] if slot == 2: slot += 3 else: slot += 1 else: slot = 0 for r in sortedRacers: if slot >= len(slots): playerLookup[r].corner = slots[len(slots) - 1] else: playerLookup[r].corner = slots[slot] if slot == 2: slot += 3 else: slot += 1 #-----------scorecard drawing------------ for key in playerLookup: currentPlayer = playerLookup[key] corner = currentPlayer.corner pygame.draw.rect(screen, (25, 25, 25), [corner[0], corner[1], 314, 142]) score = currentPlayer.collects if currentPlayer.status == "live": bg = None gameCounts, barLengths, gameMaxes = [], [], [] done = False smallBar, largeBar, barHeight = 110, 260, 20 for i, g in enumerate(games): gameCounts.append(0) if done: pass elif score <= g['count']: bg = g['background'] if score == g['count']: bg = games[i + 1]['background'] gameCounts[-1] = score done = True score -= g['count'] else: gameCounts[-1] = g['count'] score -= g['count'] gameMaxes.append(g['count']) barLengths.append( math.floor((gameCounts[-1] / g['count']) * smallBar)) img = pygame.transform.scale(bg, (310, 138)) screen.blit(img, (corner[0] + 2, corner[1] + 2)) # base boxes s = pygame.Surface((smallBar + 4, barHeight), pygame.SRCALPHA) s.fill((60, 60, 60, 192)) screen.blit(s, (40 + corner[0], 80 + corner[1])) screen.blit(s, (190 + corner[0], 80 + corner[1])) screen.blit(s, (40 + corner[0], 110 + corner[1])) if len(games) == 4: screen.blit(s, (190 + corner[0], 110 + corner[1])) # filled boxes gray = (150, 150, 150) rects = [] rects.append( pygame.draw.rect(screen, gray, [ 40 + corner[0] + 2, 80 + corner[1] + 2, barLengths[0], barHeight - 4 ])) rects.append( pygame.draw.rect(screen, gray, [ 40 + corner[0] + 2, 110 + corner[1] + 2, barLengths[1], barHeight - 4 ])) rects.append( pygame.draw.rect(screen, gray, [ 190 + corner[0] + 2, 80 + corner[1] + 2, barLengths[2], barHeight - 4 ])) if len(games) == 4: rects.append( pygame.draw.rect(screen, gray, [ 190 + corner[0] + 2, 110 + corner[1] + 2, barLengths[3], barHeight - 4 ])) # individual game counts for i in range(len(gameCounts)): if gameCounts[i] < gameMaxes[i] / 2: label = getFont(18).render(str(gameCounts[i]), 1, (220, 220, 220)) label_r = label.get_rect(midleft=(rects[i].midright[0] + 2, rects[i].midright[1])) else: label = getFont(18).render(str(gameCounts[i]), 1, (60, 60, 60)) label_r = label.get_rect(midright=(rects[i].midright[0] - 2, rects[i].midright[1])) screen.blit(label, label_r) # game icons for i, g in enumerate(games): if i == 0: x, y = 6, 75 elif i == 1: x, y = 6, 103 elif i == 2: x, y = 157, 70 elif i == 3: x, y = 157, 108 screen.blit(g['icon'], (x + corner[0], y + corner[1])) elif currentPlayer.status == "done": #shows done tag bg = pygame.transform.scale(finishBG, (310, 138)) screen.blit(bg, (corner[0] + 2, corner[1] + 2)) # screen.blit(finishBG, (playerLookup[key].corner[0], playerLookup[key].corner[1])) doneTag = getFont(60).render("Done!", 1, (220, 220, 220)) done_r = doneTag.get_rect(center=((currentPlayer.corner[0] + (length / 2), 85 + currentPlayer.corner[1]))) screen.blit(doneTag, done_r) label = getFont(24).render( str("Final Time: {0}".format(currentPlayer.completionTime)), 1, (220, 220, 220)) label_r = label.get_rect(center=((currentPlayer.corner[0] + (length / 2), 125 + currentPlayer.corner[1]))) screen.blit(label, label_r) else: text = "" offset = 0 label = getFont(23).render( "Completion: " + str(score) + "/" + str(settings.max_score) + " in " + currentPlayer.completionTime, 1, (220, 220, 220)) if currentPlayer.status == "quit": text = "Quit" elif currentPlayer.status == "disqualified": text = "Disqualified" elif currentPlayer.status == "noshow": label = getFont(20).render("", 1, (220, 220, 220)) text = "No-Show" offset = 10 textTag = getFont(48).render(text, 1, (255, 0, 0)) text_r = textTag.get_rect( center=(currentPlayer.corner[0] + (length / 2), currentPlayer.corner[1] + 80 + offset)) screen.blit(textTag, text_r) label_r = label.get_rect(center=(currentPlayer.corner[0] + (length / 2), currentPlayer.corner[1] + 123)) screen.blit(label, label_r) #-------scorecard header------- #profile picture prof = pygame.transform.scale(currentPlayer.profile, (50, 50)) screen.blit(prof, (8 + currentPlayer.corner[0], 8 + currentPlayer.corner[1])) #name & place color = (220, 220, 220) if currentPlayer.place <= 3: color = (239, 195, 0) nameRender = getFont(24).render(str(currentPlayer.nameCaseSensitive), 1, color) placeRender = getFont(40).render(str(currentPlayer.place), 1, color) screen.blit( nameRender, (65 + currentPlayer.corner[0], 15 + currentPlayer.corner[1])) #topright justify the place text place_r = placeRender.get_rect(topright=(currentPlayer.corner[0] + 304, currentPlayer.corner[1] + 5)) screen.blit(placeRender, place_r) pygame.display.flip() return screen
def draw(screen, playerLookup, sortedRacers, page): screen.blit(pygame.transform.scale(background, (1600, 900)), (0, 0)) drawTimer(screen) if page == 2: slot = 0 for i, r in enumerate(sortedRacers): if 2 < i < 28: playerLookup[r].corner = slots[len(slots) - 1] continue if slot >= len(slots): playerLookup[r].corner = slots[len(slots) - 1] else: playerLookup[r].corner = slots[slot] if slot == 2: slot += 3 else: slot += 1 else: slot = 0 for r in sortedRacers: if slot >= len(slots): playerLookup[r].corner = slots[len(slots) - 1] else: playerLookup[r].corner = slots[slot] if slot == 2: slot += 3 else: slot += 1 #-----------scorecard drawing------------ for key in playerLookup: currentPlayer = playerLookup[key] corner = currentPlayer.corner pygame.draw.rect(screen, (25, 25, 25), [corner[0], corner[1], 314, 142]) score = currentPlayer.collects if currentPlayer.status == "live": smocount = smscount = sm64count = 0 if score < 124: bg = smoBG smocount = score elif score < 168: bg = smsBG smocount = 124 smscount = score - 124 elif score < 238: bg = sm64BG smocount = 124 smscount = 44 sm64count = score - 168 img = pygame.transform.scale(bg, (310, 138)) screen.blit(img, (corner[0] + 2, corner[1] + 2)) smallBar = 110 #136 largeBar = 260 #322 barHeight = 20 smolength = math.floor((smocount / 124) * smallBar) #smglength = math.floor((smgcount/120)*largeBar) smslength = math.floor((smscount / 44) * smallBar) sm64length = math.floor((sm64count / 70) * smallBar) # base boxes s = pygame.Surface((smallBar + 4, barHeight), pygame.SRCALPHA) s.fill((60, 60, 60, 192)) screen.blit(s, (40 + corner[0], 80 + corner[1])) screen.blit(s, (190 + corner[0], 80 + corner[1])) screen.blit(s, (40 + corner[0], 110 + corner[1])) #screen.blit(s, (190+corner[0], 110+corner[1]) ) # filled boxes r1 = pygame.draw.rect(screen, (150, 150, 150, 254), [ 40 + corner[0] + 2, 80 + corner[1] + 2, smolength, barHeight - 4 ]) r2 = pygame.draw.rect(screen, (150, 150, 150, 254), [ 40 + corner[0] + 2, 110 + corner[1] + 2, smslength, barHeight - 4 ]) r3 = pygame.draw.rect(screen, (150, 150, 150, 254), [ 190 + corner[0] + 2, 80 + corner[1] + 2, sm64length, barHeight - 4 ]) #r4 = pygame.draw.rect(screen, (150,150,150,254), [190+corner[0]+2, 110+corner[1]+2, smg2length, barHeight-4]) # individual game counts for i, gme in enumerate([(smocount, r1), (smscount, r2), (sm64count, r3)]): if gme[0] < star_counts[i] / 2: label = getFont(18).render(str(gme[0]), 1, (220, 220, 220)) label_r = label.get_rect(midleft=(gme[1].midright[0] + 2, gme[1].midright[1])) else: label = getFont(18).render(str(gme[0]), 1, (60, 60, 60)) label_r = label.get_rect(midright=(gme[1].midright[0] - 2, gme[1].midright[1])) screen.blit(label, label_r) # game icons screen.blit(moon, (6 + corner[0], 75 + corner[1])) screen.blit(shine, (6 + corner[0], 103 + corner[1])) screen.blit(star, (157 + corner[0], 70 + corner[1])) #screen.blit(yoshi, (157+corner[0], 108+corner[1]) ) elif currentPlayer.status == "done": #shows done tag test = pygame.transform.scale(finishBG, (310, 138)) screen.blit(test, (corner[0] + 2, corner[1] + 2)) # screen.blit(finishBG, (playerLookup[key].corner[0], playerLookup[key].corner[1])) doneTag = getFont(60).render("Done!", 1, (220, 220, 220)) done_r = doneTag.get_rect(center=((currentPlayer.corner[0] + (length / 2), 85 + currentPlayer.corner[1]))) screen.blit(doneTag, done_r) label = getFont(24).render( str("Final Time: {0}".format(currentPlayer.completionTime)), 1, (220, 220, 220)) label_r = label.get_rect(center=((currentPlayer.corner[0] + (length / 2), 125 + currentPlayer.corner[1]))) screen.blit(label, label_r) else: text = "" offset = 0 label = getFont(23).render( "Completion: " + str(score) + "/" + str(settings.max_score) + " in " + currentPlayer.completionTime, 1, (220, 220, 220)) if currentPlayer.status == "quit": text = "Quit" elif currentPlayer.status == "disqualified": text = "Disqualified" elif currentPlayer.status == "noshow": label = getFont(20).render("", 1, (220, 220, 220)) text = "No-Show" offset = 10 textTag = getFont(48).render(text, 1, (255, 0, 0)) text_r = textTag.get_rect( center=(currentPlayer.corner[0] + (length / 2), currentPlayer.corner[1] + 80 + offset)) screen.blit(textTag, text_r) label_r = label.get_rect(center=(currentPlayer.corner[0] + (length / 2), currentPlayer.corner[1] + 123)) screen.blit(label, label_r) #-------scorecard header------- #profile picture prof = pygame.transform.scale(currentPlayer.profile, (50, 50)) screen.blit(prof, (8 + currentPlayer.corner[0], 8 + currentPlayer.corner[1])) #name & place color = (220, 220, 220) if currentPlayer.place <= 3: color = (239, 195, 0) nameRender = getFont(24).render(str(currentPlayer.nameCaseSensitive), 1, color) placeRender = getFont(40).render(str(currentPlayer.place), 1, color) screen.blit( nameRender, (65 + currentPlayer.corner[0], 15 + currentPlayer.corner[1])) #topright justify the place text place_r = placeRender.get_rect(topright=(currentPlayer.corner[0] + 304, currentPlayer.corner[1] + 5)) screen.blit(placeRender, place_r) pygame.display.flip() return screen