コード例 #1
0
    def populate(self):
        """Populates the world with entities.

        Currently just does a hard-coded a specific number of 
        lumberjacks and farmers in the same position.

        Args:
            None

        Returns:
            None"""

        start = {
            "Lumberjack": {
                "count": 2,
                "state": "Searching",
                "class": Lumberjack.Lumberjack
            },
            "Angler": {
                "count": 2,
                "state": "Searching",
                "class": Angler.Angler
            },
            "Arborist": {
                "count": 1,
                "state": "Planting",
                "class": Arborist.Arborist
            },
            "Farmer": {
                "count": 0,
                "state": "Tilling",
                "class": Farmer.Farmer
            },
            "Explorer": {
                "count": 1,
                "state": "Exploring",
                "class": Explorer.Explorer
            }
        }

        for key in start.keys():
            for count in xrange(start[key]["count"]):
                new_ent = start[key]["class"](self, key)
                new_ent.location = vector2.Vector2(self.w / 2, self.h / 2)
                new_ent.brain.set_state(start[key]["state"])
                self.add_entity(new_ent)
コード例 #2
0
    def __init__(self, tile_dimensions, screen_size):
        """Basic initialization.

        Args:
            tile_dimensions: The dimensions of the world in terms
                of tiles. default is 128x128 tiles.

            screen_size: The size of the window, this is used for scaling
                (mostly of the minimap).

        Returns:
            None
        """

        self.tile_size = 32
        self.w, self.h = self.world_size = (tile_dimensions[0] *
                                            self.tile_size,
                                            tile_dimensions[1] *
                                            self.tile_size)
        self.world_position = vector2.Vector2(-self.w / 2, -self.h / 2)

        self.clock = pygame.time.Clock()

        # Unused variables
        self.wood = 0
        self.fish = 0

        # Entities
        self.entities = {}
        self.buildings = {}
        self.entity_id = 0
        self.building_id = 0

        self.new_world(tile_dimensions)
        self.clipper = Clips.Clips(self, screen_size)

        # TODO ([email protected] | Nick Wayne): Not sure if these belong here either
        self.info_bar = pygame.image.load(
            "Images/Entities/info_bar.png").convert()
        self.info_bar.set_colorkey((255, 0, 255))
        self.f_high = (50, 200, 50)
        self.f_low = (255, 0, 0)
        self.w_high = (0, 0, 255)
        self.w_low = (76, 70, 50)
        self.e_high = (0, 255, 0)
        self.e_low = (50, 50, 0)
コード例 #3
0
ファイル: TileFuncs.py プロジェクト: sjtsp2008/villager-sim
def get_vnn_array(world, location, r):
    """ Stands for Von Neumann Neighborhood.
        Simply returns a neighborhood of locations based
        on the initial location and range r"""

    return_array = []

    """
    range: 3
    num rows: 5 (number of rows is equal to (2 * r) - 1
    0     *      1     left column is row_number  
    1   * * *    3     right column is num_in_row
    2 * * * * *  5
    3   * * *    3     middle is illustration of what is looks like
    4     *      1     num_in_row is just how many spots are looked at in the current row.
    """

    for row_number in range((2 * r) - 1):
        if row_number >= r:
            num_in_row = (2 * row_number) - (4 * (row_number - r + 1) - 1)
        else:
            num_in_row = (2 * row_number) + 1

        for cell in range(num_in_row):

            """
            the y_offset goes from -(r - 1) to +(r - 1) (not affected by the inner loop)

            the x_offset goes from -math.floor(num_in_row / 2.0) to +math.floor(num_in_row / 2.0) 

            0     0     1 |                  (0, -2)                  x, y offset pairs of a range 3 vnn array        
            1   0 1 2   3 |         (-1, -1) (0, -1) (1, -1)         
            2 0 1 2 3 4 5 | (-2, 0) (-1, 0 ) (0, 0 ) (1, 0 ) (2, 0)   left column is row_number
            3   0 1 2   3 |         (-1, 1 ) (0, 1 ) (1, 1 )          right column is num_in_row
            4     0     1 |                  (0, 2 )                  middle is cell number
            """

            tile_size = world.tile_size
            x_offset = cell - math.floor(num_in_row / 2.0)
            y_offset = row_number - (r - 1)

            new_location = vector2.Vector2(location.x + (x_offset * tile_size), location.y + (y_offset * tile_size))
            return_array.append(new_location)

    return return_array
コード例 #4
0
ファイル: TileFuncs.py プロジェクト: sjtsp2008/villager-sim
def get_tile_pos(world, location):
    return vector2.Vector2(int(location.x) >> 5, int(location.y) >> 5)
コード例 #5
0
    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()