Commit aef64cb1 by BellCodeEditor

auto save

parent 8c676a1a
Showing with 54 additions and 3 deletions
File added
import pygame import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
# 载入背景图片
background = pygame.image.load('bg.png')
foot = pygame.image.load('apple.png') #食物
right = pygame.image.load('right.png') #头朝右
boby = pygame.image.load('body.png') #身体
# 创建一个窗口 # 创建一个窗口
pygame.display.set_mode((660,480)) screes = pygame.display.set_mode((660,480))
\ No newline at end of file FPSCLOCK = pygame.time.Clock() #设置渲染延时
x = 360
y = 300
position = [(270,300),(300,300),(330,300),(x,y)]
setheading = "right"
while True:
for event in pygame.event.get():#获取pygame的监听事件遍历
print(event)
if event.type== locals.QUIT:
exit()
if event.type == locals.KEYDOWN:#侦测是否按下键盘
if event.key == locals.K_RIGHT and setheading !="left":
setheading = "right"
if event.key == locals.K_LEFT and setheading !="right":
setheading = "left"
if event.key == locals.K_UP and setheading !="down":
setheading == "up"
if event.key == locals.K_DOWN and setheading !="up":
setheading == "dowm"
if setheading =="right":
x = x+30
elif setheading =="left":
x = x-30
elif setheading =="down":
y = y-30
else:
y = y+30
#将图片渲染上去
position.append((x,y))
position.pop(0)
screes.blit(background,(0,0))
screes.blit(foot,(240,120))
screes.blit(right,(x,y))
# screes.blit(boby,(330,300))
# screes.blit(boby,(300,300))
# screes.blit(boby,(300,270))
for i in range(len(position)-1):
screes.blit(boby,position[i])
#刷新整个窗口
pygame.display.update()
FPSCLOCK.tick(3)
\ 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