本文整理匯總了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)