Commit 4f627ee8 by BellCodeEditor

auto save

parent fc70e389
Showing with 48 additions and 1 deletions
import pygame as pg import pygame as pg
from pygame import locals from pygame import locals
x = 240
y = 120
position = [(180,90),(180,120),(210,120),(x,y)]
setheading = "right"
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pg.init() pg.init()
bg= pg.image.load("bg.png")
right = pg.image.load("right.png")
food = pg.image.load("apple.png")
body = pg.image.load("body.png")
# 创建一个窗口 # 创建一个窗口
s = pg.display.set_mode((800,600)) s = pg.display.set_mode((800,600))
FPSCLOCK = pg.time.Clock()
while True: while True:
for event in pg.event.get(): for event in pg.event.get():
print(event) print(event)
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
if event.type == locals.KEYDOWN:
if event.key == locals.k_RTGHT 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 = "down"
if setheading == "right":
x += 30
elif setheading == "left":
x -= 30
elif setheading == "up":
y -= 30
else:
y += 30
position.append((x,y))
position.pop(0)
s.blit(bg, (0,0))
s.blit(right,position[-1])
for i in range(len(position)-1):
# s.blit(body,(210,120))
# s.blit(body,(180,120))
# s.blit(body,(150,120))
# s.blit(body,(150,90))
s.blit(body, position[i])
pg.display.update()
FPSCLOCK.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