def paint(self): self.game.screen.blit(self.background, (0,0)) font = pygame.font.Font("escenario/MagicSchoolOne.ttf",60) sf2 = hollow.textOutline(font, "You must first finish your career",(255,254,232), (0,0,0)) sf3 = hollow.textOutline(font, "before touring the world",(255,254,232), (0,0,0)) self.game.screen.blit(sf2, (400-sf2.get_width()/2, 350)) self.game.screen.blit(sf3, (400-sf3.get_width()/2, 420))
def paint(self): self.game.screen.blit(self.background, (0,0)) font = pygame.font.Font("escenario/MagicSchoolOne.ttf",65) font2 = pygame.font.Font("escenario/MagicSchoolOne.ttf",90) sf = hollow.textOutline(font2, "Enter your name",(255,254,232), (0,0,0)) self.game.screen.blit(sf, (400-sf.get_width()/2, 200)) sf = hollow.textOutline(font2, self.name,(255,254,232), (0,0,0)) self.game.screen.blit(sf, (400-sf.get_width()/2, 330))
def init(self, font, color=[(255,255,255), (255,255,0)], outline_color=[(0,0,0)]*2, line_step=40): self.line_step = line_step random.shuffle(self.us) random.shuffle(self.them) self.sections = self.us + self.them self.section_imgs = [] for section in self.sections: lines = [] for n,line in enumerate(section): img = hollow.textOutline(font, line, color[n], outline_color[n]) lines.append( img ) self.section_imgs.append( lines ) self.section_number = 0 self.state = self.BEGIN self.state_start = time.time() self.hand_pos = None self.hand_img = None self.puff = None self.puff_pos = None self.text = None self.nubes = [ pygame.image.load("escenario/nube/nube%d.png"%(n+1)).convert_alpha() for n in range(5) ] self.hand = pygame.image.load("escenario/manos/mano1.png").convert_alpha() self.hand2 = pygame.image.load("escenario/manos/mano2.png").convert_alpha() sounds.gritosfelicitacion()
def __init__(self): self.armed = False self.start = None font = pygame.font.Font("escenario/MagicSchoolOne.ttf",50) self.message = hollow.textOutline(font, "Start typing the spell!", (230,100,100), (0,0,0)) self.last_blink = None self.blink_state = True self.last_sound = None
def __init__(self, hechizo, font_size = 80, font = "escenario/MagicSchoolOne.ttf", altfont_size = 80, altfont = "escenario/VeraSe.ttf", width=600): self.font = pygame.font.Font(font,font_size) self.altfont = pygame.font.Font(altfont,altfont_size) text = set([ t for t in hechizo ]) self.cache = {} colores = [ [(130,130,170), (0,0,255)], [(255,255,0),(255,0,0)], [(170,170,100),(170,0,0)], [(255,0,0),(128,0,0)], ] for t in text: if t in " ,.<>:;": font = self.altfont else: font = self.font if t == " ": self.cache[t] = [ hollow.textOutline(font,t,*colores[0]), hollow.textOutline(font,t,*colores[1]), hollow.textOutline(font,"_",*colores[2]), hollow.textOutline(font,"_",*colores[3]) ] else: self.cache[t] = [ hollow.textOutline(font,t,*c) for c in colores ] self.height = self.cache[t][0].get_height() words = hechizo.split(" ") lines = [] current = "" line_len = 0 for word in words: word_len = sum([ self.get(l,0).get_width() for l in word ]) if line_len + word_len > width: lines.append( current[1:]+" " ) current = "" line_len = 0 current += " "+word line_len += 1+word_len lines.append( current[1:] ) self.lines = lines
def paint(self): self.game.screen.blit(self.background, (0,0)) font = pygame.font.Font("escenario/MagicSchoolOne.ttf",40) font2 = pygame.font.Font("escenario/MagicSchoolOne.ttf",90) font3 = pygame.font.Font("escenario/MagicSchoolOne.ttf",30) scores = self.client.listHiScores() for i in range(8): if i < len(scores): points, when, name, ip = scores[i] else: points, name = "--", "" if not name: name = " " sf1 = hollow.textOutline(font3, str(i),(255,254,232), (0,0,0)) sf2 = hollow.textOutline(font, name,(255,254,232), (0,0,0)) sf3 = hollow.textOutline(font, str(points),(255,254,232), (0,0,0)) ypos = 200 + i*30 self.game.screen.blit(sf1, (200-sf1.get_width(), ypos)) self.game.screen.blit(sf2, (270, ypos)) self.game.screen.blit(sf3, (620, ypos))
def __init__(self, font, font_selected, opts, margin=0, normal_color=(255,255,255), selected_color=(255,255,255), selected_border_color=None, normal_border_color=None): self.font = font self.font_selected = font_selected if selected_border_color == None: selected_border_color = (0,0,0) if normal_border_color == None: normal_border_color = (0,0,0) self.margin = margin self.color = color self.opts = opts self.selected = 0 self.selected_img = [] self.unselected_img = [] line_step = 0 for text in self.opts: sel = hollow.textOutline(font_selected, text, selected_color, selected_border_color ) unsel = hollow.textOutline(font, text, normal_color, normal_border_color ) self.selected_img.append( sel ) self.unselected_img.append( unsel ) line_step = max(max(sel.get_height(), unsel.get_height())+self.margin, line_step) self.line_step = line_step
def __init__(self, font, font_selected, opts, margin=0, normal_color=(255,255,255), selected_color=(255,255,255), selected_border_color=None, normal_border_color=None,rectangle=Point2(0,0)): self.font = font self.font_selected = font_selected if selected_border_color == None: selected_border_color = (0,0,0) if normal_border_color == None: normal_border_color = (0,0,0) self.margin = margin self.opts = opts self.selected = 0 self.selected_img = [] self.unselected_img = [] self.rectangle=rectangle line_step = 0 for tuple in self.opts: text = tuple[0] sel = hollow.textOutline(font_selected, text, selected_color, selected_border_color ) unsel = hollow.textOutline(font, text, normal_color, normal_border_color ) self.selected_img.append( sel ) self.unselected_img.append( unsel ) line_step = max(max(sel.get_height(), unsel.get_height())+self.margin, line_step) self.line_step = line_step
#figure out how much to rotate needle, rotate it, and draw it. angle_for_needle = get_angle(rpm_measured) rotated_needle = pygame.transform.rotate(needle_img, angle_for_needle) rect_for_rotated_needle = rotated_needle.get_rect( center=rect_for_rotated_needle.center) tachDisplay.blit(rotated_needle, rect_for_rotated_needle) #these 4 lines convert the gear to text to be drawn. if (current_gear > 0): text_to_draw = str(current_gear) else: text_to_draw = "N" #these 5 lines draw the gear indicator outlined_letter = textOutline(font, text_to_draw, text_interior_color, text_outline_color) text_to_get_box = font.render(text_to_draw, True, text_interior_color, text_back_color) textRect = text_to_get_box.get_rect() textRect.center = (440, 34) tachDisplay.blit(outlined_letter, textRect) pygame.display.update() #update drawing #clear buffers, and if too many bad rpm readings received reset obd connection pygame.event.pump() if (bad_message_count > 30): connection.close() connection = obd.OBD() bad_message_count = 0
def update(self): font = self.messagefont if self.state == PLAYING: #self.game.screen.blit(self.background, (0,0)) if self.linebyline: cursor = self.motor.cursor offset, line = self.line_manager.getLineFromCursor( cursor ) ypos = 540 xpos = (800-sum([ self.line_manager.get(l,0).get_width() for l in line ]))/2 cursor_xpos = xpos for position, letter in enumerate(line): style = self.motor.estado[position+offset] if position+offset == cursor: cursor_xpos = xpos i = self.line_manager.get(letter, self.motor.estado[position+offset]) self.game.screen.blit( i, (xpos, ypos) ) xpos += i.get_width() cursor_img = self.cursorfont.render("^", True, (255,255,255)) self.game.screen.blit(cursor_img, (cursor_xpos,ypos+self.line_manager.height) ) else: # paint forward xpos = 400 ypos = 300 cursor = self.motor.cursor if DEBUG: print "falta == ",self.motor.hechizo[cursor:] for position, letter in enumerate(self.motor.hechizo[cursor:]): style = self.motor.estado[position+cursor] i = self.line_manager.get(letter, self.motor.estado[position+cursor]) self.game.screen.blit( i, (xpos, ypos) ) xpos += i.get_width() if xpos > 800: break surface= self.line_manager.get(self.motor.hechizo[cursor], self.motor.estado[cursor]) width = surface.get_width() height = surface.get_height() cursor_sf = hollow.textOutline(self.cursorfont, "^", (150,150,250), (0,0,0)) self.game.screen.blit( cursor_sf, (400+width/2-cursor_sf.get_width()/2,370)) #pain backwards xpos = 400 letters = [l for l in self.motor.hechizo[:cursor]] if DEBUG: print "done==", self.motor.hechizo[:cursor] letters.reverse() for position, letter in enumerate(letters): style = self.motor.estado[-position+cursor] i = self.line_manager.get(letter, self.motor.estado[-1-position+cursor]) width = i.get_width() if xpos - width < 0: break xpos -= width self.game.screen.blit( i, (xpos, ypos) ) self.level_timer.blit( self.game.screen, (770, 50)) # ponemos el rate de teclas rate = self.motor.getRate() if rate < self.motor.precision_requerida: color_tx = (255,0,0) else: color_tx = (0,255,0) rate_sf = hollow.textOutline( self.ratefont, "%i%%"%(int(rate*100)), color_tx, (0,0,0) ) self.game.screen.blit( rate_sf, (770-rate_sf.get_width()/2, 35-rate_sf.get_height()/2)) # y el score score = self.motor.score score_sf = hollow.textOutline(self.ratefont, "Score: %3.1f"%score, (0,0,255), (0,0,0)) self.game.screen.blit( score_sf, (790-score_sf.get_width(), 15-score_sf.get_height()/2)) self.alarm.blit(self.game.screen) if self.state in [WON, LOST, TOMATO]: im = hollow.textOutline(font, "[press any key]", (30,30,200), (255,255,255)) ypos = 400 xpos = (800-im.get_width())/2 self.game.screen.blit( im, (xpos, ypos) )
def armarLetras(color1, color2): d = {} for l in "ABCDEFGHIJKLMNOPQRSTUVWXYZÑÃÇÕ*": d[l] = hollow.textOutline(font, l, color1, color2) return d