def simple_text(screen: pygame.display.set_mode, msgs: str, pos: str): """Simple Text Display Method which takes a line of text and a position and then either: * Prints String as option, displaying the first Letter of that String as the Hotkey to choose said Option * Prints text as info, no Hotkey Displayed It chooses to do the first one if position is `middle` and the second one if position is either `topleft`, `topright`. This is far from perfect but an alright way of quickly displaying text. """ color = (10, 10, 10) font_size = 32 if pos == 'middle' else 18 spacing = 25 if pos == 'middle' else 15 font = pygame.font.Font(None, font_size) for multiplier, msg in enumerate(msgs): if pos == 'middle': text = font.render(f'({msg[0]}) {msg}', 1, color) else: text = font.render(f'{msg}', 1, color) textpos = text.get_rect() textpos.top = 20 + spacing * multiplier if pos == 'middle': textpos.x = screen.get_rect().centerx - textpos.size[0] // 2 if pos == 'topleft': textpos.x = 10 if pos == 'topright': textpos.right = WINDOW_SIZE - 10 screen.blit(text, textpos)
def draw(self, screen: pygame.display.set_mode): if self.wrap: lines = wraptxt(text=self.label, fontsize=self.size, width=self.width) else: lines = [self.label] for i in range(len(lines)): screen.blit( pygame.font.Font("freesansbold.ttf", self.size).render(lines[i], True, self.color), (round(self.left), round(self.top) + i * (self.size + 2)))
def draw(self, screen: pygame.display.set_mode): screen.blit(self.bullet.img, (round(self.bullet.xpos), round(self.bullet.ypos))) screen.blit(self.bullet.explosion.img, (round( self.bullet.explosion.left), round(self.bullet.explosion.top))) screen.blit(pygame.transform.rotate(self.img, self.angle), (round(self.xpos), round(self.ypos))) screen.blit(self.explosion.img, (round(self.explosion.left), round(self.explosion.top)))
def draw(self, screen: pygame.display.set_mode): pbarbg = pygame.Surface((self.width, 14)) pbarbg.fill((0, 0, 0)) pbarbg.set_alpha(128) screen.blit(pbarbg, (self.left, self.top)) pygame.draw.rect(screen, self.back_color, (round(self.left), round(self.top), round(self.width), round(self.height)), 2) pygame.draw.rect(screen, self.progress_color, (round(self.progress_left), round(self.progress_top), round(self.progress_width), round(self.progress_height))) pbarlight = pygame.Surface((self.progress_width, self.progress_height - 5)) pbarlight.fill((255, 255, 255)) pbarlight.set_alpha(96) screen.blit(pbarlight, (self.progress_left, self.progress_top + self.height // 3)) pbarlight = pygame.Surface((self.progress_width, self.progress_height - (2 * self.progress_height // 3))) pbarlight.fill((255, 255, 255)) pbarlight.set_alpha(128) screen.blit(pbarlight, (self.progress_left, self.progress_top + self.height // 3 + 4)) screen.blit(pygame.font.Font("freesansbold.ttf", self.text.size).render(self.text.label, True, self.text.color), (round(self.text.left), round(self.text.top)))
def draw(self, screen: pygame.display.set_mode): screen.blit(self.img, (round(self.xpos), round(self.ypos))) screen.blit(self.explosion.img, (round(self.explosion.left), round(self.explosion.top)))
def draw(self, screen: pygame.display.set_mode): screen.blit( pygame.font.Font('freesansbold.ttf', 24).render(f"{self.mm:02d} : {self.ss:02d}", True, self.color), (self.left, self.top))
def draw(self, screen: pygame.display.set_mode): screen.blit(self.img, (round(self.xpos), round(self.ypos))) for i in range(self.weapon.count): if self.weapon.name == settings.WEAPON_LIST[0]: screen.blit( pygame.transform.rotate(self.weapon.img, -self.weapon.theta[i] * 180 / pi), (round(self.weapon.xpos[i]), round(self.weapon.ypos[i]))) elif self.weapon.name == settings.WEAPON_LIST[1]: screen.blit( self.weapon.img, (round(self.weapon.xpos[i]), round(self.weapon.ypos[i]))) elif self.weapon.name == settings.WEAPON_LIST[2]: cx, cy = self.weapon.xpos[0] + 16, self.weapon.ypos[0] + 16 jet_length1 = randint(20, 28) jet_length2 = randint(28, 36) jet_length3 = randint(36, 44) if self.weapon.xdir == "left": pygame.draw.line( screen, choice([(0, 200, 200), (0, 255, 255), (50, 255, 255)]), (round(cx), round(cy)), (round(cx) - jet_length1, round(cy)), 5) pygame.draw.line( screen, choice([(50, 255, 255), (100, 255, 255), (150, 255, 255)]), (round(cx), round(cy)), (round(cx) - jet_length2, round(cy)), 3) pygame.draw.line( screen, choice([(150, 200, 200), (200, 255, 255), (255, 255, 255)]), (round(cx), round(cy)), (round(cx) - jet_length3, round(cy)), 1) elif self.weapon.xdir == "right": pygame.draw.line( screen, choice([(0, 200, 200), (0, 255, 255), (50, 255, 255)]), (round(cx), round(cy)), (round(cx) + jet_length1, round(cy)), 5) pygame.draw.line( screen, choice([(50, 255, 255), (100, 255, 255), (150, 255, 255)]), (round(cx), round(cy)), (round(cx) + jet_length2, round(cy)), 3) pygame.draw.line( screen, choice([(150, 200, 200), (200, 255, 255), (255, 255, 255)]), (round(cx), round(cy)), (round(cx) + jet_length3, round(cy)), 1) if self.weapon.ydir == "up": pygame.draw.line( screen, choice([(0, 200, 200), (0, 255, 255), (50, 255, 255)]), (round(cx), round(cy)), (round(cx), round(cy) - jet_length1), 5) pygame.draw.line( screen, choice([(50, 255, 255), (100, 255, 255), (150, 255, 255)]), (round(cx), round(cy)), (round(cx), round(cy) - jet_length2), 3) pygame.draw.line( screen, choice([(150, 200, 200), (200, 255, 255), (255, 255, 255)]), (round(cx), round(cy)), (round(cx), round(cy) - jet_length3), 1) elif self.weapon.ydir == "down": pygame.draw.line( screen, choice([(0, 200, 200), (0, 255, 255), (50, 255, 255)]), (round(cx), round(cy)), (round(cx), round(cy) + jet_length1), 5) pygame.draw.line( screen, choice([(50, 255, 255), (100, 255, 255), (150, 255, 255)]), (round(cx), round(cy)), (round(cx), round(cy) + jet_length2), 3) pygame.draw.line( screen, choice([(150, 200, 200), (200, 255, 255), (255, 255, 255)]), (round(cx), round(cy)), (round(cx), round(cy) + jet_length3), 1) now = pygame.time.get_ticks() explosion_time = 1500 if now - self.weapon.detonation_time < explosion_time: radius_rate = round(self.weapon.explosion_radius * (explosion_time - (now - self.weapon.detonation_time)) / 2000) green_rate = round(200 * (now - self.weapon.detonation_time) / explosion_time) blue_rate = round(150 * (now - self.weapon.detonation_time) / explosion_time) width = 2 if radius_rate > width: pygame.draw.circle(screen, (255, green_rate, blue_rate, 128), (round(self.weapon.detonation_x), round(self.weapon.detonation_y)), radius_rate, width) screen.blit( self.weapon.img, (round(self.weapon.xpos[i]), round(self.weapon.ypos[i])))
def draw(self, screen: pygame.display.set_mode): screen.blit( pygame.font.Font('freesansbold.ttf', 16).render( str(self.fps) + " FPS", True, self.color), (self.left, self.top))
def draw(self, screen: pygame.display.set_mode): screen.blit(pygame.font.Font("freesansbold.ttf", 32).render("Level : " + str(self.level), True, (255, 255, 255)), (620, 552))
def draw(self, canvas: pygame.display.set_mode): canvas.blit(self.skin, self.head) for pos in self.body: canvas.blit(self.skin, pos)
def draw(self, canvas: pygame.display.set_mode): canvas.blit(self.skin, self.pos)
def draw(self, screen: pygame.display.set_mode): for i in range(3): screen.blit(pygame.font.Font("freesansbold.ttf", 14).render(self.msg[i], True, self.color[i]), (self.left, self.tops[i]))
def draw(self, screen: pygame.display.set_mode): screen.blit(self.img, (round(self.xpos), round(self.ypos)))