Commit ffbce351 by BellCodeEditor

auto save

parent a7e541ab
Showing with 32 additions and 3 deletions
import pygame import pygame #导入模块
from pygame import locals #从pygame中导入locals模块
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
bg = pygame.image.load("bg.png")#加载背景图
right = pygame.image.load("right.png")#加载蛇图片
body = pygame.image.load("body.png")#加载蛇身图片
apple = pygame.image.load("apple.png")#加载苹果图片
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660,480)) screen = pygame.display.set_mode((660,480))
#创建计时器
FPSCLOCK=pygame.time.Clock()
#定义xy坐标
x,y=120,90
position=[(90,90),(60,90),(60,60),(x,y)]
while True:
for event in pygame.event.get():
if event.type==locals.QUIT:#退出事件
exit()
x+=30
#每次追加贪吃蛇头部坐标,然后删除第一个坐标
position.append((x,y))
position.pop(0)
screen.blit(bg,(0,0))#窗口画背景图
#窗口画蛇 取列表最后下标的数
screen.blit(right,position[-1])
#窗口画蛇身
for i in range(len(position)-1):
screen.blit(body,position[i])
# screen.blit(body,(90,90))
# screen.blit(body,(60,90))
# screen.blit(body,(60,60))
screen.blit(apple,(330,210))#窗口画苹果
pygame.display.update()#刷新画面
FPSCLOCK.tick(3)#设置游戏画面每秒布超过3帧
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment