Ejemplo n.º 1
0
    def add_button(self, b_type):
        if b_type == "1":
            x = 20
            y = 20
            category = "tower"
            texture = self.w.textures["tower_wood"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "2":
            x = 20
            y = 20 + self.b_size
            category = "tower"
            texture = self.w.textures["tower_poison"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "3":
            x = 20
            y = 20 + self.b_size * 2
            category = "tower"
            texture = self.w.textures["tower_splash"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "4":
            x = 20
            y = 20 + self.b_size * 3
            category = "tower"
            texture = self.w.textures["tower_chain"]
            active = True
            b_price = self.w.game.available_towers[b_type]
        elif b_type == "gold_icon":
            texture = image.load(RES_PATH + 'ui/gold.png')
            texture = center_image(texture)
            x = texture.width + 2
            y = self.w.height - (texture.height + 2)
            category = "ui"
            active = False
            b_price = False
            b_type = "icon"
        else:
            return False

        b_sprite = Sprite(
                        texture,
                        x=x, y=y,
                        batch=self.w.batches["buttons"],
                        group=self.w.ui_group
                    )

        b_sprite.category = category
        b_sprite.b_type = b_type
        b_sprite.active = active
        b_sprite.b_price = b_price
        self.sprites.append(b_sprite)
Ejemplo n.º 2
0
    def context_menu(self, obj, action="show"):
        self.wipe_context_menu()
        category = "context"
        texture = image.load(RES_PATH + 'ui/upgrade.png')
        texture = center_image(texture)
        offset =  (
            0.0 - texture.width // 2,
            obj.height // 2 + texture.height // 2
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )

        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price // 2
        if b_sprite.b_price > self.w.game.gold:
            b_sprite.opacity = 80
        b_sprite.b_type = "upgrade"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)

        size = 10
        offset = (
            0.0 - texture.width // 2 + 1,
            obj.height // 2 + texture.height // 2 + (size * 1.5) - 1
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(32, 32, 32, 196)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = True
        self.context_sprites.append(label)

        offset = (
            0.0 - texture.width // 2,
            obj.height // 2 + texture.height // 2 + (size * 1.5)
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(130, 255, 130, 255)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = False
        if obj.price // 2 > self.w.game.gold:
            label.color = (255, 140, 140, 225)
        self.context_sprites.append(label)

        texture = image.load(RES_PATH + 'ui/sell.png')
        texture = center_image(texture)
        offset =  (
            texture.width // 2,
            obj.height // 2 + texture.height // 2
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )
        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price
        b_sprite.b_type = "sell"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)
Ejemplo n.º 3
0
    def showContextMenu(self, obj, action="show"):
        self.wipeContextMenu()
        category = "context"
        texture = self.w.textures['upgrade']
        offset =  (
            -texture.width,
            0
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )

        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price // 2
        if b_sprite.b_price > self.w.game.gold:
            b_sprite.opacity = 80
        b_sprite.b_type = "upgrade"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)

        size = 10
        offset = (
            -texture.width - 1,
            texture.width // 2 - 1
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(32, 32, 32, 196)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = True
        self.context_sprites.append(label)

        size = 10
        offset = (
            0,
            obj.image.height
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(int(obj.dmg)), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(32, 32, 32, 255)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "towerinfo"
        label.category = category
        label.shadow = False
        self.context_sprites.append(label)

        offset = (
            -texture.width,
            texture.width // 2
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(130, 255, 130, 255)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = False
        if obj.price // 2 > self.w.game.gold:
            label.color = (255, 140, 140, 225)
        self.context_sprites.append(label)

        texture = self.w.textures["sell"]
        offset = (
            texture.width,
            0
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )
        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price
        b_sprite.b_type = "sell"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)