本文整理汇总了Python中World.hashpos方法的典型用法代码示例。如果您正苦于以下问题:Python World.hashpos方法的具体用法?Python World.hashpos怎么用?Python World.hashpos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.hashpos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updatePosition
# 需要导入模块: import World [as 别名]
# 或者: from World import hashpos [as 别名]
def updatePosition(entity):
entity.rect.x = int(entity.posx)
collided = False
h = []
h.append(World.hashpos(entity.rect.x, entity.rect.y))
h.append(World.hashpos(entity.rect.x + entity.rect.width, entity.rect.y))
h.append(World.hashpos(entity.rect.x, entity.rect.y + entity.rect.height))
h.append(World.hashpos(
entity.rect.x + entity.rect.width, entity.rect.y + entity.rect.height))
for hashVal in h:
try:
for tile in World.tileBuckets[hashVal].objects():
if pygame.sprite.collide_rect(entity, tile):
if entity.rect.x < tile.rect.x:
entity.rect.x = tile.rect.x - entity.rect.width - 1
elif entity.rect.x > tile.rect.x:
entity.rect.x = tile.rect.x +\
tile.rect.width + 1
entity.velx = 0
entity.posx = entity.rect.x
collided = True
break
if collided:
break
except IndexError:
pass
if entity.isGrounded:
entity.rect.y += 1
else:
entity.rect.y = int(entity.posy)
collided = False
h = []
h.append(World.hashpos(entity.rect.x, entity.rect.y))
h.append(World.hashpos(entity.rect.x + entity.rect.width, entity.rect.y))
h.append(World.hashpos(entity.rect.x, entity.rect.y + entity.rect.height))
h.append(World.hashpos(
entity.rect.x + entity.rect.width, entity.rect.y + entity.rect.height))
for hashVal in h:
try:
for tile in World.tileBuckets[hashVal].objects():
if pygame.sprite.collide_rect(entity, tile):
#entity.vely = 0
if entity.rect.y < tile.rect.y:
entity.rect.y = tile.rect.y - entity.rect.height
entity.isGrounded = True
entity.vely = 0
elif entity.rect.y > tile.rect.y:
entity.rect.y = tile.rect.y +\
tile.rect.height + 1
entity.vely = entity.vely + 100
entity.posy = entity.rect.y
collided = True
break
if collided:
break
except IndexError:
pass
if not collided:
entity.isGrounded = False