本文整理匯總了Python中rect.Rect.center方法的典型用法代碼示例。如果您正苦於以下問題:Python Rect.center方法的具體用法?Python Rect.center怎麽用?Python Rect.center使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rect.Rect
的用法示例。
在下文中一共展示了Rect.center方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_map
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import center [as 別名]
def make_map(self):
#fill map with "blocked" tiles
self.map = [[ Tile(True)
for y in range(self.height) ]
for x in range(self.width) ]
#create two rooms
rooms = []
num_rooms = 0
for r in range(self.max_rooms):
#random width and height
w = libtcod.random_get_int(0, self.room_min_size, self.room_max_size)
h = libtcod.random_get_int(0, self.room_min_size, self.room_max_size)
#random position without going out of the boundaries 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)
#"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
#if we find an intersection we need to generate a new room
# if len(list(filter(new_room.intersect, rooms))) > 0:
# continue
#"paint" it to the map's tiles
self.create_room(new_room)
#center coordinates of new room, will be useful later
(new_x, new_y) = new_room.center()
if num_rooms == 0:
#this is the first room, where the player starts at
self.starting_pos = (new_x, 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
self.create_h_tunnel(prev_x, new_x, prev_y)
self.create_v_tunnel(prev_y, new_y, new_x)
else:
#first move vertically, 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 new room to the list
rooms.append(new_room)
num_rooms += 1
示例2: main
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import center [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)
示例3: get_rect
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import center [as 別名]
def get_rect(self):
r = Rect(0, 0, self.width, self.height)
r.center = (self.x, self.y)
return r
示例4: make_map
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import center [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)
示例5: setup_map
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import center [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
示例6: make_map
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import center [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
示例7: make_map
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import center [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