Facebook
From Algo, 1 Month ago, written in Python for S60.
Embed
Download Paste or View Raw
Hits: 140
  1. import pygame
  2. from random import randint
  3. pygame.init()
  4.  
  5.  
  6. #create a game window
  7. clock = pygame.time.Clock()
  8. back = (255, 255, 255) #background color
  9. mw = pygame.display.set_mode((500, 500)) #main window
  10. mw.fill(back)
  11.  
  12.  
  13. #colors
  14. BLACK = (0, 0, 0)
  15. LIGHT_BLUE = (200, 200, 255)
  16.  
  17.  
  18. class TextArea():
  19.    def __init__(self, x=0, y=0, width=10, height=10, color=None):
  20.        """ area: a rectangle in the right place and the right color """
  21.        #memorize the rectangle:
  22.        self.rect = pygame.Rect(x, y, width, height)
  23.        #fill color - either the passed parameter or the overall background color
  24.        self.fill_color = color
  25.  
  26.  
  27.    #place text
  28.    def set_text(self, text, fsize=12, text_color=BLACK):
  29.        self.text = text
  30.        self.image = pygame.font.Font(None, fsize).render(text, True, text_color)
  31.      
  32.    #draw a rectangle with text
  33.    def draw(self, shift_x=0, shift_y=0):
  34.        pygame.draw.rect(mw, self.fill_color, self.rect)
  35.        mw.blit(self.image, (self.rect.x + shift_x, self.rect.y + shift_y))  
  36.  
  37.  
  38.