def drawBuffer(self, color, linewidth): surface = pygame.Surface((BUFFER_WIDTH, self.height*BLOCK_WIDTH)) transform = lambda y: (0, (self.height-1-y)*BLOCK_WIDTH) buffer_sum = sum(self.atk_buffer) for i in range(min(buffer_sum, self.height)): bar = make_surface(RED, (BUFFER_WIDTH, BLOCK_WIDTH)) surface.blit(bar, transform(i)) # add frame surface = add_frame(surface, color, linewidth) return surface
def drawHold(self, color, linewidth): surface = pygame.Surface((4*BLOCK_WIDTH, 4*BLOCK_WIDTH)) transform = lambda (x, y): (x*BLOCK_WIDTH, (3-y)*BLOCK_WIDTH) # hold piece if self.hold is not None: fx, fy = 2*BLOCK_WIDTH, 2*BLOCK_WIDTH cx, cy = find_center(self.hold.get_pos()) for x, y in self.hold.get_pos(): surface.blit(self.hold.pattern, (int(fx + (x-cx-0.5)*BLOCK_WIDTH), int(fy + (-y+cy-0.5)*BLOCK_WIDTH))) # resize to hold size surface = pygame.transform.scale(surface, HOLD_SIZE) # add frame surface = add_frame(surface, color, linewidth) return surface
def drawNext(self, color, linewidth): surfaceList = [] transform = lambda (x, y): (x*BLOCK_WIDTH, (3-y)*BLOCK_WIDTH) for i in range(self.next_size): nextmino = self.nextminos[i] surface = pygame.Surface((4*BLOCK_WIDTH, 4*BLOCK_WIDTH)) fx, fy = 2*BLOCK_WIDTH, 2*BLOCK_WIDTH cx, cy = find_center(nextmino.get_pos()) for x, y in nextmino.get_pos(): surface.blit(nextmino.pattern, (int(fx + (x-cx-0.5)*BLOCK_WIDTH), int(fy + (-y+cy-0.5)*BLOCK_WIDTH))) # resize to next size surface = pygame.transform.scale(surface, NEXT_SIZE) # add frame surface = add_frame(surface, color, linewidth) # add to list surfaceList.append(surface) return surfaceList
def drawStatus(self, color, linewidth): f = pygame.font.SysFont("Consolas", 24) text1 = f.render("%4d lines " % self.info.lineTot, 2, WHITE) text2 = f.render("%4d attack " % self.info.atkTot, 2, WHITE) text3 = f.render("%4d combo " % self.info.combo, 2, WHITE) text4 = f.render(self.getClearDescription(self.lineClear, self.tSpinDisplay), 2, WHITE) w1, h1 = text1.get_size() w2, h2 = text2.get_size() w3, h3 = text3.get_size() w4, h4 = text4.get_size() surface = pygame.Surface((max(w1, w2, w3, w4), h1 + h2 + h3 + h4)) surface.blit(text1, (0, 0)) surface.blit(text2, (0, h1)) surface.blit(text3, (0, h1 + h2)) surface.blit(text4, (0, h1 + h2 + h3)) # add frame surface = add_frame(surface, color, linewidth) return surface
def drawGrid(self, color, linewidth): surface = pygame.Surface((self.width*BLOCK_WIDTH, self.height*BLOCK_WIDTH)) transform = lambda (x, y): (x*BLOCK_WIDTH, (self.height-y-1)*BLOCK_WIDTH) # current map for i in range(self.width): for j in range(self.height): if self.pattern[i][j] is not None: surface.blit(self.pattern[i][j], transform((i, j))) else: surface.blit(self.default[i][j], transform((i, j))) # ghost piece ghost = self.mino.ghost(self) for pos in ghost.get_pos(): if self.check_inside(pos): surface.blit(ghost.pattern, transform(pos)) # current piece for pos in self.mino.get_pos(): if self.check_inside(pos): surface.blit(self.mino.pattern, transform(pos)) # add frame surface = add_frame(surface, color, linewidth) return surface