def drawCaptureHealth(self, health, coords, player): #Create and add settings to the text we want to draw. Background needs to be set so we don't have per pixel alpha. label = self.captureFont.render(str(health), True, LIGHT_RED if player == PLAYER_ONE else LIGHT_BLUE, WHITE) label.set_colorkey(WHITE) label.set_alpha(100) #Find where to place the text. sizeDiff = subtractCoords(CELL_SIZE.size, subtractCoords(label.get_size(), (0, 10))) halfDiff = (sizeDiff[0] / 2, sizeDiff[1] / 2) #Draw the text. self.screen.blit(label, addCoords(coords, halfDiff))
def drawTextBox(self): #Start by drawing the text box in the appropriate color. pygame.draw.rect(self.screen, DARK_RED if self.textBoxContent == '' else LIGHT_GREEN, self.buttonRect.move(self.textPosition)) #Then draw the number in the text box. label = self.gameFont.render(self.textBoxContent + ('|' if self.boxSelected else ''), True, BLACK) offset = subtractCoords(self.buttonRect.center, label.get_rect().center) self.screen.blit(label, addCoords(self.textPosition, offset)) #Finally, draw the text box title. boxLabel = self.gameFont.render("Games to play:", True, BLACK) boxLabelOffset = (0, - boxLabel.get_height() - FIELD_SPACING) self.screen.blit(boxLabel, addCoords(self.textPosition, boxLabelOffset))
def drawCaptureHealths(self, health): label1 = self.monsterFont.render(str(health[0]), True, DARK_BLUE, WHITE) label2 = self.monsterFont.render(str(health[1]), True, DARK_RED, WHITE) #Find out where to put the text onscreen. label1Size = label1.get_size() label2Size = label2.get_size() label1Center = (label1Size[0] / 2, label1Size[1] / 2) label2Center = (label2Size[0] / 2, label2Size[1] / 2) boardCenter = ((self.screen.get_width() - self.buttonArea.width) / 2, self.screen.get_height() / 2) #Initialize destinations for the sake of scope. destination1 = 0 destination2 = 0 #Change the settings of the text surface to look the way it should. label1.set_colorkey(WHITE) label2.set_colorkey(WHITE) label1.set_alpha(50) label2.set_alpha(50) #Find out which case occured. Both players have anthills getting captured, or just one. if health[0] != -1 and health[1] != -1: #Make destinations offset for both units. destination1 = subtractCoords(boardCenter, (label1Size[0], label1Center[1])) destination2 = subtractCoords(boardCenter, (0, label2Center[1])) #Draw the text surface. self.screen.blit(label1, destination1) self.screen.blit(label2, destination2) elif health[0] != -1: destination1 = subtractCoords(boardCenter, label1Center) destination2 = 0 #Draw the text surface. self.screen.blit(label1, destination1) elif health[1] != -1: destination1 = 0 destination2 = subtractCoords(boardCenter, label2Center) #Draw the text surface. self.screen.blit(label2, destination2) else: print "Oh my gawd my code broke in UserInterface.drawCaptureHealth"
def drawButton(self, key, buttons): label = self.gameFont.render(key, True, BLACK) offset = subtractCoords(self.buttonRect.center, label.get_rect().center) self.screen.blit(self.buttonTextures[buttons[key][1]], buttons[key][0]) self.screen.blit(label, addCoords(buttons[key][0], offset))