コード例 #1
0
ファイル: weapons.py プロジェクト: Holodome/worms.py
    def __init__(self):
        super().__init__(
            Rect(0, Window.Instance.height * 2 / 3, Window.Instance.width,
                 Window.Instance.height / 3))
        self.set_color(Color(40, 40, 40, 230))

        self.title = Label(
            Loader.get_font("ALoveOfThunder.ttf",
                            200).render("WEAPONS", False, (180, 10, 0)))
        self.title.constraints.add_width_constraint(
            RelativeMultConstraint(0.25))
        self.title.constraints.add_height_constraint(AspectConstraint())
        self.title.constraints.add_x_constraint(RelativeMultConstraint(1))
        self.title.constraints.add_y_constraint(RelativeMultConstraint(1))
        self.add_element(self.title)

        self.weaponListContainer = Container()
        self.weaponListContainer.set_color(Color(35, 35, 35, 230))
        self.weaponListContainer.constraints.add_x_constraint(
            RelativeMultConstraint(1))
        self.weaponListContainer.constraints.add_y_constraint(
            RelativeMultConstraint(1.15))
        self.weaponListContainer.constraints.add_width_constraint(
            RelativeMultConstraint(1))
        self.weaponListContainer.constraints.add_height_constraint(
            RelativeMultConstraint(0.85))
        self.add_element(self.weaponListContainer)
        for i, weapon in enumerate(Weapons):
            weapon_img = weapon.HoldImage.copy()
            pygame.draw.rect(weapon_img, (255, 0, 0), weapon_img.get_rect(), 1)
            weapon_btn = Button(weapon_img)

            x = i // 2 * 0.05 + 0.15
            y = 0.5 if i % 2 == 1 else 0.1

            weapon_btn.constraints.add_x_constraint(RelativeAddConstraint(x))
            weapon_btn.constraints.add_y_constraint(RelativeAddConstraint(y))
            weapon_btn.constraints.add_width_constraint(
                RelativeMultConstraint(0.045))
            weapon_btn.constraints.add_height_constraint(AspectConstraint())
            weapon_btn.set_click_function(self.set_id_wrapper(i))
            self.weaponListContainer.add_element(weapon_btn)

        self.explodeTimeLabel = Label(
            Loader.get_font("ALoveOfThunder.ttf",
                            200).render("3", False, (180, 10, 0)))
        self.explodeTimeLabel.constraints.add_x_constraint(
            RelativeAddConstraint(0.05))
        self.explodeTimeLabel.constraints.add_y_constraint(
            RelativeAddConstraint(0.1))
        self.explodeTimeLabel.constraints.add_width_constraint(
            RelativeMultConstraint(0.035))
        self.explodeTimeLabel.constraints.add_height_constraint(
            AspectConstraint())
        self.weaponListContainer.add_element(self.explodeTimeLabel)

        self.lastSelectedWeaponID = 0
コード例 #2
0
ファイル: weapons.py プロジェクト: Holodome/worms.py
 def set_time(self, time: int):
     assert 1 <= time <= 5
     self.explodeTimeLabel.set_image(
         Loader.get_font("ALoveOfThunder.ttf",
                         200).render(str(time), False, (180, 10, 0)))