本文整理汇总了Python中Convert.world_to_pixel方法的典型用法代码示例。如果您正苦于以下问题:Python Convert.world_to_pixel方法的具体用法?Python Convert.world_to_pixel怎么用?Python Convert.world_to_pixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Convert
的用法示例。
在下文中一共展示了Convert.world_to_pixel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tentative_move
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_pixel [as 别名]
def tentative_move(self, world, old_pos, index):
self.pos[index] += self.vel[index]
if index == 0:
self.bounding_box.x = Convert.world_to_pixel(self.pos[index])
else:
self.bounding_box.y = Convert.world_to_pixel(self.pos[index])
block_left = int(Convert.world_to_chunk(self.pos[0])[0])
chunk_left = Convert.world_to_chunk(self.pos[0])[1]
block_right = math.ceil(Convert.world_to_chunk(self.pos[0] + self.width)[0])
chunk_right = Convert.world_to_chunk(self.pos[0] + self.width)[1]
block_top = int(self.pos[1])
block_bottom = math.ceil(self.pos[1] + self.height)
col1 = col2 = col3 = col4 = False
if chunk_left == chunk_right:
chunk = world.loaded_chunks.get(chunk_left)
col1 = self.check_collision(chunk, block_left, block_right, block_top, block_bottom, old_pos, index)
else:
#need to check from block_left in chunk_left to block_right in chunk_right and all the blocks in any chunks between them
chunk = world.loaded_chunks.get(chunk_left)
col2 = self.check_collision(chunk, block_left, Chunk.WIDTH, block_top, block_bottom, old_pos, index)
for c in range(chunk_left + 1, chunk_right):
chunk = world.loaded_chunks.get(c)
col3 = self.check_collision(chunk, 0, Chunk.WIDTH, block_top, block_bottom, old_pos, index)
chunk = world.loaded_chunks.get(chunk_right)
col4 = self.check_collision(chunk, 0, block_right, block_top, block_bottom, old_pos, index)
if col1 or col2 or col3 or col4:
self.vel[index] = 0 #reset acceleration?
if index == 0:
self.bounding_box.x = Convert.world_to_pixel(self.pos[index])
else:
self.bounding_box.y = Convert.world_to_pixel(self.pos[index])
示例2: __init__
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_pixel [as 别名]
def __init__(self, pos, imageurl, scale=()):
self.pos = pos
self.imageurl = imageurl
self.scale = scale
self.load_image()
#bounding box is in pixels because it can only have ints
self.bounding_box = pygame.Rect(Convert.world_to_pixel(pos[0]), Convert.world_to_pixel(pos[1]), self.img.get_width(), self.img.get_height())
self.width = Convert.pixel_to_world(self.img.get_width()) + 1
self.height = Convert.pixel_to_world(self.img.get_height()) + 1
self.dir = [0, 0] #direction: -1, 0, 1
self.vel = [0, 0] #speeds: any numbers
示例3: collides
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import world_to_pixel [as 别名]
def collides(self, block_pos):
return self.bounding_box.colliderect(pygame.Rect(Convert.world_to_pixel(block_pos[0]), Convert.world_to_pixel(block_pos[1]), Convert.world_to_pixel(1), Convert.world_to_pixel(1)))