本文整理汇总了Python中snake.Snake.extend方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.extend方法的具体用法?Python Snake.extend怎么用?Python Snake.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.extend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import extend [as 别名]
class World():
def __init__(self):
self.mc = minecraft.Minecraft.create()
self.apple = None
self.snake = Snake(self.mc)
def get_player_pos(self):
return self.mc.player.getTilePos()
def get_apple_pos(self):
return self.apple
def place_apple(self, x, z):
self.remove_apple()
y = self.mc.getHeight(x,z)
self.mc.setBlock(x, y, z, 35, 14)
self.apple = Vec3(x,y,z)
def remove_apple(self):
if self.apple is None:
return
self.mc.setBlock(self.apple.x, self.apple.y, self.apple.z, 0)
self.apple = None
def check_collision(self):
pos = [floor(axis) for axis in self.get_player_pos()]
center = Vec3(pos[0], pos[1], pos[2])
for offset in shell:
block = center + offset
if (block.x, block.y, block.z) in list(self.snake.body)[3:]:
return True
return False
def move_snake(self):
new_pos = self.get_player_pos()
new_pos = tuple([floor(i) for i in new_pos])
self.snake.update(new_pos)
def extend_snake(self):
self.snake.extend()
def post(self, message):
self.mc.postToChat(message)
print(message)