Ejemplo n.º 1
0
    def grow_trees(self, trees):
        for i in range(len(trees)):
            ran = randint(0, 100)
            if ran == 1 and len(trees) > 0:
                try:
                    a = trees.keys()
                    old_tile = self.get_tile(trees[a[i]])
                    darkness = pygame.Surface((32, 32))
                    darkness.set_alpha(old_tile.darkness)

                    new_tile = Tile.TreePlantedTile_w(self, WithTree_img)

                    new_tile.darkness = old_tile.darkness

                    new_tile.location = old_tile.location
                    new_tile.rect.topleft = new_tile.location
                    new_tile.color = old_tile.color

                    new_tile.id = self.TreeID
                    self.TreeID += 1

                    self.TileArray[int(new_tile.location.y / 32)][int(
                        new_tile.location.x / 32)] = new_tile
                    self.background.blit(new_tile.img, new_tile.location)
                    self.background.blit(darkness, new_tile.location)
                    #print self.Baby_TreeLocations
                    del self.Baby_TreeLocations[str(a[i])]
                except IndexError:
                    pass
Ejemplo n.º 2
0
    def new_world(self):
        del self.full_surface
        #seed(self.seed)
        img = self.mapGenerator.negative(
            self.mapGenerator.reallyCoolFull(self.ssize, num_p=23))
        #img = self.mapGenerator.whole_new(25, self.ssize, 1, -1)
        self.map_width, self.map_height = img.get_size()

        self.minimap_img = pygame.Surface((self.map_width, self.map_height))

        self.TileArray = [[0 for i in xrange(self.map_width)]
                          for a in xrange(self.map_height)]

        self.TreeID = 0
        self.TreeLocations = {}
        self.Baby_TreeID = 0
        self.Baby_TreeLocations = {}

        self.buildings = {
            "LumberYard": {},
            "Dock": {},
            "House": {},
            "Manor": {},
            "UC": {}
        }

        self.building = {}
        self.entities = {}
        #Stores all entities the game processes
        self.entity_id = 0
        #Each entity is given a unique id so the program can find it
        self.wood = 0
        #Probably will add other resources
        self.MAXwood = 50
        self.food = 0
        self.MAXfood = 0
        self.population = 0
        self.MAXpopulation = 15
        self.background_pos = vector2.Vector2(self.ss[0] / 5.0, 0)
        self.mapGenerator = mapGen()

        self.full_surface = pygame.Surface(self.size, pygame.HWSURFACE)

        self.clock_degree = 0
        #Used for the clock

        self.BuildingQueue = []
        self.buildqueue = 0

        for i in xrange(self.map_width):
            self.current_height = 0
            w_last = False
            for a in xrange(self.map_height):

                f_color = img.get_at((i, a))
                color = f_color[0]

                to_rotate = 1

                color2 = (255, 0, 220)

                #                 if color < 95:
                #                     colorb = 0
                #                     tile = DeepWaterTile(self, self.deepwater_img)

                if color < 110:
                    colorb = 0
                    tile = Tile.WaterTile(self, self.water_img)

                    last_image = self.sand_img
                    last_color = 0

                elif color >= 110 and color < 120:
                    colorb = 110
                    tile = Tile.BeachTile(self, self.sand_img)
                    last_image = self.sand_img
                    #to_rotate = 0
                    last_color = 110

                elif color >= 120 and color < 140:
                    colorb = 120
                    tile = Tile.GrassTile(self, self.grass_img)
                    last_image = self.sand_img
                    last_color = 120

                elif color >= 140 and color < 160:
                    colorb = 140
                    tile = Tile.TreePlantedTile(self, self.tree_img)
                    last_image = self.grass_img
                    last_color = 140

                elif color >= 160 and color < 170:
                    colorb = 160
                    if color2[2] == 220:

                        tile = Tile.TreePlantedTile_w(self, self.WithTree_img)
                        tile.location = vector2.Vector2(i << 5, a << 5)
                        tile.rect.topleft = tile.location
                        tile.id = self.TreeID

                        self.TreeLocations[str(self.TreeID)] = tile.location
                        self.TreeID += 1

                        to_rotate = 0
                    else:
                        tile = Tile.TreePlantedTile(self, self.tree_img)

                    last_image = self.tree_img
                    last_color = 160

                elif color >= 170 and color < 190:
                    colorb = 170
                    tile = Tile.TreePlantedTile(self, self.tree_img)
                    last_image = self.WithTree_img
                    last_color = 170

                elif color >= 190 and color < 236:
                    colorb = 190
                    tile = Tile.SmoothStoneTile(self, self.SStone_img)
                    last_image = self.tree_img
                    to_rotate = 0
                    last_color = 190

                else:
                    colorb = 236
                    tile = Tile.SnowTile(self, self.snow_img)
                    last_image = self.SStone_img
                    last_color = 236

                #Shadows----
                fake_color = color
                if color < 110:
                    fake_color = 110
                if fake_color > self.current_height - 3:

                    dark_surface = pygame.Surface((32, 32))
                    dark_surface.set_alpha(0)
                    if color >= 110:
                        self.current_height = fake_color

                    else:
                        self.current_height -= 3

                else:
                    self.current_height -= 3
                    dark_surface = pygame.Surface((1, 1))
                    dark_surface.set_alpha(128)
                #-----------

                #Used for determening start position
                if color2[1] == 255:
                    WORLD_START_POS = (i, a)
                #-----

                tile.location = vector2.Vector2(i << 5, a << 5)
                tile.rect.topleft = tile.location
                tile.color = color

                if to_rotate:
                    tile.img = pygame.transform.rotate(tile.img,
                                                       randint(0, 4) * 90)

                self.background.blit(tile.img, tile.location)

                dark_surface2 = pygame.Surface((32, 32))

                alph = 235 - color
                if color >= 190 and color < 236:
                    alph = 330 - color

                dark_surface2.set_alpha(alph)

                tile.darkness = alph

                self.background.blit(dark_surface, tile.location)
                self.background.blit(dark_surface2, tile.location)
                """
                try:
                    percentage = (color-last_color) / float(
                        colorb - last_color)

                except ZeroDivisionError:
                    percentage = 0.0
                combined_img = self.mapGenerator.lerp_two_images(tile.img,
                 last_image, percentage)
                """

                #self.minimap_img.blit(combined_img.subsurface(
                #   (0,0,1,1)), (i,a))
                self.minimap_img.blit(tile.img.subsurface((0, 0, 1, 1)),
                                      (i, a))
                self.minimap_img.blit(dark_surface.subsurface((0, 0, 1, 1)),
                                      (i, a))
                self.minimap_img.blit(dark_surface2.subsurface((0, 0, 1, 1)),
                                      (i, a))

                self.TileArray[a][i] = tile

        self.populate()
        self.cliper = Clips(self, self.ss)