def __init__(self, config, totalPlayerPoints): super().__init__() self.config = config self.totalPlayerPoints = totalPlayerPoints self.texture = QImage(self.config.endOfStageTotalPlayerPointsContainer) self.m_boundingRect = QRectF(0, 0, self.texture.width(), self.texture.height()) self.digits = [] for i in range(7): self.digits.append(i) self.extractDigitsFromPlayerPoints() self.numbers = [] for i in range(len(self.digits)): number = HudNumber(self, self.config.numberColors["white"], self.config.numberSize["big"], self.digits[i], self.config) number.setPos(self.x() + i * number.width, self.y()) self.numbers.append(number)
def __init__(self, config, tankDetails): super().__init__() self.config = config self.currentPoints = 0 self.pointsStep = tankDetails["pointsStep"] self.texture = QImage( self.config.endOfStageSeparateTankPointsContainer) self.m_boundingRect = QRectF(0, 0, self.texture.width(), self.texture.height()) self.digits = [] for i in range(4): self.digits.append(i) self.extractDigitsFromPlayerPoints() self.numbers = [] for i in range(len(self.digits)): number = HudNumber(self, self.config.numberColors["white"], self.config.numberSize["big"], self.digits[i], self.config) number.setPos(self.x() + i * number.width, self.y()) self.numbers.append(number)
def __init__(self, config, currentStage): super().__init__() self.config = config self.currentStage = currentStage self.texture = QImage(self.config.currentStageTexture) self.m_boundingRect = QRectF(0, 0, self.texture.width(), self.texture.height()) # handles only numbers from 0 to 99 self.digits = [] for i in range(2): self.digits.append(i) self.extractDigitsFromCurrentStage() self.numbers = [] for i in range(len(self.digits)): number = HudNumber(self, self.config.numberColors["black"], self.config.numberSize["small"], self.digits[i], self.config) number.setPos(self.x() + i * number.width, self.y() + 2 * self.texture.height() // 3) self.numbers.append(number)
def __init__(self, config, count): super().__init__() self.config = config self.currentCount = 0 self.count = count self.texture = QImage( self.config.endStageTanksPerPlayerCounterContainer) self.m_boundingRect = QRectF(0, 0, self.texture.width(), self.texture.height()) self.digits = [] for i in range(2): self.digits.append(i) self.extractDigitsFromCurrentCount() self.numbers = [] for i in range(len(self.digits)): number = HudNumber(self, self.config.numberColors["white"], self.config.numberSize["big"], self.digits[i], self.config) number.setPos(self.x() + i * number.width, self.y()) self.numbers.append(number) self.m_boundingRect = QRectF(0, 0, self.numbers[0].width, self.numbers[0].height)
def __init__(self, playerNum, config, initialLives): super().__init__() self.playerNum = playerNum self.config = config self.lives = initialLives self.texture = QImage(self.config.playersLives[f"player{self.playerNum}"]) self.m_boundingRect = QRectF(0, 0, self.texture.width(), self.texture.height()) self.firstDigit = None self.secondDigit = None self.extractDigits(self.lives) self.firstNumber = HudNumber(self, self.config.numberColors["black"], self.config.numberSize["small"], self.firstDigit, self.config) self.firstNumber.setPos(self.x() + self.texture.width() // 3, self.y() + self.texture.height() // 2) self.secondNumber = HudNumber(self, self.config.numberColors["black"], self.config.numberSize["small"], self.secondDigit, self.config) self.secondNumber.setPos(self.x() + 2 * self.texture.width() // 3, self.y() + self.texture.height() // 2)
class HudPlayerLives(QGraphicsItem): def __init__(self, playerNum, config, initialLives): super().__init__() self.playerNum = playerNum self.config = config self.lives = initialLives self.texture = QImage(self.config.playersLives[f"player{self.playerNum}"]) self.m_boundingRect = QRectF(0, 0, self.texture.width(), self.texture.height()) self.firstDigit = None self.secondDigit = None self.extractDigits(self.lives) self.firstNumber = HudNumber(self, self.config.numberColors["black"], self.config.numberSize["small"], self.firstDigit, self.config) self.firstNumber.setPos(self.x() + self.texture.width() // 3, self.y() + self.texture.height() // 2) self.secondNumber = HudNumber(self, self.config.numberColors["black"], self.config.numberSize["small"], self.secondDigit, self.config) self.secondNumber.setPos(self.x() + 2 * self.texture.width() // 3, self.y() + self.texture.height() // 2) def boundingRect(self): return self.m_boundingRect def paint(self, QPainter, QStyleOptionGraphicsItem, widget=None): QPainter.drawImage(0, 0, self.texture) def extractDigits(self, lives): if lives < 10: self.firstDigit = 0 self.secondDigit = lives else: number_string = str(lives) self.firstDigit = int(number_string[0]) self.secondDigit = int(number_string[1]) def updateLives(self, lives): self.extractDigits(lives) self.firstNumber.updateNumber(self.firstDigit) self.secondNumber.updateNumber(self.secondDigit)