Commit e45e03aa by BellCodeEditor

save project

parent 5d2278c0
Showing with 65 additions and 26 deletions
import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备
pygame.init()
# 创建一个窗口
screen =pygame.display.set_mode((660,480))
bg=pygame.image.load("bg.png")
apple=pygame.image.load("apple.png")
body=pygame.image.load("body.png")
down=pygame.image.load("down.png")
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
screen.blit(bg,(0,0))
screen.blit(apple,(270,240))
screen.blit(body,(240,90))
screen.blit(body,(240,60))
screen.blit(body,(240,30))
screen.blit(body,(210,30))
screen.blit(body,(180,30))
screen.blit(body,(150,30))
screen.blit(down,(240,120))
pygame.display.update()
import pygame
from pygame import locals
pygame.init()
ticks=pygame.time.Clock()
a="right"
x=330
y=60
location=[(270,90),(300,90),(300,60),(x,y)]
screen=pygame.display.set_mode((660,480))
apple=pygame.image.load("apple.png")
bg=pygame.image.load("bg.png")
body=pygame.image.load("body.png")
down=pygame.image.load("down.png")
left=pygame.image.load("left.png")
right=pygame.image.load("right.png")
up=pygame.image.load("up.png")
b=right
while True:
for i in pygame.event.get():
if i.type == locals.QUIT:
exit()
elif i.type==locals.KEYDOWN:
if i.key==locals.K_RIGHT and a != "left":
a="right"
b=right
elif i.key==locals.K_LEFT and a != "right":
a="left"
b=left
elif i.key==locals.K_UP and a != "down":
a="up"
b=up
elif i.key==locals.K_DOWN and a != "up":
a="down"
b=down
if a=="right":
x+=30
elif a=="left":
x-=30
elif a=="up":
y-=30
elif a=="down":
y+=30
location.append((x,y))
location.pop(0)
screen.blit(bg,(0,0))
screen.blit(apple,(30,90))
for j in range(len(location)-1):
screen.blit(body,location[j])
screen.blit(b,location[-1])
pygame.display.update()
ticks.tick(5)
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