Commit 6e07d111 by BellCodeEditor

auto save

parent d5739bd2
Showing with 18 additions and 8 deletions
import pygame import pygame
from pygame import locals from pygame import locals
from random import *
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -18,7 +19,8 @@ up = pygame.image.load('up.png') # 头 朝上 ...@@ -18,7 +19,8 @@ up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下 down = pygame.image.load('down.png') # 头 朝下
x, y = 240, 120 x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)] a_x,a_y = 360,300
#position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right" setheading = "right"
snake_head = right snake_head = right
...@@ -51,18 +53,25 @@ while True: ...@@ -51,18 +53,25 @@ while True:
y -= 30 y -= 30
else: else:
y += 30 y += 30
position.append((x, y))
position.pop(0) if x == a_x and y == a_y:
g_x = randint(0,21)
g_y = randint(0,15)
a_x = g_x * 30
a_y = g_y * 30
#position.append((x, y))
#position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0,0))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1]) screen.blit(snake_head,(x,y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): #for i in range(len(position)-1):
screen.blit(body, position[i]) # screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (a_x, a_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.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