當前位置: 首頁>>代碼示例>>Python>>正文


Python Rect.intersect方法代碼示例

本文整理匯總了Python中rect.Rect.intersect方法的典型用法代碼示例。如果您正苦於以下問題:Python Rect.intersect方法的具體用法?Python Rect.intersect怎麽用?Python Rect.intersect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rect.Rect的用法示例。


在下文中一共展示了Rect.intersect方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: aggro_check

# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import intersect [as 別名]
 def aggro_check(self, size):
     aggro_range = self.map.tile_width * size
     offset = (self.map.tile_width * (size / 2))
     collided = []
     for player in self.player_characters:
         rect = Rect(player.x - offset, player.y - offset, aggro_range, aggro_range)
         collided += [e for e in self.entities if rect.intersect(Rect(*e.pos + e.size)) and e.data.type == 'enemy']
     return collided
開發者ID:spinningD20,項目名稱:kivy_rpg,代碼行數:10,代碼來源:tilemap.py

示例2: main

# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import intersect [as 別名]
def main():
    dungeon_map = [['_' for x in xrange(MAP_HEIGHT)] for x in xrange(MAP_WIDTH)]
    rooms = []
    num_rooms = 0

    for r in xrange(MAX_ROOMS):
        width = random.randrange(ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        height = random.randrange(ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        xcorner = random.randrange(0, MAP_WIDTH - width - 1)
        ycorner = random.randrange(0, MAP_HEIGHT - height - 1)
        new_room = Rect(xcorner, ycorner, width, height)
        # new_room.print_rect()

        if num_rooms > 0:
            for other_room in rooms:
                if new_room.intersect(other_room):
                    break

                dungeon_map = create_room(new_room, dungeon_map)
                (new_x, new_y) = new_room.center()
                (prev_x, prev_y) = rooms[num_rooms-1].center()

                if random.randrange(0, 1) == 1:
                    #first move horizontally, then vertically
                    dungeon_map = create_h_tunnel(prev_x, new_x, prev_y, dungeon_map)
                    dungeon_map = create_v_tunnel(prev_y, new_y, new_x, dungeon_map)
                else:
                    #first move vertically, then horizontally
                    dungeon_map = create_v_tunnel(prev_y, new_y, prev_x, dungeon_map)
                    dungeon_map = create_h_tunnel(prev_x, new_x, new_y, dungeon_map)

                rooms.append(new_room)
                num_rooms = num_rooms + 1

        else:
            dungeon_map = create_room(new_room, dungeon_map)
            rooms.append(new_room)
            num_rooms = num_rooms + 1

    print_dungeon_map(dungeon_map)
開發者ID:phegan,項目名稱:dungeongenerator,代碼行數:42,代碼來源:create_map.py

示例3: make_map

# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import intersect [as 別名]
	def make_map(self):
		self.map = [[ Tile(True)
			for y in range(self.height) ]
				for x in range(self.width) ]

		rooms = []
		num_rooms = 0

		self.monster_chances = enemy_decoder.decode_all_spawn_chances()
		for chance in self.monster_chances:
			self.monster_chances[chance] = from_dungeon_level(self.monster_chances[chance])

		self.item_chances = item_decoder.decode_all_spawn_chances()
		for chance in self.item_chances:
			self.item_chances[chance] = from_dungeon_level(self.item_chances[chance])

		self.equipment_chances = equipment_decoder.decode_all_spawn_chances()
		for chance in self.equipment_chances:
			self.equipment_chances[chance] = from_dungeon_level(self.equipment_chances[chance])

		# print self.monster_chances
		# print self.item_chances
		# print self.equipment_chances

		for r in range(Map.MAX_ROOMS):
			#make a random room
			w = libtcod.random_get_int(0, Map.ROOM_MIN_SIZE, Map.ROOM_MAX_SIZE)
			h = libtcod.random_get_int(0, Map.ROOM_MIN_SIZE, Map.ROOM_MAX_SIZE)

			x = libtcod.random_get_int(0, 0, self.width - w - 1)
			y = libtcod.random_get_int(0, 0, self.height - h - 1)

			new_room = Rect(x, y, w, h)

			#make sure it doesn't intersect other rooms
			failed = False
			for other_room in rooms:
				if new_room.intersect(other_room):
					failed = True
					break

			if not failed:
				self.create_room(new_room)
				self.place_objects(new_room)
				(new_x, new_y) = new_room.center()

				if num_rooms == 0:
					self.origin = (new_x, new_y)

				else:
					#connect our room to the previous room
					(prev_x, prev_y) = rooms[num_rooms-1].center()

					if libtcod.random_get_int(0, 0, 1) == 1:
						self.create_h_tunnel(prev_x, new_x, prev_y)
						self.create_v_tunnel(prev_y, new_y, new_x)
					else:
						self.create_v_tunnel(prev_y, new_y, prev_x)
						self.create_h_tunnel(prev_x, new_x, new_y)

				rooms.append(new_room)
				num_rooms+= 1

		self.stairs = Object(new_x, new_y, '<', 'stairs', libtcod.white, always_visible=True)
		self.objects.append(self.stairs)
		self.send_to_back(self.stairs)
開發者ID:VoltaicAge8838,項目名稱:rougelike,代碼行數:68,代碼來源:map.py

示例4: setup_map

# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import intersect [as 別名]
    def setup_map(self):
        #Create the map, add objects and monsters, and save it all for later use
        rooms = []
        num_rooms = 0

        for r in range(self.max_rooms):
            #Generate a random width and height for each room
            w = libtcod.random_get_int(0, self.min_room_size, self.max_room_size)
            h = libtcod.random_get_int(0, self.min_room_size, self.max_room_size)

            #Generate a random map position, inside the bounds of the map
            x = libtcod.random_get_int(0, 0, self.width - w - 1)
            y = libtcod.random_get_int(0, 0, self.height - h -1)

            #Create a new room from the random numbers
            new_room = Rect(x, y, w, h)

            #Run through all the other rooms and see if they intersect with this one
            failed = False
            for other_room in rooms:
                if new_room.intersect(other_room):
                    failed = True
                    break

            if not failed:
                #If we've gotten here, the room is valid, and does not intersect any other rooms
                #Carve the room into the maps tiles
                self.create_room(new_room)

                #Get the center coordinates for the new room
                (new_x, new_y) = new_room.center()

                if num_rooms == 0:
                    #This is the first room created, so start the player off in the center
                    player_start_x = new_x
                    player_start_y = new_y
                else:
                    #This is not the first room, so connect it to the previous room via tunnels

                    #add some contents to this room, such as monsters, objects etc. We never add creatures to the
                    #starting room
                    self.place_objects(new_room)

                    #Get the center coordinates for the previous room
                    (prev_x, prev_y) = rooms[num_rooms - 1].center()

                    #Flip a coin to see if we move horizontally, or vertically first
                    if libtcod.random_get_int(0, 0, 1) == 1:
                        #Tunnel horizontally first, then vertically
                        self.create_h_tunnel(prev_x, new_x, prev_y)
                        self.create_v_tunnel(prev_y, new_y, new_x)
                    else:
                        #Tunnel vertically first, then horizontally
                        self.create_v_tunnel(prev_y, new_y, prev_x)
                        self.create_h_tunnel(prev_x, new_x, new_y)

                #Finally, append the newly added room to the rooms list
                rooms.append(new_room)
                num_rooms += 1

        #Create the stairs in the last room to be created
        stairs_down = Object(new_x, new_y, '>', 'stairs down', libtcod.white)
        self.objects.append(stairs_down)

        return self.map, self.objects, player_start_x, player_start_y, stairs_down
開發者ID:jcerise,項目名稱:DungeonCrawler,代碼行數:67,代碼來源:standardDungeon.py

示例5: make_map

# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import intersect [as 別名]
def make_map():
    global map
    global player_start_x
    global player_start_y

    #Fill map with blocked tiles, this will allow us to 'carve' rooms for the player
    #to explore
    map = [[Tile(True)
        for y in range(MAP_HEIGHT) ]
            for x in range(MAP_WIDTH) ]

    rooms = []
    num_rooms = 0

    for r in range(MAX_ROOMS):
        #Generate a random width and height for each room
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)

        #Generate a random map position, inside the bounds of the map
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h -1)

        #Create a new room from the random numbers
        new_room = Rect(x, y, w, h)

        #Run through all the other rooms and see if they intersect with this one
        failed = False
        for other_room in rooms:
            if new_room.intersect(other_room):
                failed = True
                break

        if not failed:
            #If we've gotten here, the room is valid, and does not intersect any other rooms
            #Carve the room into the maps tiles
            create_room(new_room)

            #Get the center coordinates for the new room
            (new_x, new_y) = new_room.center()

            if num_rooms == 0:
                #This is the first room created, so start the player off in the center
                player_start_x = new_x
                player_start_y = new_y
            else:
                #This is not the first room, so connect it to the previous room via tunnels

                #add some contents to this room, such as monsters, objects etc. We never add creatures to the
                #starting room
                place_objects(new_room)

                #Get the center coordinates for the previous room
                (prev_x, prev_y) = rooms[num_rooms - 1].center()

                #Flip a coin to see if we move horizontally, or vertically first
                if libtcod.random_get_int(0, 0, 1) == 1:
                    #Tunnel horizontally first, then vertically
                    create_h_tunnel(prev_x, new_x, prev_y)
                    create_v_tunnel(prev_y, new_y, new_x)
                else:
                    #Tunnel vertically first, then horizontally
                    create_v_tunnel(prev_y, new_y, prev_x)
                    create_h_tunnel(prev_x, new_x, new_y)

            #Finally, append the newly added room to the rooms list
            rooms.append(new_room)
            num_rooms += 1
開發者ID:m8ttyB,項目名稱:DungeonCrawler,代碼行數:70,代碼來源:DungeonCrawler.py

示例6: make_map

# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import intersect [as 別名]
def make_map():
    num_rooms = 0
    player = {'x' : 0, 'y' : 0}
    dungeon_map = [[], []]

    for r in xrange(MAX_ROOMS):
        #random width and height
        w = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        h = libtcod.random_get_int(0, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
        #random position without going out of the boundaries of the map
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)


        #"Rect" class makes rectangles easier to work with
        new_room = Rect(x, y, w, h)

        #run through the other rooms and see if they intersect with this one
        failed = False
        for other_room in rooms:
            if new_room.intersect(other_room):
                failed = True
                break


        if not failed:
            #this means there are no intersections, so this room is valid

            #"paint" it to the map's tiles
            dungeon_map = create_room(new_room, dungeon_map)

            #center coordinates of new room, will be useful later
            (new_x, new_y) = new_room.center()

            #optional: print "room number" to see how the map drawing worked
            #          we may have more than ten rooms, so print 'A' for the first room, 'B' for the next...
            room_no = Object(new_x, new_y, chr(65+num_rooms), libtcod.white)
            objects.insert(0, room_no) #draw early, so monsters are drawn on top`

            if num_rooms == 0:
                #this is the first room, where the player starts at
                player.x = new_x
                player.y = new_y

        else:
            #all rooms after the first:
            #connect it to the previous room with a tunnel

            #center coordinates of previous room
            (prev_x, prev_y) = rooms[num_rooms-1].center()

            #draw a coin (random number that is either 0 or 1)
            if libtcod.random_get_int(0, 0, 1) == 1:
                #first move horizontally, then vertically
                dungeon_map = create_h_tunnel(prev_x, new_x, prev_y, dungeon_map)
                dungeon_map = create_v_tunnel(prev_y, new_y, new_x, dungeon_map)
            else:
                #first move vertically, then horizontally
                dungeon_map = create_v_tunnel(prev_y, new_y, prev_x, dungeon_map)
                dungeon_map = create_h_tunnel(prev_x, new_x, new_y, dungeon_map)

        #finally, append the new room to the list
        rooms.append(new_room)
        num_rooms += 1
開發者ID:phegan,項目名稱:dungeongenerator,代碼行數:66,代碼來源:room.py


注:本文中的rect.Rect.intersect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。