14 Star 209 Fork 103

jeffyan20i00 / Snake创意游戏

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.py 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
jeffyan20i00 提交于 2020-08-06 09:58 . added comments
from game import *
from scene import *
import sys
# 读取当前存档,如果没有的话则开始新的游戏
if os.path.exists("save"):
f = open("save", "r")
c_level = int(f.read())
f.close()
g = Game(c_level)
else:
g = Game()
# 主循环
while True:
# 处理事件
for event in pygame.event.get():
# 关闭事件,在关闭的时候存下当前关卡
if event.type == pygame.QUIT:
f = open("save", "w")
f.write(str(g.current_level))
f.close()
pygame.quit()
sys.exit()
# 鼠标事件,更新环境变量
if event.type == pygame.MOUSEMOTION:
env["mouse_x"] = pygame.mouse.get_pos()[0]
env["mouse_y"] = pygame.mouse.get_pos()[1]
env["mouse_direction"] = atan2(env["mouse_y"] - screen_height/2, env["mouse_x"] - screen_width/2)
# 让游戏处理事件
g.handle_event(event)
# 游戏更新
g.update()
# 清空屏幕,然后绘制一个新的屏幕
screen.fill(0)
g.draw()
# 因为基本上每次都需要更新整个屏幕,直接使用flip来刷新整个屏幕
pygame.display.flip()
# 将帧速率限制到40fps
clock.tick(40)
Python
1
https://gitee.com/jeffyan2000/Adapted-game-snake.git
git@gitee.com:jeffyan2000/Adapted-game-snake.git
jeffyan2000
Adapted-game-snake
Snake创意游戏
master

搜索帮助