Commit 34aa057f by BellCodeEditor

save project

parent c6188a1e
Showing with 56 additions and 2 deletions
import pygame import pygame
#导入locals子模块
from pygame import locals
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
#设置游戏帧数(pygame时钟)
fps=pygame.time.Clock()
# 创建一个窗口 # 创建一个窗口
?? screen=pygame.display.set_mode((660,480))
\ No newline at end of file
#导入背景图片
bg=pygame.image.load("bg.png")
#导入蛇头右图片
right=pygame.image.load("right.png")
#导入食物图片
food=pygame.image.load("apple.png")
#导入身体部分
body=pygame.image.load("body.png")
#初始化贪吃蛇头部坐标
x=240
y=120
#贪吃蛇初始坐标列表
position=[(150,120),(180,120),(210,120),(x,y)]
while True:
#遍历列表中(监听)的事件
for event in pygame.event.get():
#print(event)
#接到退出事件后退程序
if event.type==locals.QUIT:
exit()
x=x+30
position.append((x,y))
position.pop(0)
#将背景渲染进游戏窗口
screen.blit(bg,(0,0))
#渲染游戏元素
screen.blit(right,(x,y))
screen.blit(food,(360,300))
for i in range(len(position)-1):
screen.blit(body,position[i])
# screen.blit(body,(210,120))
# screen.blit(body,(180,120))
# screen.blit(body,(150,120))
#刷新画面
pygame.display.update()
fps.tick(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