Commit d7dc4927 by BellCodeEditor

save project

parent 7e1bef36
Showing with 45 additions and 10 deletions
...@@ -2,19 +2,54 @@ import pygame ...@@ -2,19 +2,54 @@ import pygame
from pygame import locals from pygame import locals
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
d=pygame.image.load((bg.png))
a=pygame.image.load((right.png))
b=pygame.image.load((body.png)) body=pygame.image.load("body.png")
c=pygame.image.load((apple.png)) apple=pygame.image.load("apple.png")
right=pygame.image.load("right.png")
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((800,600)) screen = pygame.display.set_mode((800,600))
FPS=pygame.time.Clock()
x,y=210,120
position=[(180,120),(180,90),(180,60),(x,y)]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
screen.bilt(a,(210,120)) if event.type == locals.KEYDOWN:
screen.bilt(b,(180,120)) if event.type == locals.K_RIGHT and setheading != "left":
screen.bilt(c,(180,90)) setheading = 'right'
screen.bilt(c,(30,40)) snake_head = right
pygame.display.update() if event.type == locals.K_LEFT and setheading != "right":
\ No newline at end of file setheading = 'left'
snake_head = left
if event.type == locals.K_UP and setheading != "down":
setheading = 'up'
snake_head = up
if event.type == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
if aetheading == "right":
x += 30
elif aetheading == "left":
x += 30
elif aetheading == "up":
y += 30
elif aetheading == "down":
y += 30
x +=30
position.append((x,y))
position.pop(0)
for i in range(len(position)-1):
screen.bilt(body,position[i])
# screen.bilt(background,(0,0))
# screen.bilt(right,(x,y))
# screen.bilt(body,(180,120))
# screen.bilt(body,(180,90))
# screen.bilt(body,(180,60))
# screen.bilt(apple,(30,40))
pygame.display.update()
FPS.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