예제 #1
0
 def __init__(self,
              path,
              elements=None,
              normal_params=None,
              colorkey=None,
              start_frame=0,
              low=2,
              nread=float("inf"),
              finish=True):
     low = 1 if low < 1 else low
     if not HAS_PIL:
         print(
             "You need to have PIL installed in order to use animated gifs")
     ThorpyImage.__init__(self,
                          path=path,
                          elements=elements,
                          normal_params=normal_params,
                          colorkey=colorkey,
                          finish=False)
     self.colorkey = colorkey
     if isinstance(path, list):
         self.frames = frames
     else:
         self.frames = processImage(path)
     self.current_frame = start_frame
     self.low = low
     self.nread = nread
     self.i = 0
     thorpy.add_time_reaction(self, self.next_frame)
     for img in self.frames:
         img.set_colorkey(self.colorkey)
     if finish:
         self.finish()
예제 #2
0
 def build_map(self, map_initializer, fast, use_beach_tiler, load_tilers):
     map_initializer.build_map(self.me, fast, use_beach_tiler, load_tilers)
     self.map_initializer = map_initializer
     self.me.build_objects_dict()
     self.collect_path_objects(map_initializer)
     self.add_structures()
     thorpy.add_time_reaction(self.me.e_box, self.func_reac_time)
예제 #3
0
 def build_map(self, map_initializer, fast, use_beach_tiler, load_tilers):
     cs = self.me.cell_size
     n_submaps_per_map = 36
     n_time_frames = 16
     n_maps_on_screen = 9
     some_random_factor = 2.
     N = int(n_submaps_per_map * n_time_frames * n_maps_on_screen *
             some_random_factor)
     print("***INITIAL", N)
     map_initializer.init_loading_bar()
     map_initializer.update_loading_bar("Initializing surfaces", 0.)
     for i in range(N):
         nsubmap_x = SUBMAP_FACTOR // cs
         submap_size = (nsubmap_x * cs, ) * 2
         self.me.surfaces32.append(pygame.Surface(submap_size))
     map_initializer.build_map(self.me,
                               fast,
                               use_beach_tiler,
                               load_tilers,
                               build_gui=self.is_main)
     self.map_initializer = map_initializer
     self.me.build_objects_dict()
     self.collect_path_objects(map_initializer)
     if self.is_main:
         thorpy.add_time_reaction(self.me.e_box, self.func_reac_time)
         ui = gui.Gui(self)
예제 #4
0
##game.set_flag((18,5), humans.flag, humans.team)

##game.set_flag((15,7), humans.flag, 1)
##game.set_fire((15,7), 2)
##game.add_smoke("small", (8,8))
##game.add_smoke("large", (10,8))

##game.get_cell_at(15,14).set_name("My top cell")

#### GUI and events part #######################################################


ui = gui.Gui(game)
game.set_ambiant_sounds(False)

thorpy.add_time_reaction(me.e_box, game.func_reac_time)

game.gui.footstep = get_sprite_frames("sprites/footstep.png", s=12,
                                        resize_factor=0.6)
game.gui.sword = get_sprite_frames("sprites/sword_shine.png")
game.gui.medic = get_sprite_frames("sprites/medic.png", s=16)
game.gui.under_construct = get_sprite_frames("sprites/under_construction.png", s=16)
game.gui.under_capture = get_sprite_frames("sprites/under_capture.png", s=16)

game.update_player_income(game.current_player)
game.gui.e_gold_txt.set_text(str(game.current_player.money))
game.gui.empty_star = get_sprite_frames("sprites/star_empty.png", s=13)[0]
game.gui.plain_star = get_sprite_frames("sprites/star_plain.png", s=13)[0]
game.hourglass = get_sprite_frames("sprites/hourglass.png")

#me.e_box includes many default reactions. You can remove them as follow:
예제 #5
0
    def show_players_infos(self):
        w = self.game.me.screen.get_width() // 2
        objs = ["village", "windmill", "tower"]
        unit_types = set([u.str_type for u in self.game.units])
        boxes = []
        o_e = []
        for pn in [0, 1]:
            p = self.game.players[pn]
            title = thorpy.make_text(p.name, 15, p.color_rgb)
            line = thorpy.Line(w, "h")
            p = self.game.players[pn]
            els = []
            for typ in objs:
                for o in self.game.get_objects_of_team(p.team, typ):
                    ##                    img = self.game.me.extract_img(o.cell)
                    if typ == "village":
                        img = self.game.village.imgs_z_t[0][0]
                    elif typ == "windmill":
                        img = self.game.windmill.imgs_z_t[0][0]
                    elif typ == "tower":
                        img = p.race.tower.imgs_z_t[0][0]
                    els.append(thorpy.Image(img))
                    o_e.append((els[-1], o))
            thorpy.grid_store(10, pygame.Rect(0, 0, 100, 100), els)
            g_buildings = thorpy.make_group(els, mode=None)
            #
            els = []
            for typ in unit_types:
                for u in self.game.units:
                    if u.str_type == typ and u.race.team == p.team:
                        img = u.imgs_z_t[0][u.get_current_frame()]
                        els.append(thorpy.Image(img))
                        o_e.append((els[-1], u))
            thorpy.grid_store(10, pygame.Rect(0, 0, 100, 100), els)
            g_units = thorpy.make_group(els, mode=None)
            #
            money_img = thorpy.Image(self.e_gold_img.get_image())
            money_txt = thorpy.make_text(str(p.money))
            income = self.game.compute_player_income(p)
            income_txt = thorpy.make_text("  (income: " + str(income) + ")")
            g_money = thorpy.make_group([money_img, money_txt, income_txt])
            g = thorpy.Element(
                elements=[title, line, g_units, g_buildings, g_money])
            thorpy.store(g)
            g.fit_children()
            boxes.append(g)
        e = thorpy.Box(boxes)
        e.center()

        def refresh():
            for element, obj in o_e:
                img = obj.imgs_z_t[0][obj.get_current_frame()]
                ##                fire = self.game.get_object("fire", obj.cell.coord)
                ##                if fire:
                ##                    img_fire = fire.imgs_z_t[0][fire.get_current_frame()]
                ##                    r = img_fire.get_rect()
                ##                    w,h = img.get_size()
                ##                    r.center = w//2, h//2
                ##                    r.bottom = h
                ##                    img.blit(img_fire, r)
                element.set_image(img)
            self.game.me.func_reac_time()
            self.game.t += 1
            e.blit()
            pygame.display.flip()

        thorpy.add_time_reaction(e, refresh)

        def click():
            if not e.get_fus_rect().collidepoint(pygame.mouse.get_pos()):
                thorpy.functions.quit_menu_func()

        thorpy.add_click_reaction(e, click)
        m = thorpy.Menu(e, fps=self.game.me.fps)
        m.play()