コード例 #1
0
 def update_load_data(self):
     if self.selected_button:
         self.loadname_label.set_text(self.selected_button.get_text())
         self.loadtime_label.set_text(self.load_metadata["time"])
         self.loadplname_label.set_text(self.load_metadata["player_name"])
         self.loadcrystals_label.set_text(millify_num(self.load_metadata["crystals"]) + " carbonic crystals")
         self.loadgame_button.set_callback(self.load_game, self.selected_button.get_text())
         self.loadgame_button.set_active(True)
     else:
         self.loadname_label.set_text("")
         self.loadtime_label.set_text("")
         self.loadplname_label.set_text("")
         self.loadcrystals_label.set_text("")
         self.loadgame_button.set_active(False)
コード例 #2
0
    def __init__(self, x, y, reward_name, amount):
        super().__init__()

        self.totalwidth = 36

        font_16 = pygame.font.Font("assets/Dosis.otf", 16)

        # Reward image
        reward_image = MGUI.ImageWidget(x, y, 32, 32,
                                        self.reward_images[reward_name])
        reward_image.set_icon_autoscale(True)
        self.add_widget(reward_image, "image")

        tmp_x = x + reward_image.get_width() / 2
        # Reward label
        reward_label = MGUI.Label(0, 0, 0, 0, font_16, millify_num(amount))
        reward_label.set_text_resize(res_hor=True, res_ver=True)
        reward_label.set_position(tmp_x - reward_label.get_width() / 2, y + 32)
        reward_label.set_transparent(True)
        self.add_widget(reward_label, "label")

        if reward_label.get_width() + 8 > self.totalwidth:
            self.totalwidth = reward_label.get_width() + 8
コード例 #3
0
    def __init__(self, x, y, width, height, base_buildings, player_data,
                 place_building_method):
        super().__init__()

        self.base_buildings = base_buildings

        backg_widget = MGUI.Widget(x, y, width, height)
        backg_widget.set_background((60, 20, 60, 150))
        backg_widget.set_border(True, (150, 20, 150))
        self.add_widget(backg_widget, "background", layer=3)

        font_22 = pygame.font.Font("assets/Dosis.otf", 22)
        font_16 = pygame.font.Font("assets/Dosis.otf", 16)
        build_label = MGUI.Label(x + 4, y + 4, width - 8, 0, font_22,
                                 "Build...")
        build_label.set_text_resize(res_ver=True, padding=4)
        build_label.set_background((60, 20, 60, 255))
        build_label.set_border(True, backg_widget.get_border_color())
        self.add_widget(build_label, "build_label", layer=4)

        # Building buttons
        button_start_y = build_label.get_position(
        )[1] + build_label.get_height() + 4
        button_height = 64
        self.building_buttons = []
        for i, bname in enumerate(player_data.owned_buildings):
            self.building_buttons.append(bname)
            bdata = self.base_buildings[bname]

            button_x = x + 4
            button_y = button_start_y + 90 * i

            # Background
            tmp_bg = MGUI.Widget(button_x, button_y, width - 8, button_height)
            tmp_bg.set_background((80, 0, 80))
            tmp_bg.set_border(True, (150, 0, 150))
            self.add_widget(tmp_bg, "button_" + bname + "_bg", layer=4)

            # Image
            tmp_img = MGUI.ImageWidget(button_x, button_y, button_height,
                                       button_height,
                                       "assets/buildings/" + bdata["base_img"])
            tmp_img.set_border(True, tmp_bg.get_border_color())
            self.add_widget(tmp_img, "button_" + bname + "_img", layer=5)

            tmp_x = button_x + tmp_img.get_width() - 1
            tmp_width = tmp_bg.get_width() - tmp_img.get_width() + 1
            # Name label
            tmp_name_label = MGUI.Label(tmp_x, button_y, tmp_width, 0, font_16,
                                        bname)
            tmp_name_label.set_text_resize(res_ver=True)
            tmp_name_label.set_background(tmp_bg.get_background())
            tmp_name_label.set_border(True, tmp_bg.get_border_color())
            self.add_widget(tmp_name_label,
                            "button_" + bname + "_namelabel",
                            layer=5)

            tmp_y = button_y + tmp_name_label.get_height()
            tmp_height = tmp_bg.get_height() - tmp_name_label.get_height() - 2
            cost_img_width = 18
            # Cost label & img
            tmp_cost_label = MGUI.Label(0, 0, 0, tmp_height, font_16,
                                        "Cost: " + millify_num(bdata["cost"]))
            tmp_cost_label.set_text_resize(res_hor=True, padding=4)
            tmp_x += 1 + tmp_width / 2 - (tmp_cost_label.get_width() +
                                          cost_img_width) / 2
            tmp_y += 1
            tmp_cost_label.set_position(tmp_x, tmp_y)
            tmp_cost_label.set_background(tmp_bg.get_background())
            self.add_widget(tmp_cost_label,
                            "button_" + bname + "_costlabel",
                            layer=5)

            tmp_x += tmp_cost_label.get_width()
            tmp_cost_img = MGUI.AnimSprite(tmp_x,
                                           tmp_y,
                                           cost_img_width,
                                           tmp_height,
                                           "assets/materials/energy.png",
                                           4,
                                           autosize=False)
            tmp_cost_img.set_icon_autoscale(False)
            self.add_widget(tmp_cost_img,
                            "button_" + bname + "_costimg",
                            layer=5)

            # Place building button
            tmp_place_button = MGUI.Button(button_x, button_y + button_height,
                                           tmp_bg.get_width(), 22, font_16,
                                           "Place building")
            tmp_place_button.set_callback(place_building_method, [bname])
            tmp_place_button.set_background(tmp_bg.get_background())
            tmp_place_button.set_border(True, tmp_bg.get_border_color())
            tmp_place_button.set_hovered_color((150, 0, 150, 100))
            tmp_place_button.set_pressed_color((70, 0, 70, 100))
            self.add_widget(tmp_place_button,
                            "button_" + bname + "_place",
                            layer=5)
コード例 #4
0
    def __init__(self, x, y, bdata, bname, amount, bunits):
        super().__init__()

        font_16 = pygame.font.Font("assets/Dosis.otf", 16)
        font_21 = pygame.font.Font("assets/Dosis.otf", 21)

        self.total_width = 191

        # Building info frame
        buildinfo_frame = MGUI.Widget(x, y, self.total_width, 234)
        buildinfo_frame.set_transparent(True)
        buildinfo_frame.set_border(True, (255, 100, 255))
        self.add_widget(buildinfo_frame, "buildinfo_frame")

        tmp_x = x + 2
        tmp_y = y + 2
        # Building map icon reference
        build_mapicon = MGUI.Widget(tmp_x, tmp_y, 28, 28)
        build_mapicon.set_background(bdata["map_color"])
        self.add_widget(build_mapicon, "build_mapicon")

        tmp_width = buildinfo_frame.get_width() - 5 - build_mapicon.get_width()
        # Building name
        build_name_label = MGUI.Label(tmp_x + build_mapicon.get_width() + 1,
                                      tmp_y, tmp_width,
                                      build_mapicon.get_height(), font_21,
                                      bname)
        if build_name_label.get_font().size(
                build_name_label.get_text())[0] > build_name_label.get_width():
            build_name_label.set_text_resize(res_hor=True)
        build_name_label.set_transparent(True)
        build_name_label.set_border(True, (255, 100, 255))
        self.add_widget(build_name_label, "build_name_label", layer=1)

        tmp_y += build_name_label.get_height() + 1
        # Building image
        build_image = MGUI.ImageWidget(tmp_x, tmp_y, 64, 64,
                                       "assets/buildings/" + bdata["base_img"])
        build_image.set_border(True, (255, 100, 255))
        self.add_widget(build_image, "build_image")

        tmp_x += build_image.get_width() + 4
        tmp_y += 8
        # Building health
        build_health_label = MGUI.Label(
            tmp_x, tmp_y, 0, 0, font_16,
            "Health: " + millify_num(bdata["maxhp"]))
        build_health_label.set_transparent(True)
        build_health_label.set_text_resize(res_hor=True, res_ver=True)
        self.add_widget(build_health_label, "build_health_label")

        tmp_y += build_health_label.get_height() + 2
        # Building amount in level
        build_amt_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                     "Amount in level: " + str(amount))
        build_amt_label.set_transparent(True)
        build_amt_label.set_text_resize(res_hor=True, res_ver=True)
        self.add_widget(build_amt_label, "build_amt_label")

        tmp_x, tmp_y = build_image.get_position()
        tmp_y += build_image.get_height() + 1
        # Spawner unit info
        if bdata["type"] == buildings.buildtype_spawner:
            unitsp = bunits[bdata["spawn_unit"]]
            unitsp_imgdata = unitsp["img_data"]

            # Unit name label
            unitsp_label = MGUI.Label(tmp_x, tmp_y,
                                      buildinfo_frame.get_width() - 4, 0,
                                      font_21, bdata["spawn_unit"])
            unitsp_label.set_text_resize(res_ver=True)
            unitsp_label.set_transparent(True)
            unitsp_label.set_border(True, (255, 100, 255))
            self.add_widget(unitsp_label, "unitsp_label")

            # Animated unit image
            tmp_y += unitsp_label.get_height() + 1
            unitsp_image = MGUI.AnimSprite(tmp_x,
                                           tmp_y,
                                           0,
                                           0,
                                           icon="assets/units/" +
                                           unitsp_imgdata["img"],
                                           frames=unitsp_imgdata["frames"],
                                           autosize=True)
            unitsp_image.set_icon_autoscale(False)
            if unitsp_image.get_bounds().width > build_image.get_width(
            ) or unitsp_image.get_bounds().height > build_image.get_height():
                unitsp_image.set_icon_autoscale(True)
            unitsp_image.set_icon_autosize(False)
            unitsp_image.set_bounds_size(*build_image.get_size())

            if "animations" in unitsp_imgdata and "base" in unitsp_imgdata[
                    "animations"]:
                unitsp_image.set_animation_data(
                    {"base": unitsp_imgdata["animations"]["base"]})
            if "anim_delay" in unitsp_imgdata:
                unitsp_image.set_animation_delay(unitsp_imgdata["anim_delay"])
            unitsp_image.set_border(True, (255, 100, 255))
            self.add_widget(unitsp_image, "unitsp_image")

            tmp_y += 2
            tmp_x += unitsp_image.get_width() + 4
            # Unit health icon
            unithealth_img = MGUI.ImageWidget(tmp_x,
                                              tmp_y,
                                              18,
                                              18,
                                              "assets/UI/heart.png",
                                              smooth=True)
            unithealth_img.set_icon_autoscale(True)
            self.add_widget(unithealth_img, "unithealth_img")

            tmp_x += unithealth_img.get_width() + 4
            # Unit health label
            unithealth_label = MGUI.Label(tmp_x, tmp_y - 1, 0, 0, font_16,
                                          millify_num(unitsp["maxhp"]))
            unithealth_label.set_text_resize(res_hor=True, res_ver=True)
            unithealth_label.set_transparent(True)
            unithealth_label.set_font_color((255, 110, 110))
            self.add_widget(unithealth_label, "unithealth_label")

            tmp_x += unithealth_label.get_width() + 8
            # Unit speed icon
            unitspeed_img = MGUI.ImageWidget(tmp_x, tmp_y, 18, 18,
                                             "assets/UI/speed_boot.png")
            unitspeed_img.set_icon_autoscale(True)
            self.add_widget(unitspeed_img, "unitspeed_img")

            tmp_x += unitspeed_img.get_width() + 4
            # Unit speed label
            unitspeed_label = MGUI.Label(tmp_x, tmp_y - 1, 0, 0, font_16,
                                         millify_num(unitsp["speed"]))
            unitspeed_label.set_text_resize(res_hor=True, res_ver=True)
            unitspeed_label.set_transparent(True)
            unitspeed_label.set_font_color((110, 255, 110))
            self.add_widget(unitspeed_label, "unitspeed_label")

            tmp_x = unithealth_img.get_position()[0]
            tmp_y += unithealth_img.get_height() + 2
            # Unit damage to player icon
            unit_pldmg_img = MGUI.ImageWidget(tmp_x, tmp_y, 18, 18,
                                              "assets/UI/escape.png")
            unit_pldmg_img.set_icon_autoscale(True)
            self.add_widget(unit_pldmg_img, "unit_pldmg_img")

            tmp_x += unit_pldmg_img.get_width() + 4
            # Unit damage to player label
            unit_pldmg_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                          millify_num(unitsp["dmg_player"]))
            unit_pldmg_label.set_text_resize(res_ver=True, res_hor=True)
            unit_pldmg_label.set_transparent(True)
            unit_pldmg_label.set_font_color((255, 255, 110))
            self.add_widget(unit_pldmg_label, "unit_pldmg_label")

            tmp_x += unit_pldmg_label.get_width() + 8
            # Unit attack speed icon
            unit_attspd_img = MGUI.ImageWidget(tmp_x, tmp_y, 0, 0,
                                               "assets/UI/attack_speed.png",
                                               True)
            self.add_widget(unit_attspd_img, "unit_attspd_img")

            tmp_x += unit_attspd_img.get_width() + 4
            # Unit attack speed label
            unit_attspd_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                           str(unitsp["attspd"]))
            unit_attspd_label.set_text_resize(res_ver=True, res_hor=True)
            unit_attspd_label.set_transparent(True)
            unit_attspd_label.set_font_color((110, 255, 110))
            self.add_widget(unit_attspd_label, "unit_attspd_label")

            # region ---- UNIT DAMAGE TYPES INFORMATION ----
            tmp_x, tmp_y = unitsp_image.get_position()
            tmp_x += 2
            tmp_y += unitsp_image.get_height() + 4
            # Unit physical damage icon
            unit_physdmg_img = MGUI.ImageWidget(tmp_x, tmp_y, 18, 18,
                                                "assets/UI/attack_swords.png")
            unit_physdmg_img.set_icon_autoscale(True)
            self.add_widget(unit_physdmg_img, "unit_physdmg_img")

            tmp_x += unit_physdmg_img.get_width() + 4
            # Unit physical damage label
            tmp_text = "0"
            if "dmg_phys" in unitsp:
                tmp_text = millify_num(unitsp["dmg_phys"])
            unit_physdmg_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                            tmp_text)
            unit_physdmg_label.set_text_resize(res_hor=True, res_ver=True)
            unit_physdmg_label.set_transparent(True)
            self.add_widget(unit_physdmg_label, "unit_physdmg_label")

            tmp_x += unit_physdmg_label.get_width() + 8
            # Unit fire damage image
            unit_firedmg_img = MGUI.ImageWidget(
                tmp_x, tmp_y, 18, 18, "assets/UI/firedmg_swords.png")
            unit_firedmg_img.set_icon_autoscale(True)
            self.add_widget(unit_firedmg_img, "unit_firedmg_img")

            tmp_x += unit_firedmg_img.get_width() + 4
            tmp_text = "0"
            if "dmg_fire" in unitsp:
                tmp_text = millify_num(unitsp["dmg_fire"])
            # Unit fire damage label
            unit_firedmg_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                            tmp_text)
            unit_firedmg_label.set_text_resize(res_hor=True, res_ver=True)
            unit_firedmg_label.set_transparent(True)
            unit_firedmg_label.set_font_color((255, 180, 110))
            self.add_widget(unit_firedmg_label, "unit_firedmg_label")

            tmp_x += unit_firedmg_label.get_width() + 8
            # Unit cold damage image
            unit_colddmg_img = MGUI.ImageWidget(
                tmp_x, tmp_y, 18, 18, "assets/UI/colddmg_swords.png")
            unit_colddmg_img.set_icon_autoscale(True)
            self.add_widget(unit_colddmg_img, "unit_colddmg_img")

            tmp_x += unit_colddmg_img.get_width() + 4
            tmp_text = "0"
            if "dmg_cold" in unitsp:
                tmp_text = millify_num(unitsp["dmg_cold"])
            # Unit cold damage label
            unit_colddmg_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                            tmp_text)
            unit_colddmg_label.set_text_resize(res_hor=True, res_ver=True)
            unit_colddmg_label.set_transparent(True)
            unit_colddmg_label.set_font_color((110, 200, 255))
            self.add_widget(unit_colddmg_label, "unit_colddmg_label")

            tmp_x += unit_colddmg_label.get_width() + 8
            # Unit lightning damage image
            unit_lningdmg_img = MGUI.ImageWidget(
                tmp_x, tmp_y, 18, 18, "assets/UI/lightningdmg_swords.png")
            unit_lningdmg_img.set_icon_autoscale(True)
            self.add_widget(unit_lningdmg_img, "unit_lningdmg_img")

            tmp_x += unit_lningdmg_img.get_width() + 4
            tmp_text = "0"
            if "dmg_lightning" in unitsp:
                tmp_text = millify_num(unitsp["dmg_lightning"])
            # Unit lightning damage label
            unit_lningdmg_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                             tmp_text)
            unit_lningdmg_label.set_text_resize(res_hor=True, res_ver=True)
            unit_lningdmg_label.set_transparent(True)
            unit_lningdmg_label.set_font_color((255, 200, 110))
            self.add_widget(unit_lningdmg_label, "unit_lningdmg_label")
            # endregion

            # region ---- UNIT RESISTANCE TYPES INFORMATION ----
            tmp_x = unit_physdmg_img.get_position()[0]
            tmp_y += unit_physdmg_img.get_height() + 1
            # Unit armor image
            unitarmor_img = MGUI.ImageWidget(tmp_x, tmp_y, 18, 18,
                                             "assets/UI/armor.png")
            unitarmor_img.set_icon_autoscale(True)
            self.add_widget(unitarmor_img, "unitarmor_img")

            tmp_x += unitarmor_img.get_width() + 4
            tmp_text = "0"
            if "armor" in unitsp:
                tmp_text = millify_num(unitsp["armor"])
            # Unit armor label
            unitarmor_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16, tmp_text)
            unitarmor_label.set_text_resize(res_hor=True, res_ver=True)
            unitarmor_label.set_transparent(True)
            self.add_widget(unitarmor_label, "unitarmor_label")

            tmp_x += unitarmor_label.get_width() + 8
            # Unit fire resistance image
            unit_fireres_img = MGUI.ImageWidget(tmp_x, tmp_y, 18, 18,
                                                "assets/UI/fire_res.png")
            unit_fireres_img.set_icon_autoscale(True)
            self.add_widget(unit_fireres_img, "unit_fireres_img")

            tmp_x += unit_fireres_img.get_width() + 4
            tmp_text = "0"
            if "res_fire" in unitsp:
                tmp_text = millify_num(unitsp["res_fire"])
            # Unit fire resistance label
            unit_fireres_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                            tmp_text)
            unit_fireres_label.set_text_resize(res_hor=True, res_ver=True)
            unit_fireres_label.set_transparent(True)
            unit_fireres_label.set_font_color(
                unit_firedmg_label.get_font_color())
            self.add_widget(unit_fireres_label, "unit_fireres_label")

            tmp_x += unit_fireres_label.get_width() + 8
            # Unit cold resistance image
            unit_coldres_img = MGUI.ImageWidget(tmp_x, tmp_y, 18, 18,
                                                "assets/UI/cold_res.png")
            unit_coldres_img.set_icon_autoscale(True)
            self.add_widget(unit_coldres_img, "unit_coldres_img")

            tmp_x += unit_coldres_img.get_width() + 4
            tmp_text = "0"
            if "res_cold" in unitsp:
                tmp_text = millify_num(unitsp["res_cold"])
            # Unit cold resistance label
            unit_coldres_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                            tmp_text)
            unit_coldres_label.set_text_resize(res_hor=True, res_ver=True)
            unit_coldres_label.set_transparent(True)
            unit_coldres_label.set_font_color(
                unit_colddmg_label.get_font_color())
            self.add_widget(unit_coldres_label, "unit_coldres_label")

            tmp_x += unit_coldres_label.get_width() + 8
            # Unit lightning resistance image
            unit_lningres_img = MGUI.ImageWidget(
                tmp_x, tmp_y, 18, 18, "assets/UI/lightning_res.png")
            unit_lningres_img.set_icon_autoscale(True)
            self.add_widget(unit_lningres_img, "unit_lningres_img")

            tmp_x += unit_lningres_img.get_width() + 4
            tmp_text = "0"
            if "res_lightning" in unitsp:
                tmp_text = millify_num(unitsp["res_lightning"])
            # Unit lightning resistance label
            unit_lningres_label = MGUI.Label(tmp_x, tmp_y, 0, 0, font_16,
                                             tmp_text)
            unit_lningres_label.set_text_resize(res_hor=True, res_ver=True)
            unit_lningres_label.set_transparent(True)
            unit_lningres_label.set_font_color(
                unit_lningdmg_label.get_font_color())
            self.add_widget(unit_lningres_label, "unit_lningres_label")
            # endregion

        # Fix width
        for w in self.widgets_dict:
            w = self.widgets_dict[w][0]
            w_fullwidth = w.get_position(
            )[0] - self["buildinfo_frame"].get_position()[0] + w.get_width()
            if w_fullwidth > self.total_width:
                self.total_width = w_fullwidth + 2
                self["buildinfo_frame"].set_bounds_size(
                    self.total_width, buildinfo_frame.get_height())
コード例 #5
0
    def handle_event(self, event_list):
        super().handle_event(event_list)

        if self.finishmsg.is_visible():
            return

        self.tick()

        sel_tile = self.map_coll.selected_tile

        # Handle events
        for event in event_list:
            if event.type in {pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN}:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                buildmenu_hovered = self.buildmenu.is_visible() and \
                                    self.buildmenu["background"].get_bounds_at(self.x, self.y).collidepoint(mouse_x, mouse_y)

                if not buildmenu_hovered:
                    self.map_coll.set_hovered(True)
                else:
                    self.map_coll.set_hovered(False)
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_p:  # Pause game
                    self.paused = not self.paused
                elif event.key == pygame.K_DELETE:  # Delete building
                    if sel_tile:
                        self.remove_building(self.get_building_at(sel_tile.x, sel_tile.y), sell=True)
                elif event.key in {pygame.K_1, pygame.K_2, pygame.K_3, pygame.K_4, pygame.K_5, pygame.K_6, pygame.K_7, pygame.K_8, pygame.K_9}:
                    if self.buildmenu.is_visible():
                        num_press = int(event.unicode) - 1
                        try:
                            self.place_building(self.player_data.owned_buildings[num_press])
                        except IndexError:
                            pass

        # Open buildings panel when selecting tile
        if sel_tile and sel_tile.owned and not self.get_building_at(sel_tile.x, sel_tile.y):
            if not self.buildmenu.is_visible():
                self.buildmenu.set_visible(True)
                self.buildmenu.update_data(self.energy)
        else:
            if self.buildmenu.is_visible():
                self.buildmenu.set_visible(False)

        self.map_coll.handle_event(event_list)
        self.map_coll.update()

        cam_x, cam_y = self.map_coll.get_camera_position()
        for h in range(self.levelmap.height):
            # Update buildings
            for b in self.building_list[h]:
                bx, by = b.get_draw_position()
                if not b.get_position() == (bx + cam_x, by + cam_y):
                    b.set_position(bx + cam_x, by + cam_y)

            # Update units
            for u in self.unit_list[h]:
                ux, uy = u.get_draw_position()
                if not u.get_position() == (ux + cam_x, uy + cam_y):
                    u.set_position(ux + cam_x, uy + cam_y)

        # Update energy label
        energy_txt = millify_num(self.energy) + " energy"
        self.energy_label.set_text(energy_txt)

        # Update health label
        health_txt = millify_num(self.health) + " health"
        self.health_label.set_text(health_txt)

        # Update pause label
        if not self.paused_label.is_visible() == self.paused:
            self.paused_label.set_visible(self.paused)
コード例 #6
0
    def __init__(self, x, y, width, height, player_data):
        super().__init__(x, y, width, height)
        self.player_data = player_data
        self.energy = 0
        self.energy_ps = 0
        self.health = 0

        self.ticker = 0
        self.paused = False
        self.victory = False

        # Load base buildings/units
        with open("assets/buildings.json", "r") as file:
            self.base_buildings = json.loads(file.read())
        with open("assets/units.json", "r") as file:
            self.base_units = json.loads(file.read())

        self.backg_widget.set_border(True, (200, 200, 200))

        self.levelmap = LevelMap(0, 0, 0, 0)
        self.levelmap.set_visible(False)

        self.map_coll = MapCollection(x, y, width, height, self.levelmap)
        self.add_element(self.map_coll.get_widgets_list())

        # Buildings menu panel
        self.buildmenu = PlayerBuildMenu(4, 4, 200, height - 8, self.base_buildings, player_data, self.place_building)
        self.buildmenu.set_visible(False)
        self.add_element(self.buildmenu.get_widgets_list())

        # Game finished message panel
        self.finishmsg = GameFinishMSG(width / 2, height / 2)
        self.finishmsg["continue_button"].set_callback(self.switch_target, ["main"])
        self.finishmsg.set_visible(False)
        self.add_element(self.finishmsg.get_widgets_list())

        # Buildings data
        self.building_list = []

        # Units data
        self.unit_list = []
        self.unit_layer = MGUI.GUICanvas(0, 0, *self.get_size())
        self.unit_layer.backg_widget.set_transparent(True)

        font = pygame.font.Font("assets/Dosis.otf", 18)
        # Energy img & label
        self.energy_label = MGUI.Label(width / 2, 8, 0, 0, font, millify_num(self.energy) + " energy")
        self.energy_label.set_text_resize(res_hor=True, res_ver=True, padding=2)
        self.energy_label.set_transparent(True)
        self.energy_label.set_font_color((255, 210, 255))
        self.add_element(self.energy_label, layer=10)

        self.energy_img = MGUI.AnimSprite(0, 0, 0, 0, "assets/materials/energy.png", 4)
        tmp_x = self.energy_label.get_position()[0] - self.energy_img.get_width() - 2
        self.energy_img.set_position(tmp_x, self.energy_label.get_position()[1] - 2)
        self.add_element(self.energy_img, layer=10)

        # Health img & label
        self.health_label = MGUI.Label(width / 2, 10 + self.energy_label.get_height(), 0, 0, font, millify_num(self.health) + " health")
        self.health_label.set_text_resize(res_hor=True, res_ver=True, padding=2)
        self.health_label.set_transparent(True)
        self.health_label.set_font_color((255, 210, 210))
        self.add_element(self.health_label, layer=10)

        self.health_img = MGUI.AnimSprite(0, 0, 0, 0, "assets/materials/health.png", 4)
        tmp_x = self.health_label.get_position()[0] - self.health_img.get_width() - 2
        self.health_img.set_position(tmp_x, self.health_label.get_position()[1] - 2)
        self.add_element(self.health_img, layer=10)

        # Paused label
        self.paused_label = MGUI.Label(0, 0, 0, 0, font, "PAUSED")
        self.paused_label.set_background((60, 20, 60))
        self.paused_label.set_text_resize(res_hor=True, res_ver=True, padding=8)
        self.paused_label.set_border(True, (150, 20, 150))
        tmp_x = width / 2 - self.paused_label.get_width() / 2
        tmp_y = height / 2 - self.paused_label.get_height() / 2
        self.paused_label.set_position(tmp_x, tmp_y)
        self.paused_label.set_visible(False)
        self.add_element(self.paused_label, layer=10)
コード例 #7
0
 def get_ccps_str(self):
     return millify_num(self.ccps)
コード例 #8
0
 def get_carbcrystals_str(self):
     return millify_num(self.carb_crystals)