Commit c1496b59 by BellCodeEditor

auto save

parent adac006c
Showing with 19 additions and 49 deletions
import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
# 初始化pygame,为使用pygame做准备
pygame.init()
x,y=240,120
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
# 背景
background = pygame.image.load('bg.png')
screen = pygame.display.set_mode((660,480))
import pygame
from pygame import locals
bg = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
apple = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
FPS=pygame.time.Clock()
a=[(180,90),(180,120),(210,120),(x,y)]
b='right'
c=right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type=locals.KEYDOWN:
if event.key==locals.K_RIGHT and b !="left":
b='right'
c=right
if event.key==locals.K_LEFT and b !="right":
b='left'
c=left
if event.key==locals.K_DOWN and b!="up":
b='down'
c=down
if event.key==locals.K_UP and b!="down":
b='up'
c=up
# 初始化pygame,为使用pygame做准备
pygame.init()
x+=30
a.append((x,y))
a.pop(0)
# 创建一个窗口
screen = pygame.display.set_mode((660,480))
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right,a[-1] )
# 将贪吃蛇的身体画上去
for i in range(len(a)-1):
screen.blit(body,a[i] )
#screen.blit(body, (180, 120))
#screen.blit(body, (180, 90))
# 将果实画上去
screen.blit(apple, (360, 300))
# 刷新画面
while True :
for event in pygame.event.get():
if event.type==locals.QUIT:
exit()
screen.blit(bg,(0,0))
screen.blit(right,(480,60))
screen.blit(body,(450,60))
screen.blit(body,(420,60))
screen.blit(body,(420,30))
screen.blit(apple,(480,90))
pygame.display.update()
FPS.tick(3)
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