def new_world(self, array_size): """Creates a new world (including all of the entities) Args: array_size: The size of the tile array, same as tile_dimensions in the constructor. Returns: None """ map_width, map_height = array_size map_generator = VoronoiMapGen.mapGen() # midpoint_generator = MidpointDisplacement.MidpointDisplacement() # mid_map = PertTools.scale_array(midpoint_generator.normalize(midpoint_generator.NewMidDis(int(math.log(map_width, 2)))), 255) #vor_map = map_generator.whole_new_updated(size=array_size, ppr=2, c1=-1, c2=1, c3=0) #combined_map = PertTools.combine_arrays(vor_map, mid_map, 0.33, 0.66) # pert_map = PertTools.scale_array(midpoint_generator.normalize(midpoint_generator.NewMidDis(int(math.log(map_width, 2)))), 255) # vor_map = map_generator.radial_drop(PertTools.pertubate(combined_map, pert_map), 1.5, 0.0) # vor_map = map_generator.radial_drop(mid_map, 1.5, 0.0) vor_map = map_generator.radial_drop(map_generator.negative( map_generator.reallyCoolFull(array_size, num_p=23)), max_scalar=1.5, min_scalar=0.0) # All grass map for testing # vor_map = [[150 for x in xrange(128)] for y in xrange(128) ] # Method without radial drop # vor_map = map_generator.negative(map_generator.reallyCoolFull(array_size, num_p=23)) self.minimap_img = pygame.Surface((map_width, map_height)) self.tile_array = [[0 for tile_x in xrange(map_width)] for tile_y in xrange(map_height)] self.world_surface = pygame.Surface(self.world_size, pygame.HWSURFACE) if len(sys.argv) >= 4: do_hard_shadow = bool(int(sys.argv[3])) else: do_hard_shadow = False if do_hard_shadow: shadow_drop = 2.5 / (map_width / 128.0) shaded = False for tile_x in xrange(map_width): shadow_height = 0 for tile_y in xrange(map_height): color = vor_map[tile_x][tile_y] if do_hard_shadow: shaded = False if color < shadow_height and not shadow_height < 110: shaded = True shadow_height -= shadow_drop elif color >= 110 and color > shadow_height: shadow_height = color shadow_height -= shadow_drop else: shadow_height -= shadow_drop if color < 110: # Water tile new_tile = Tile.WaterTile(self, "AndrewWater") elif 120 > color >= 110: # Sand / Beach tile new_tile = Tile.BeachTile(self, "Sand") # TODO: Implement a humidity / temperature system elif 160 > color >= 120: # Grass new_tile = Tile.GrassTile(self, "MinecraftGrass") elif 170 > color >= 160: # Tree new_tile = Tile.TreePlantedTile(self, "GrassWithCenterTree") elif 190 > color >= 170: # Grass (again) new_tile = Tile.GrassTile(self, "MinecraftGrass") elif 220 > color >= 190: # Rock new_tile = Tile.SmoothStoneTile(self, "AndrewSmoothStone") else: # Snow new_tile = Tile.SnowTile(self, "MinecraftSnow") new_tile.location = vector2.Vector2(tile_x * self.tile_size, tile_y * self.tile_size) new_tile.rect.topleft = new_tile.location new_tile.color = color alph = 220 - color if 220 > color >= 190: alph = 330 - color new_tile.darkness = alph subtle_shadow = pygame.Surface( (self.tile_size, self.tile_size)) subtle_shadow.set_alpha(alph) if do_hard_shadow: hard_shadow = pygame.Surface( (self.tile_size, self.tile_size)) hard_shadow.set_alpha(128) if shaded: new_tile.img.blit(hard_shadow, (0, 0)) self.world_surface.blit(new_tile.img, new_tile.location) self.world_surface.blit(subtle_shadow, new_tile.location) self.minimap_img.blit(new_tile.img.subsurface((0, 0, 1, 1)), (tile_x, tile_y)) self.minimap_img.blit(subtle_shadow.subsurface((0, 0, 1, 1)), (tile_x, tile_y)) self.tile_array[tile_y][tile_x] = new_tile self.populate()
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)