Commit a51c60ce by BellCodeEditor

auto save

parent e4bbe901
Showing with 43 additions and 0 deletions
import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备
pygame.init()
#载入图片
beijing = pygame.image.load('bg.png')
apple = pygame.image.load('apple.png')
juese = pygame.image.load('right.png')
shenti=pygame.image.load('body.png')
# 创建一个窗口
screen=pygame.display.set_mode((660,480))
FPS=pygame.time.Clock() #pygame时钟,设置游戏速度(帧数)
x,y =240,120
zuobiao=[(180,90),(180,120),(210,120),(x,y)]#身体和头的坐标库
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 退出程序
exit()
if event.type == locals.KEYDOWN:
if event == locals.K_RIGHT and setheading !='left':
setheading='right'
if event == locals.K_LEFT and setheading !='right':
setheading='left'
if event == locals.K_UP and setheading !='down':
setheading='up'
if event == locals.K_DOWN and setheading !='up':
setheading='down'
#向右走
x +=30
zuobiao.append((x,y))#增加一个头的坐标进入列表
zuobiao.pop(0)#删掉第一个坐标
#将背景画上去
screen.blit(beijing,(0,0))
#把头画上去
screen.blit(juese,zuobiao[-1])
#把身体画上去
for i in range(len(zuobiao)-1):
screen.blit(shenti,zuobiao[i])
#把苹果画上去
screen.blit(apple,(0,60))
#刷新画面
pygame.display.update()
FPS.tick(2)
\ 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