def __display_paused_message(self): dest = self.gamelogic.radar_surface font_size = dest.get_rect().height / 16 fontobj = pygame.font.Font(S.MAIN_FONT, font_size) lines = ['GAME IS PAUSED'] source = U.render_lines(fontobj, lines, S.RED) U.blit_dead_centre(dest, source)
def __get_max_line_length(self, fontobj): ''' Return the maximum number of characters that can fit on a line of the console. ''' chars_number = 2 while True: chars_number += 1 lines = ['-' * chars_number] width = U.render_lines(fontobj, lines, S.WHITE).get_width() if width > S.CLI_RECT.width: return chars_number - 2 #always leave some space to the right
def draw(self, surface): ''' Blit self on radar surface. ''' x, y = U.sc(self.location) # GATE # In order to facilitate blitting information on the orientation of the # gate, we create the image already rotated 90° clockwise by swapping # width and height... gate_width_px = U.rint(self.width / S.METRES_PER_PIXEL) gate_length_px = S.RADAR_RECT.h / 4 aaf = 5 #anti-alias factor g_img = pygame.surface.Surface((gate_length_px*aaf, gate_width_px*aaf), SRCALPHA) # BOUNDARIES OF THE GATE pygame.draw.line( g_img, S.GRAY, (0, aaf), (gate_length_px*aaf, aaf), aaf) pygame.draw.line( g_img, S.GRAY, (0, gate_width_px*aaf-aaf), (gate_length_px*aaf, gate_width_px*aaf-aaf), aaf) # INFO ON ORIENTATION and FLIGHT LEVELS fl = lambda x : str(x/100).zfill(2) lines = ['H:' + str(self.heading).zfill(3), 'B:' + fl(self.bottom), 'T:' + fl(self.top)] fontobj = pygame.font.Font(S.MAIN_FONT, S.HUD_INFO_FONT_SIZE * aaf) label = U.render_lines(fontobj, lines, S.GRAY) label = label.subsurface(label.get_bounding_rect()) w, h = label.get_size() ypsilon = U.rint(gate_width_px*aaf/2.0-h/2) g_img.blit(label, (0, ypsilon)) g_img.blit(label, (gate_length_px*aaf-w, ypsilon)) # tranformation and blitting rotang = 90 if 0<= self.heading < 180 else 270 g_img = pygame.transform.rotate(g_img, rotang-self.heading) g_img = g_img.subsurface(g_img.get_bounding_rect()).copy() r = g_img.get_rect() g_img = pygame.transform.smoothscale(g_img, (U.rint(r.w*1.0/aaf), U.rint(r.h*1.0/aaf))) g_rect = g_img.get_rect() surface.blit(g_img, (x-g_rect.centerx, y-g_rect.centery)) # LABEL fontobj = pygame.font.Font(S.MAIN_FONT, S.HUD_INFO_FONT_SIZE) label = fontobj.render(self.name, True, S.RED) w, h = label.get_size() signed_offset = lambda n : cmp(1,n)*w x += (signed_offset(x) if self.side <=0 else 0) - w/2 y += (signed_offset(y) if self.side >=0 else 0) - h/2 surface.blit(label, (x,y))