我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用pygame.draw()。
def draw(self): (w, h) = self.size self.draw_button() triangle_size = self.style.button_text_font_size / 2 self.text(self.selected[0], xy=(5, h / 2), size = (w-10-triangle_size,h), align="left", color=self.style.button_text_color, font=self.style.button_text_font, font_size=self.style.button_text_font_size) triangle_points = ((w-5, (h-triangle_size) / 2), (w - 5 - triangle_size/2, (h+triangle_size) / 2), (w - 5 - triangle_size, (h-triangle_size) / 2)) pygame.draw.polygon(self.surface, _color(self.style.button_text_color), triangle_points)
def render(self): screen = self.screen pos = self.pos message = string.join(self.current_string, "") if self.selected: pygame.draw.rect(screen, (172, 172, 172), (pos[0], pos[1], self.geometry[0], self.geometry[1]), 1) pygame.draw.rect(screen, (255, 255, 255), (pos[0] + 1, pos[1] + 1, self.geometry[0] - 2, self.geometry[1] - 2), 0) else: pygame.draw.rect(screen, (172, 172, 172), (pos[0], pos[1], self.geometry[0], self.geometry[1]), 1) pygame.draw.rect(screen, (251, 252, 254), (pos[0] + 1, pos[1] + 1, self.geometry[0] - 2, self.geometry[1] - 2), 0) pygame.draw.rect(screen, (248, 250, 253), (pos[0] + 3, pos[1] + 3, self.geometry[0] - 6, self.geometry[1] - 6), 0) clip = 0 if len(message) != 0: if self.fontobj.size(message)[0] > self.geometry[0] - 5: while self.fontobj.size(message)[0] > self.geometry[0] - 5: message = message[1:] clip += 1 screen.blit(self.fontobj.render(message, True, (30, 30, 30)), (pos[0] + 3, pos[1] + 3)) if int(time.time()) % 2 == 0 and self.selected: lx = pos[0] + 3 + self.fontobj.size(string.join(self.current_string[clip:self.curpos], ""))[0] pygame.draw.line(screen, (30, 30, 30), (lx, pos[1] + 3), (lx, pos[1] + self.geometry[1] - 4))
def draw(self): self.screen.fill((212, 212, 212)) image = pygame.image.load(os.path.join('/Users/emmadrost/Documents/Development/python/euromast1.bmp')) self.screen.blit(image,(0, 0)) self.Rects.draw(self.screen) pygame.display.flip()
def program_loop(self): while not process_events(): self.update() self.draw()
def draw(self, screen, x1, y1, x2, y2): pygame.draw.rect(screen, self.Color, (int(x1), int(y1), int(x2), int(y2)))
def draw(self,screen): start_button = pygame.draw.rect(screen,blue,(0.1*self.Mainmenu.width,0.1*self.Mainmenu.height,0.3*self.Mainmenu.width,25)) # start highscore_button = pygame.draw.rect(screen,blue,(0.1*self.Mainmenu.width,0.2*self.Mainmenu.height,0.3*self.Mainmenu.width,25)) #high score spelregels_button = pygame.draw.rect(screen,blue,(0.1*self.Mainmenu.width,0.3*self.Mainmenu.height,0.3*self.Mainmenu.width,25)) #spelregels multiplayer_button = pygame.draw.rect(screen,blue,(0.1*self.Mainmenu.width,0.4*self.Mainmenu.height,0.3*self.Mainmenu.width,25)) #multiplayer quit_button = pygame.draw.rect(screen,blue,(0.1*self.Mainmenu.width,0.5*self.Mainmenu.height,0.3*self.Mainmenu.width,25)) # quit
def draw(self, screen): pygame.draw.rect(screen, white, (int(self.x1), int(self.y1), int(self.x2), int(self.y2)))
def display_box(screen, message): "Print a message in a box in the middle of the screen" fontobject = pygame.font.Font(None,18) pygame.draw.rect(screen, (0,0,0), ((screen.get_width() / 2) - 100, (screen.get_height() / 2) - 10, 200,20), 0) pygame.draw.rect(screen, (255,255,255), ((screen.get_width() / 2) - 102, (screen.get_height() / 2) - 12, 204,24), 1) if len(message) != 0: screen.blit(fontobject.render(message, 1, (255,255,255)), ((screen.get_width() / 2) - 100, (screen.get_height() / 2) - 10)) pygame.display.flip()
def drawpoly(targetsurface,polyverts,incolor,bordercolor,border): pygame.draw.polygon(targetsurface,incolor,polyverts,0) if border != 0: pygame.draw.polygon(targetsurface,bordercolor,polyverts,border) # Generate ngon poly list:
def renderplayer(targetsurface): polyverts = ngonlist(gamewidth//2,gameheight//2,pstate,pradius,pangle) pygame.draw.line(targetsurface,colors[saturated[pcolor]],polyverts[0],(polyverts[0][0] + 0.25*pradius*math.cos(pangle),polyverts[0][1] + 0.25*pradius*math.sin(pangle)),2) drawpoly(targetsurface,polyverts,colors[saturated[pcolor]],colors['black'],2) # Enemy stuff:
def renderhall(self): winners = [w for w in players.winners if w.name] if not winners: return None textfont = txt.Font(None, 24) smallfont = txt.Font(None, 16) count = min(4, len(players.winners)) size = count*160, 70 img = pygame.Surface(size) img.fill((30,30,80)) pygame.draw.rect(img, (50, 50, 100), img.get_rect(), 1) img.blit(fame, (8, 3)) left = 90 firstone = 1 for p in winners: if not firstone: pygame.draw.line(img, (50, 50, 100), (left-80, 20), (left-80, 60), 1) img.blit(*textfont.text((240, 240, 240), p.name, (left, 40))) if p.cheater: img.blit(*smallfont.text((160, 160, 160), 'Cheater', (left, 58))) elif p.lives: if p.skips: img.blit(*smallfont.text((160, 160, 160), '%d ships, %d skips'%(p.lives,p.skips), (left, 58))) else: img.blit(*smallfont.text((160, 160, 160), '%d ships'%p.lives, (left, 58))) left += 160 firstone = 0 return img, Rect((gfx.rect.width-size[0]-10, 520), size)
def draw(self, gfx): percent = 1.0 - (self.clocks / self.life) c1 = (percent * 0.4 + 0.2) * 255 c2 = c1 / 4 color = (c1, c2, c2) pygame.draw.line(gfx.surface, color, self.start, self.end, 3) gfx.dirty(self.rect)
def __init__(self, **kwargs): """??? ????? game_name ???? icon ????? screen_size ???? display_mode ???? loop_speed ????? font_name ????? font_size ???? """ pygame.init() pygame.mixer.init() self.game_name = kwargs.get("game_name") or GAME_NAME pygame.display.set_caption(self.game_name) self.screen_size = kwargs.get("screen_size") or SCREEN_SIZE self.screen_width, self.screen_height = self.screen_size self.display_mode = kwargs.get("display_mode") or DISPLAY_MODE self.images = {} self.sounds = {} self.musics = {} self.icon = kwargs.get("icon") or None self.icon and pygame.display.set_icon(pygame.image.load(self.icon)) self.screen = pygame.display.set_mode(self.screen_size, self.display_mode) self.loop_speed = kwargs.get("loop_speed") or LOOP_SPEED self.font_name = kwargs.get("font_name") or FONT_NAME self.font_size = kwargs.get("font_size") or FONT_SIZE self.font = pygame.font.Font(self.font_name, self.font_size) self.clock = pygame.time.Clock() self.now = 0 self.background_color = kwargs.get("background") or BLACK self.set_background() self.key_bindings = {} # ????????? self.add_key_binding(KEY_PAUSE, self.pause) self.game_actions = {} # ???????? self.draw_actions = [self.draw_background] # ???????? self.running = True self.draw = pygame.draw