Commit c6d97ff4 by BellCodeEditor

auto save

parent c6188a1e
Showing with 58 additions and 5 deletions
import pygame import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备 import random
pygame.init() pygame.init()
FPSCLOCK=pygame.time.Clock()
bg=pygame.image.load('bg.png')
right=pygame.image.load('right.png')
body=pygame.image.load('body.png')
apple=pygame.image.load('apple.png')
left=pygame.image.load('left.png')
down=pygame.image.load('down.png')
up=pygame.image.load('up.png')
# 创建一个窗口 # 创建一个窗口
?? screen=pygame.display.set_mode((660,480))
\ No newline at end of file x,y=150,120
apple_x=60
apple_y=60
s=[(60,120),(90,120),(120,120),(x,y)]
setheading='right'
tou=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 setheading!='left':
setheading='right'
tou=right
if event.key==locals.K_LEFT and setheading!='right':
setheading='left'
tou=left
if event.key==locals.K_UP and setheading!='down':
setheading='up'
tou=up
if event.key==locals.K_DOWN and setheading!='up':
setheading='down'
tou=down
if setheading=='right':
x+=30
elif setheading=='left':
x-=30
elif setheading=='down':
y+=30
else:
y-=30
s.append((x,y))
if x==apple_x and y==apple_y:
h=random.randint(1,22)
z=random.randint(1,16)
apple_x=h*30-30
apple_y=z*30-30
else:
s.pop(0)
screen.blit(bg,(0,0))
screen.blit(tou,s[-1])
screen.blit(apple,(apple_x,apple_y))
for i in range(len(s)-1):
screen.blit(body,s[i])
pygame.display.update()
FPSCLOCK.tick(6)
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