Commit 46502cd6 by BellCodeEditor

save project

parent 8ea7acd0
Showing with 11 additions and 4 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
a=pygame.time.Clock() a=pygame.time.Clock()
...@@ -17,7 +17,10 @@ food = pygame.image.load('apple.png') ...@@ -17,7 +17,10 @@ food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
setheading="right" setheading="right"
look=right look=right
apple_x=360
apple_y=300
x,y=240,120 x,y=240,120
j=[(180,90),(180,120),(180,150),(x,y)] j=[(180,90),(180,120),(180,150),(x,y)]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -42,15 +45,19 @@ while True: ...@@ -42,15 +45,19 @@ while True:
if setheading=="left": if setheading=="left":
x-=30 x-=30
if setheading=="up": if setheading=="up":
y+=30
if setheading=="down":
y-=30 y-=30
if setheading=="down":
y+=30
# 将背景图画上去 # 将背景图画上去
j.append((x,y)) j.append((x,y))
j.pop(0) j.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
screen.blit(look,(x,y))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right,j[-1]) screen.blit(look,j[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(j)-1): for i in range(len(j)-1):
screen.blit(body,j[i]) screen.blit(body,j[i])
......
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