import pygame
+from color import Color
from rectangle import Rectangle
+from text import Text
pygame.init()
clock = pygame.time.Clock()
delta = 0
-# Testing Rectangle
-r = Rectangle(100, 100, 100, 100, (255, 0, 0))
-r2 = Rectangle(200, 200, 100, 100, (0, 255, 0), (0, 0, 255), 5, 10)
-r3 = Rectangle(300, 300, 100, 100, (0, 0, 255), (255, 0, 0), 5, 10)
+# Testing Text
+a = Text(100, 100, "Hello World", "Arial", 20, color=Color.RED)
+b = Text(100, 200, "Word hunt", "Imprint Shadow", 20)
+c = Rectangle(100, 300, 100, 100, (255, 0, 0))
is_running = True
while is_running:
screen.fill((255, 255, 255))
- r.draw(screen)
- r2.draw(screen)
- r3.move(delta * 10, delta * 10)
- r3.draw(screen)
+ a.draw(screen)
+ b.move(delta * 10, delta * 10)
+ b.set_text("Word hunt " + str(round(clock.get_fps())) + " FPS")
+ b.draw(screen)
+ c.draw(screen)
pygame.display.update()
delta = clock.tick(60) / 1000 # Seconds since last frame
--- /dev/null
+import pygame
+from color import Color
+from rectangle import Rectangle
+
+
+class Text:
+
+ def __init__(self, x, y, text, font, font_size, color=Color.BLACK):
+ self.x = x
+ self.y = y
+ self.text = text
+ self.font_size = font_size
+ self.font = pygame.font.SysFont(font, self.font_size)
+ self.color = color
+
+ self.text_surface = self.font.render(self.text, True, self.color)
+
+ def update(self):
+ self.text_surface = self.font.render(self.text, True, self.color)
+
+ def set_position(self, x, y):
+ self.x = x
+ self.y = y
+
+ def move(self, dx, dy):
+ self.x += dx
+ self.y += dy
+
+ def set_text(self, text):
+ self.text = text
+ self.update()
+
+ def set_font(self, font, font_size):
+ self.font_size = font_size
+ self.font = pygame.font.SysFont(font, font_size)
+ self.update()
+
+ def set_color(self, color):
+ self.color = color
+ self.update()
+
+ def draw(self, screen):
+ screen.blit(self.text_surface, (self.x, self.y))