Tema: Pygame Dudas
Ver Mensaje Individual
  #11 (permalink)  
Antiguo 13/07/2009, 21:20
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 2 meses
Puntos: 1360
Respuesta: Pygame Dudas

Encontre un codigo que habia hecho hace tiempo. Espero que te sirva

Código python:
Ver original
  1. #!/usr/bin/env python
  2. #coding: UTF-8
  3.  
  4. import pygame
  5. from string import letters
  6. from string import whitespace
  7.  
  8. pygame.init()
  9. size = width, height = 640, 480
  10.  
  11. #Colors
  12. black = (0, 0, 0)
  13. white = (255, 255, 255)
  14. green = (0, 255, 0)
  15. blue = (0, 0, 255)
  16. red = (255, 0, 0)
  17.  
  18. class Text:
  19.     def __init__(self, FontName = None, FontSize = 20):
  20.         pygame.font.init()
  21.         self.font = pygame.font.Font(FontName, FontSize)
  22.         self.size = FontSize
  23.  
  24.     def render(self, surface, text, color, position):
  25.         text = unicode(text, "UTF-8")
  26.         x, y = position
  27.         for i in text.split("\r"):
  28.             surface.blit(self.font.render(i, 1, color), (x, y))
  29.             y += self.size
  30.  
  31. screen = pygame.display.set_mode(size)
  32. pygame.display.set_caption("UTF-8 con pygame")
  33. text = Text("font.ttf", 30)
  34. s = ""
  35. pygame.key.set_repeat(100)
  36. while True:
  37.     for event in pygame.event.get():
  38.         if event.type == pygame.QUIT:
  39.             exit()
  40.         if event.type == pygame.KEYDOWN:
  41.            if event.unicode in letters or event.unicode in whitespace:
  42.                s += str(event.unicode)
  43.            if event.key == pygame.K_BACKSPACE and len(s) > 0:
  44.                s = s[:-1]
  45.            if event.key == pygame.K_ESCAPE:
  46.             exit()
  47.  
  48.     screen.fill(white)
  49.     text.render(screen, s, black, (0, 0))
  50.     pygame.display.flip()