コード例 #1
0
ファイル: piece_layer.py プロジェクト: jneem/clashadash
    def _updateChargeIndicator(self):
        """Displays a bar indicating how charged the unit is."""

        if hasattr(self._piece, 'chargeAtTurn') and hasattr(self._piece, 'turn'):
            maxValue = self._piece.chargeAtTurn(0)
            value = self._piece.toughness
            if self._chargeIndicator is None:
                bgColor = (255, 255, 255, 0)
                emptyColor = (255, 0, 0, 255)
                fullColor = (0, 255, 0, 255)
                self._chargeIndicator = MeterLayer(8, self.height, maxValue, bgColor, emptyColor, fullColor, horizontal=False)
                self.add(self._chargeIndicator)

            self._chargeIndicator.setValueAndMax(value, maxValue)
            self._chargeIndicator.position = (self.width-8, 0)
        else:
            if self._chargeIndicator is not None:
                self.remove(self._chargeIndicator)
                self._chargeIndicator = None
コード例 #2
0
ファイル: game_layer.py プロジェクト: jneem/clashadash
    def _addPlayerInfo(self, player, playerLayers, isBottomPlayer):
        """Add the player display (life, mana, etc.) layers to the game.
        """

        lifeMeter = MeterLayer(192, 16, player.maxLife,
                               (255, 255, 255, 127), # background color
                               (255, 0, 0, 255),     # empty life color
                               (0, 255, 0, 255))     # full life color
        lifeMeter.value = player.life
        self.add(lifeMeter)
        # Don't tie the life meter directly to the display, because for animating
        # attacks we prefer to update the life to sync up with the attack.
        #player.lifeChanged.addHandler(lambda x: lifeMeter.setValue(x))

        manaMeter = MeterLayer(192, 16, player.maxMana,
                               (255, 255, 255, 127), # background color
                               (130, 130, 130, 255), # empty mana color
                               (0, 0, 255, 255))     # full mana color
        manaMeter.value = player.mana
        self.add(manaMeter)
        player.manaChanged.addHandler(lambda x: manaMeter.setValue(x))

        movesTextBox = TextBoxLayer(player.maxMoves)
        self.add(movesTextBox)
        player.moveChanged.addHandler(lambda x: movesTextBox.setValue(x))

        unitsTextBox = TextBoxLayer(player.maxUnitTotal)
        self.add(unitsTextBox)
        player.unitChanged.addHandler(lambda x: unitsTextBox.setValue(x))

        boardY = BOTTOM_MARGIN
        if not isBottomPlayer:
            boardY += BOARD_HEIGHT + BOARD_GAP

        lifeMeter.position = (32, boardY + 112 + 16 + 32)
        manaMeter.position = (32, boardY + 112)
        movesTextBox.position = (32, boardY + 80)
        unitsTextBox.position = (32, boardY + 50)

        playerLayers.lifeMeter = lifeMeter
        playerLayers.manaMeter = manaMeter
        playerLayers.movesCounter = movesTextBox
        playerLayers.unitsCounter = unitsTextBox
コード例 #3
0
ファイル: piece_layer.py プロジェクト: jneem/clashadash
class PieceLayer(cocos.layer.Layer):
    def __init__(self, piece, width, height):
        super(PieceLayer, self).__init__()
        
        self._width = width
        self._height = height
        self._piece = piece
        #logging.debug('New piece layer %d x %d, image name %s' % (width, height, piece.imageName()))

        # Pieces with the 'color' property get a background.
        if hasattr(piece, 'color'):
            #logging.debug('color ' + str(piece.color))
            c = colors[piece.color]
            bg = ColorLayer(c[0], c[1], c[2], 192, width=width, height=height)
            self.add(bg)
            self._background = bg

        pieceSprite = Sprite(piece.imageName())
        pieceSprite.image_anchor_x = 0
        pieceSprite.image_anchor_y = 0

        # Scale the sprite to the correct size.
        rect = pieceSprite.get_rect()
        scale = min(float(width) / rect.width,
                    float(height) / rect.height)
        pieceSprite.scale = scale
        self._pieceSprite = pieceSprite

        self.add(pieceSprite)
        self._opacity = 255

        self._turnIndicator = None
        self._updateTurnIndicator()
        self._chargeIndicator = None
        self._updateChargeIndicator()

    @property
    def opacity(self):
        return self._opacity

    @opacity.setter
    def opacity(self, op):
        # This is a cheap version of transparency: just set the children
        # to be transparent.
        self._background.opacity = op
        self._pieceSprite.opacity = op
        self._opacity = op

    @property
    def width(self):
        return self._width

    @property
    def height(self):
        return self._height

    def _updateTurnIndicator(self):
        """Displays text indicating how many turns are left before attacking."""

        if hasattr(self._piece, 'turn'):
            if self._turnIndicator is None:
                self._turnIndicator = TurnIndicator(36)
                self.add(self._turnIndicator)

            self._turnIndicator.text = str(self._piece.turn)
            self._turnIndicator.position = (self.width / 2, self.height / 2)
        else:
            if self._turnIndicator is not None:
                self.remove(self._turnIndicator)
                self._turnIndicator = None

    def _updateChargeIndicator(self):
        """Displays a bar indicating how charged the unit is."""

        if hasattr(self._piece, 'chargeAtTurn') and hasattr(self._piece, 'turn'):
            maxValue = self._piece.chargeAtTurn(0)
            value = self._piece.toughness
            if self._chargeIndicator is None:
                bgColor = (255, 255, 255, 0)
                emptyColor = (255, 0, 0, 255)
                fullColor = (0, 255, 0, 255)
                self._chargeIndicator = MeterLayer(8, self.height, maxValue, bgColor, emptyColor, fullColor, horizontal=False)
                self.add(self._chargeIndicator)

            self._chargeIndicator.setValueAndMax(value, maxValue)
            self._chargeIndicator.position = (self.width-8, 0)
        else:
            if self._chargeIndicator is not None:
                self.remove(self._chargeIndicator)
                self._chargeIndicator = None

    def refresh(self):
        self._updateTurnIndicator()
        self._updateChargeIndicator()