代码拉取完成,页面将自动刷新
import cocos
from cocos.director import director
import define
from snake import Snake
from dot import Dot
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。