本文整理汇总了Python中snake.Snake.init_body方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.init_body方法的具体用法?Python Snake.init_body怎么用?Python Snake.init_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.init_body方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Arena
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import init_body [as 别名]
class Arena(cocos.layer.ColorLayer):
is_event_handler = True
def __init__(self):
super(Arena, self).__init__(250, 255, 255, 255, define.WIDTH, define.HEIGHT)
self.center = (director.get_window_size()[0] / 2, director.get_window_size()[1] / 2)
self.batch = cocos.batch.BatchNode()
self.add(self.batch)
self.snake = Snake()
self.add(self.snake, 10000)
self.snake.init_body()
self.enemies = []
for i in range(7):
self.add_enemy()
self.keys_pressed = set()
for i in range(50):
self.batch.add(Dot())
self.schedule(self.update)
def add_enemy(self):
enemy = Snake(True)
self.add(enemy, 10000)
enemy.init_body()
self.enemies.append(enemy)
def update(self, dt):
self.x = self.center[0] - self.snake.x
self.y = self.center[1] - self.snake.y
def on_key_press(self, key, modifiers):
self.keys_pressed.add(key)
self.snake.update_angle(self.keys_pressed)
def on_key_release (self, key, modifiers):
self.keys_pressed.remove(key)
self.snake.update_angle(self.keys_pressed)
示例2: add_enemy
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import init_body [as 别名]
def add_enemy(self):
enemy = Snake(True)
self.add(enemy, 10000)
enemy.init_body()
self.enemies.append(enemy)