Exemple #1
0
    def __init__(self, ss, WorldSize, font, rand_seed):
        self.size = WorldSize
        #How big the map is
        self.TileSize = 32
        self.ssize = (self.size[0] / self.TileSize,
                      self.size[1] / self.TileSize)
        self.seed = rand_seed
        seed(self.seed)

        self.ss = ss
        self.w, self.h = self.size
        #Certain functions entities need this.
        self.center = vector2.Vector2(self.w / 2, self.h / 2)

        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(ss[0] / 5.0, 0)
        self.mapGenerator = mapGen()

        self.background_over = pygame.Surface((1600, 900), pygame.HWSURFACE)
        self.background_over.set_alpha(128)
        self.background_over.fill((0, 0, 20, 128))

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

        self.clock = pygame.time.Clock()

        print self.size
        self.background = pygame.Surface((self.size[0], self.size[1]),
                                         pygame.HWSURFACE)
        self.background.fill((255, 255, 255))

        self.font = font
        self.font_size = self.font.size("A")[1]

        self.text = self.font.render(str(self.wood), True, (0, 0, 0))
        #World entity also stores global font for rendering to the screen.

        self.clock_degree = 0
        #Used for the clock

        self.convert_all()
        self.new_world()
        self.cliper = Clips(self, self.ss)

        self.BuildingQueue = []
        self.buildqueue = 0
Exemple #2
0
    def check_conditions(self):
        check = self.Lumberjack.world.get_tile(
            vector2.Vector2(self.Lumberjack.location))
        if self.Lumberjack.location.get_distance_to(
                self.Lumberjack.main_des) < 2:
            self.Lumberjack.destination = vector2.Vector2(
                self.Lumberjack.location)

            if check.name != "TreePlantedTile_W":
                self.Lumberjack.hit = 0
                self.Lumberjack.num = 0
                self.Lumberjack.image = self.Lumberjack.start
                self.Lumberjack.ani_speed = self.Lumberjack.ani_speed_init
                return "Searching"

            self.Lumberjack.update()

            if self.Lumberjack.hit == 4:
                self.Lumberjack.destination = vector2.Vector2(
                    self.Lumberjack.location)
                self.Lumberjack.image = self.Lumberjack.start
                self.Lumberjack.image.set_colorkey((255, 0, 255))

                old_tile = self.Lumberjack.world.get_tile(
                    Vector2(self.Lumberjack.location))

                darkness = pygame.Surface((32, 32))
                darkness.set_alpha(old_tile.darkness)

                new_tile = TreePlantedTile(self.Lumberjack.world, NoTreeImg)
                new_tile.darkness = old_tile.darkness

                new_tile.location = self.Lumberjack.world.get_tile_pos(
                    self.Lumberjack.destination) * 32
                new_tile.rect.topleft = new_tile.location
                new_tile.color = old_tile.color

                self.Lumberjack.world.TileArray[int(
                    new_tile.location.y / 32)][int(new_tile.location.x /
                                                   32)] = new_tile
                self.Lumberjack.world.background.blit(new_tile.img,
                                                      new_tile.location)
                self.Lumberjack.world.background.blit(darkness,
                                                      new_tile.location)

                self.Lumberjack.hit = 0

                #del self.Lumberjack.world.TreeLocations[str(
                #   self.Lumberjack.tree_id)]
                return "Delivering"
Exemple #3
0
 def process_vert_line(self, vert):
     id = vert[0]
     x = float(vert[1])
     y = float(vert[2])
     pos = vector2.Vector2(x, y)
     self.verts[id] = vertex.Vertex(id, pos)  # store vertex
     self.edges[id] = []  # set up adjacency list
Exemple #4
0
 def __init__(self):
     pygame.init()
     pygame.display.set_caption('Bouncing image')
     self.resolution_width = 640
     self.resolution_height = 360
     self.application_surface = pygame.display.set_mode(
         (self.resolution_width, self.resolution_height),
         flags=pygame.SCALED)
     self.BASE_FPS = 60
     self.clock = pygame.time.Clock()
     self.image = pygame.image.load('wall.png')
     self.position = vector2.Vector2()
     self.velocity = vector2.Vector2(200, 180)
     self.initialize()
     self.running = True
     self.main_loop()
     pygame.quit()
Exemple #5
0
    def getParameter(self, point, optionalTarget=None):

        # This can potentially have a divide by zero if the box
        # has a size dimension of 0.

        result = optionalTarget or vector2.Vector2()

        return result.set((point.x - self.min.x) / (self.max.x - self.min.x),
                          (point.y - self.min.y) / (self.max.y - self.min.y))
Exemple #6
0
    def setFromCenterAndSize(self, center, size):

        v1 = vector2.Vector2()

        halfSize = v1.copy(size).multiplyScalar(0.5)
        self.min.copy(center).sub(halfSize)
        self.max.copy(center).add(halfSize)

        return self
Exemple #7
0
 def random_dest(self):
     """Function for going to a random destination,
     currently limited to top 1/12 of the map
     """
     w, h = self.Lumberjack.worldSize
     offset = self.Lumberjack.TileSize / 2
     TileSize = self.Lumberjack.TileSize
     random_dest = (randint(0, 25) * TileSize + offset,
                    randint(0, 25) * TileSize + offset)
     self.Lumberjack.destination = vector2.Vector2(*random_dest)
Exemple #8
0
def main():
    errors = pygame.init() # initialise pygame
    if errors[1] > 0:
        print('Initialisation failed.')
        sys.exit(-1)
    surface = pygame.display.set_mode(DIMENSIONS) # crée une surface
    pygame.display.set_caption('Snake') # modifie le titre de la fenêtre
    time.sleep(2) # attend 2 secondes
    red = pygame.Color(255, 0, 0) # créer une couleur RGB
    green = pygame.Color(0, 255, 0)
    blue = pygame.Color(0, 0, 255)
    black = pygame.Color(0, 0, 0)
    white = pygame.Color(255, 255, 255)
    brown = pygame.Color(165, 42, 42)
    
    fps_controller = pygame.time.Clock()
    head = vector2.Vector2(WIDTH / 2, HEIGHT / 2)
    body = []
    food = vector2.Vector2(random.randrange(int(WIDTH / TILE_SIZE)) * TILE_SIZE, random.randrange(int(HEIGHT / TILE_SIZE)) * TILE_SIZE)
    def __init__(self, world, name, image):

        self.world = world
        self.name = name

        self.image = image
        try:
            self.image.set_colorkey((255, 0, 255))
        except AttributeError:
            pass
        self.location = vector2.Vector2(0, 0)
        self.world_location = vector2.Vector2(0, 0)
        self.destination = vector2.Vector2(0, 0)
        self.speed = 0.

        self.brain = StateMachine.StateMachine()

        self.id = 0

        self.tp = 1.0
Exemple #10
0
    def get_close_entity(self, name, location, range=100.):

        location = vector2.Vector2(*location)

        for entity in self.entities.itervalues():
            if entity.name == name:
                distance = location.get_distance_to(entity.location)
                if range == -1:
                    return entity
                if distance < range:
                    return entity

        return None
Exemple #11
0
    def populate(self):
        """adds all the people and make sure they don't go all ape shit
        """
        FARMER_COUNT = 4
        VILLAGER_COUNT = 5
        BUILDER_COUNT = 1

        lumber1 = Building.LumberYard(self, self.lumberyard_img)
        lumber1.location = vector2.Vector2(self.w / 2, self.h / 2)
        lumber1.tile_x, lumber1.tile_y = 4, 4
        self.add_entity(lumber1)

        for Villager_no in xrange(VILLAGER_COUNT):
            """Adds all Wood Cutters
            """
            villager = Lumberjack.Lumberjack(self, self.lumberjack_img)
            villager.location = lumber1.location.copy()
            villager.LastLumberYard = lumber1
            villager.brain.set_state("Searching")
            self.add_entity(villager)
            self.population += 1

        for Building_no in xrange(BUILDER_COUNT):
            builder = Builder.Builder(self, self.builder_img, lumber1)
            builder.location = lumber1.location.copy()
            builder.brain.set_state("Idle")
            self.add_entity(builder)
            self.population += 1

        for FARMER in xrange(FARMER_COUNT):
            """Adds all the farmers
            """
            farmer = Farmer.Farmer(self, self.farmer_img)
            farmer.location = vector2.Vector2(20, 20)
            farmer.brain.set_state("Planting")
            self.add_entity(farmer)
            self.population += 1
 def __init__(self):
     pygame.init()
     pygame.display.set_caption('Bouncing image')
     self.resolution_width = 640
     self.resolution_height = 360
     self.application_surface = pygame.display.set_mode((self.resolution_width, self.resolution_height), flags=pygame.SCALED)
     self.BASE_FPS = 60
     self.clock = pygame.time.Clock()
     self.image = pygame.image.load('cat.jpg')
     self.angle = 0
     self.position = vector2.Vector2()
     self.head_position = (86 - 150, 114 - 200)
     self.head_angle_to_center = math.atan2(self.head_position[1], self.head_position[0])
     self.head_distance_to_center = math.sqrt(self.head_position[0] ** 2 + self.head_position[1] ** 2)
     self.initialize()
     self.running = True
     self.main_loop()
     pygame.quit()
    def plant_seed(self):
        #Function for planting trees

        #Test to see if the tile the farmer is on is a tile
        # that a tree can be planted on
        if self.Farmer.world.get_tile(self.Farmer.location).plantable == 1:
            self.Farmer.hit = 0
            self.Farmer.image = self.Farmer.start
            self.Farmer.image.set_colorkey((255, 0, 255))

            old_tile = self.Farmer.world.get_tile(
                vector2.Vector2(self.Farmer.location))

            darkness = pygame.Surface((32, 32))
            darkness.set_alpha(old_tile.darkness)

            new_tile = Tile.Baby_Tree(self.Farmer.world, Tile_image)
            new_tile.darkness = old_tile.darkness
            new_tile.location = self.Farmer.world.get_tile_pos(
                self.Farmer.destination) * 32
            new_tile.rect.topleft = new_tile.location
            new_tile.color = old_tile.color

            #Give it an ID so it can be found
            new_tile.id = self.Farmer.world.Baby_TreeID
            self.Farmer.world.Baby_TreeID += 1

            self.Farmer.world.TileArray[int(new_tile.location.y / 32)][int(
                new_tile.location.x / 32)] = new_tile
            self.Farmer.world.background.blit(new_tile.img, new_tile.location)
            self.Farmer.world.background.blit(darkness, new_tile.location)

            #Add the location to a dictionary so
            #villagers can see how far they are from it.
            self.Farmer.world.Baby_TreeLocations[str(
                self.Farmer.world.Baby_TreeID)] = new_tile.location

        #Goes to a random destination no matter what
        self.Farmer.hit = 0
        self.random_dest()
Exemple #14
0
    def getCenter(self, optionalTarget=None):

        result = optionalTarget or vector2.Vector2()
        return result.set(0, 0) if self.isEmpty() else result.addVectors(
            self.min, self.max).multiplyScalar(0.5)
Exemple #15
0
    def distanceToPoint(self, point):

        v1 = vector2.Vector2()

        clampedPoint = v1.copy(point).clamp(self.min, self.max)
        return clampedPoint.sub(point).length()
Exemple #16
0
    def clampPoint(self, point, optionalTarget=None):

        result = optionalTarget or vector2.Vector2()
        return result.copy(point).clamp(self.min, self.max)
Exemple #17
0
    def test_buildable(self, building, built, pos):

        if building == "LumberYard":
            if built:
                Build = Building.LumberYard(self, self.lumberyard_img)
            else:
                Build = Building.UnderConstruction(self, self.uc_img,
                                                   "LumberYard")

        elif building == "House":
            if built:
                Build = Building.House(self, self.house_img)
            else:
                Build = Building.UnderConstruction(self, self.uc_house_img,
                                                   "House")

        elif building == "Dock":
            if built:
                Build = Building.Dock(self, self.dock_img)
            else:
                Build = Building.UnderConstruction(self, self.ucw_img, "Dock")

        elif building == "Manor":
            if built:
                Build = Building.Manor(self, self.manor_img)
            else:
                Build = Building.UnderConstruction(self, self.uc_img, "Manor")

        buildable = 1
        land = 0
        water = 0

        Twidth, Theight = Build.image.get_size()
        for i in range(Twidth >> 5):
            for j in range(Theight >> 5):
                try:
                    if built:
                        test_tile = self.get_tile(
                            vector2.Vector2((pos.x - 32) + (i << 5),
                                            (pos.y - 32) + (j << 5)))
                        #print "A", test_tile, test_tile.location
                    else:
                        test_tile = self.get_tile(
                            vector2.Vector2(
                                ((pos.x - 32) - self.background_pos.x) +
                                (i << 5),
                                ((pos.y - 32) - self.background_pos.y) +
                                (j >> 5)))
                        #print "B", test_tile, test_tile.location

                    if test_tile.buildable != 1 and building != "Dock":
                        buildable = 0
                        return 0
                    elif building == "Dock":
                        if test_tile.buildable_w:
                            water += 1
                        elif test_tile.buildable:
                            land += 1
                except IndexError:
                    print 'IndexError'
                    return 0

        if building == "Dock" and not built:
            if water >= 1 and land <= 2 and land > 0:
                #print ('buildable', water, land)
                buildable = 1
                return 1, Build
            else:
                #print ('not buildable', water, land)
                buildable = 0
                return 0

        return 1, Build
def run():
    pygame.display.set_caption("Villager Simulation")

    sizes = pygame.display.list_modes()
    SCREEN_SIZE = sizes[0]
    Owidth, Oheight = SCREEN_SIZE

    side_size = Owidth / 5.0

    mapGenerator = mapGen()

    if FULL_ON:
        screen = pygame.display.set_mode(SCREEN_SIZE,
                                         pygame.FULLSCREEN | pygame.HWSURFACE,
                                         32)
    else:
        screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32)

    fade = CrossFade(screen)
    all_sprites = pygame.sprite.Group(fade)

    draw = False
    held = False

    #Load the image the world will be based on,
    #then set the world size proportionate to it

    #world_img_str, mini_img_str = random_map("SCREENSHOT", "*")
    #world_img = pygame.image.load(world_img_str).convert()

    #mini_img_str = None
    #world_img = mapGenerator.whole_new(25, (256, 256))

    size = (256, 256)
    w_size = size[0] * TILE_SIZE, size[1] * TILE_SIZE

    seed = randint(0, 100)
    #print seed

    world = World.World(SCREEN_SIZE, w_size, font, seed)
    #pygame.image.save(world.minimap_img, "Images/UBER-COOL-small.png")

    Villager_image = pygame.image.load(
        "Images/Entities/Villager.PNG").convert()
    Farmer_image = pygame.image.load("Images/Entities/Farmer.png").convert()
    Lumberjack_image = pygame.image.load(
        "Images/Entities/Lumberjack.png").convert()
    Builder_image = pygame.image.load("Images/Entities/Builder.png").convert()

    placing_lumberyard_img = pygame.image.load(
        "Images/Buildings/Dark_Lumberyard.png").convert()
    placing_lumberyard_img.set_colorkey((255, 0, 255))
    placing_house_img = pygame.image.load(
        "Images/Buildings/Dark_House.png").convert()
    placing_house_img.set_colorkey((255, 0, 255))
    placing_dock_img = pygame.image.load(
        "Images/Buildings/Dark_Dock.png").convert()
    placing_dock_img.set_colorkey((255, 0, 255))
    placing_manor_img = pygame.image.load(
        "Images/Buildings/Dark_Manor.png").convert()
    placing_manor_img.set_colorkey((255, 0, 255))

    bad_lumberyard_img = pygame.image.load(
        "Images/Buildings/Red_Lumberyard.png").convert()
    bad_lumberyard_img.set_colorkey((255, 0, 255))

    #pygame.image.save(me_double_size(pygame.image.load(
    #    "Images/Buildings/LumberYard_Icon.png").convert()), "LARGERLumb.png")
    #pygame.image.save(me_double_size(pygame.image.load(
    #    "Images/Buildings/Manor_Icon.png").convert()), "LARGERMan.png")

    world.clipper = Clips(world, (Owidth, Oheight))
    #pygame.image.save(world.background, "Images/VeryLargeShowingOff.png")
    #pygame.image.save(world.minimap_img, "Images/SmallAndVariety2.png")

    selected_building = "LumberYard"
    selected_img = pygame.image.load(
        "Images/Buildings/Dark_Lumberyard.png").convert()
    selected_img.set_colorkey((255, 0, 255))

    world.clock.tick()
    while True:

        time_passed = world.clock.tick(60)
        time_passed_seconds = time_passed / 1000.
        pos = vector2.Vector2(*pygame.mouse.get_pos())

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                quit()

            if event.type == pygame.MOUSEBUTTONDOWN:
                if (pos.x > world.clipper.minimap_rect.x
                        and pos.y > world.clipper.minimap_rect.y):
                    pass
                else:
                    if event.button == 1:
                        held = True
                        start = vector2.Vector2(*pygame.mouse.get_pos())
                        draw = True
                        if (pos.x < world.clipper.side.w) and (
                                pos.y < world.clipper.side.top_rect.h):
                            for L in world.clipper.side.tiles:
                                for T in L:
                                    if T is None:
                                        continue

                                    if T.rect.collidepoint((pos.x, pos.y)):
                                        if T.selected:
                                            T.selected = False
                                        else:
                                            T.selected = True

                                        selected_building = T.rep
                                        world.clipper.side.update(T)

                        else:
                            selected_building = None
                            world.clipper.side.update()

                    if event.button == 3 and selected_building is not None:
                        world.add_building(selected_building, pos)
                        if world.test_buildable(selected_building, 0, pos):
                            selected_building = None
                            world.clipper.side.update()

            if event.type == pygame.MOUSEBUTTONUP:
                draw = False
                held = False

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_F2:
                    str1 = str(datetime.now())
                    str1 = str1.split(".")
                    str2 = str1[0] + str1[1]
                    str2 = str2.split(":")
                    str1 = ""
                    for i in str2:
                        str1 += i
                    pygame.image.save(
                        screen, "Images/Screenshots/SCREENSHOT%s.png" % str1)
                if event.key == pygame.K_n:
                    world.new_world()

            if event.type == pygame.VIDEORESIZE:
                Owidth, Oheight = event.size

        #------------------Keys Below------------------------------------------
        pressed_keys = pygame.key.get_pressed()
        if pressed_keys[pygame.K_ESCAPE]:
            #quits the game
            pygame.quit()
            exit()

        if pressed_keys[pygame.K_SPACE]:
            #Resets wood
            world.wood = 0

        if pressed_keys[pygame.K_d]:
            #Fast-forward-esk functionability
            world.clock_degree += 5

        if pressed_keys[pygame.K_l]:
            #Test to see what the first entity's state is
            print world.entities[1].brain.active_state

        #--------------Keys Above----------------------------------------
        #--------------Mouse Below---------------------------------------

        if int(pos.x) <= 15:
            if not FULL_ON:
                pygame.mouse.set_pos((15, pos.y))
            world.background_pos.x += 500 * time_passed_seconds
            #print world.background_pos.x
            if world.background_pos.x > side_size:

                world.background_pos.x = side_size

        elif int(pos.x) >= Owidth - 16:
            if not FULL_ON:
                pygame.mouse.set_pos((Owidth - 16, pos.y))
            world.background_pos.x -= 500 * time_passed_seconds

            if world.background_pos.x < -1 * (world.w - Owidth):
                world.background_pos.x = -1 * (world.w - Owidth)
            #print world.background_pos.x

        if int(pos.y) <= 15:
            if not FULL_ON:
                pygame.mouse.set_pos((pos.x, 15))
            world.background_pos.y += 500 * time_passed_seconds

            if world.background_pos.y > 0:
                world.background_pos.y = 0

        elif int(pos.y) >= Oheight - 16:

            if not FULL_ON:
                pygame.mouse.set_pos((pos.x, Oheight - 16))

            world.background_pos.y -= 500 * time_passed_seconds

            if world.background_pos.y < -1 * (world.h - Oheight):
                world.background_pos.y = -1 * (world.h - Oheight)

        if pygame.mouse.get_pressed()[0]:
            if (pos.x > world.clipper.minimap_rect.x
                    and pos.y > world.clipper.minimap_rect.y):
                draw = False
                if held is not True:
                    world.background_pos.x = (
                        -1 * (pos.x - world.clipper.minimap_rect.x) *
                        world.clipper.a) + (world.clipper.rect_view_w *
                                            world.clipper.a) / 2
                    world.background_pos.y = (
                        -1 * (pos.y - world.clipper.minimap_rect.y) *
                        world.clipper.b) + (world.clipper.rect_view_h *
                                            world.clipper.b) / 2

        #--------------Mouse Above---------------------------------------
        #--------------Process below-------------------------------------

        world.process(time_passed_seconds)

        if selected_building == "House":
            selected_img = placing_house_img
        elif selected_building == "LumberYard":
            selected_img = placing_lumberyard_img
        elif selected_building == "Dock":
            selected_img = placing_dock_img
        elif selected_building == "Manor":
            selected_img = placing_manor_img

        #--------------Process above-------------------------------------
        #--------------Render Below------------------------

        screen.fill((0, 0, 0))
        world.render_all(screen, time_passed_seconds, pos)

        all_sprites.clear(screen, world.background)
        all_sprites.update()
        all_sprites.draw(screen)

        world.grow_trees(world.Baby_TreeLocations)

        if fade.trans_value == 0:
            all_sprites.remove(fade)

        if selected_building is not None:
            if (pos.x > world.clipper.minimap_rect.x
                    and pos.y > world.clipper.minimap_rect.y) or (
                        pos.x < world.clipper.side.w + 32):
                pass
            else:
                if not world.test_buildable(selected_building, 0, pos):
                    selected_img = bad_lumberyard_img
                blit_pos = world.get_tile_pos(pos - world.background_pos) * 32
                screen.blit(selected_img,
                            ((blit_pos.x - (selected_img.get_width() - 32)) +
                             world.background_pos.x,
                             (blit_pos.y - (selected_img.get_height() - 32)) +
                             world.background_pos.y))

        #This is for selecting-------------
        if draw is True and selected_building is None:
            a = vector2.Vector2(*pygame.mouse.get_pos())
            lst = world.get_tile_array(start, ((a.x - start.x) / 32,
                                               (a.x - start.x) / 32))
            for i in lst:
                for j in i:
                    j.selected = 1
            s = pygame.Surface((abs(a.x - start.x), abs(a.y - start.y)))
            s.set_alpha(25)
            s.fill((255, 255, 255))
            if a.x - start.x <= 0 and a.y < start.y and a.x > start.x:
                newa = (a.x - (a.x - start.x), a.y)
                screen.blit(s, (newa))
            if a.x - start.x <= 0 and a.y > start.y and a.x < start.x:
                newa = (a.x, a.y - (a.y - start.y))
                screen.blit(s, (newa))
            if a.x - start.x > 0 and a.y - start.y > 0:
                screen.blit(s, (start))
            if a.x - start.x < 0 and a.y - start.y < 0:
                screen.blit(s, (a))
            pygame.draw.rect(screen, (255, 255, 255),
                             (start, (a.x - start.x, a.y - start.y)), 1)
        #Selecting Above------------------

        #--------------Render Above------------------------

        pygame.display.flip()
Exemple #19
0
 def get_tile_pos(self, location):
     return vector2.Vector2(int(location.x) >> 5, int(location.y) >> 5)
Exemple #20
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)
Exemple #21
0
    def getSize(self, optionalTarget=None):

        result = optionalTarget or vector2.Vector2()
        return result.set(0, 0) if self.isEmpty() else result.subVectors(
            self.max, self.min)
Exemple #22
0
    def __init__(self, min=None, max=None):

        self.min = min or vector2.Vector2(+float("inf"), +float("inf"))
        self.max = max or vector2.Vector2(-float("inf"), -float("inf"))
 def check_conditions(self):
     if self.Farmer.location.get_distance_to(self.Farmer.destination) < 2:
         self.Farmer.destination = vector2.Vector2(self.Farmer.location)
         self.Farmer.update()