Commit 4a869bca by BellCodeEditor

save project

parent 35e05a4d
Showing with 39 additions and 3 deletions
# import pygame
# # 初始化pygame,为使用pygame做准备
# pygame.init()
# # 创建一个窗口
# screen=pygame.display.set_mode((800.600))
import pygame import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
screen=pygame.display.set_mode((800.600)) screen = pygame.display.set_mode((660, 480))
\ No newline at end of file t=pygame.time.Clock()#创建计时器 设置帧数来控制速度
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x,y=240,120
pr=[(150,120),(180,120),(210,120),(x,y)]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
x+=30
pr.append((x,y))
pr.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right,pr[-1])
# 将贪吃蛇的身体画上去
for i in range(len(pr)-1):
screen.blit(body,pr[i])
# 将果实画上去
screen.blit(food, (360, 300))
t.tick(3)
# 刷新画面
pygame.display.update()
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