Commit c1496b59 by BellCodeEditor

auto save

parent adac006c
Showing with 20 additions and 50 deletions
import pygame import pygame
from pygame import locals from pygame import locals
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
x,y=240,120
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660,480))
import pygame
# 背景 from pygame import locals
background = pygame.image.load('bg.png') bg = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
apple = pygame.image.load('apple.png') apple = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
left = pygame.image.load('left.png') # 初始化pygame,为使用pygame做准备
up = pygame.image.load('up.png') pygame.init()
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
# 创建一个窗口
screen = pygame.display.set_mode((660,480))
x+=30 while True :
a.append((x,y)) for event in pygame.event.get():
a.pop(0) if event.type==locals.QUIT:
exit()
# 将背景图画上去 screen.blit(bg,(0,0))
screen.blit(background, (0, 0)) screen.blit(right,(480,60))
# 将贪吃蛇画上去 screen.blit(body,(450,60))
screen.blit(right,a[-1] ) screen.blit(body,(420,60))
# 将贪吃蛇的身体画上去 screen.blit(body,(420,30))
for i in range(len(a)-1): screen.blit(apple,(480,90))
screen.blit(body,a[i] )
#screen.blit(body, (180, 120))
#screen.blit(body, (180, 90))
# 将果实画上去
screen.blit(apple, (360, 300))
# 刷新画面
pygame.display.update() 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