1 Star 0 Fork 1

dragon/gluttonous

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
arena.py 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
Crossin Yuan 提交于 2016-09-06 16:47 . game demo
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/dragon-teng140806/gluttonous.git
[email protected]:dragon-teng140806/gluttonous.git
dragon-teng140806
gluttonous
gluttonous
master

搜索帮助