Commit 35ab2044 by BellCodeEditor

save project

parent a2fb1586
apple.png

2.05 KB

bg.png

22.5 KB

body.png

1.4 KB

down.png

2.01 KB

left.png

2.07 KB

File added
right.png

2.05 KB

import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660,480))
import pygame
from pygame import locals
bg = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
down = pygame.image.load('down.png')
up = pygame.image.load('up.png')
apple = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
# 初始化pygame,为使用pygame做准备
pygame.init()
x,y=480,60
# 创建一个窗口
screen = pygame.display.set_mode((660,480))
FPS=pygame.time.Clock()
hp=[(420,30),(420,60),(450,60),(x,y)]
s="right"
b=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 s!= "left":
s="right"
if event.key==locals.K_UP and s!= "down":
s="up"
if event.key==locals.K_LEFT and s!= "right":
s="left"
if event.key==locals.K_DOWN and s!= "up":
s="down"
x+=30
hp.append((x,y))
hp.pop(0)
screen.blit(bg,(0,0))
screen.blit(right,hp[-1])
for i in range(len(hp)-1):
screen.blit(body,hp[i])
# screen.blit(body,(420,60))
# screen.blit(body,(420,30))
screen.blit(apple,(480,90))
pygame.display.update()
FPS.tick(3)
\ No newline at end of file
up.png

2.05 KB

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