Commit bfd27ca3 by BellCodeEditor

auto save

parent 38564745
Showing with 18 additions and 12 deletions
import pygame
import time
from random import randint
from pygame import locals
......@@ -19,6 +20,7 @@ left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下
txt=pygame.font.Font("neuropol.ttf",20)
over=pygame.font.Font("neuropol.ttf",75)
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
......@@ -47,20 +49,12 @@ while True:
snake_head = down
# 设置贪吃蛇的头部坐标
if setheading == "right":
x += 30
elif setheading == "left":
x -= 30
elif setheading == "up":
y -= 30
else:
y += 30
position.append((x, y))
if position[-1] == (fx,fy):
fx=randint(0,20)*30
fy=randint(0,15)*30
score+=1
else:
position.pop(0)
# 将背景图画上去
......@@ -69,9 +63,21 @@ while True:
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
if 0>x or 630<x or 0>y or y>450:
a=over.render("GAME OVER",True,(0,0,0))
screen.blit(a, (0, 75))
else:
if setheading == "right":
x += 30
elif setheading == "left":
x -= 30
elif setheading == "up":
y -= 30
else:
y += 30
# 将果实画上去1
screen.blit(food, (fx, fy))
screen.blit(text,(10,10))
......
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