Commit 3828667e by BellCodeEditor

save project

parent 6df52525
Showing with 9 additions and 3 deletions
import pygame import pygame
from pygame import locals from pygame import locals
from random import randint
x,y=240,120 x,y=240,120
pusition=[(180,90),(180,120),(210,120),(x,y)] pusition=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=300
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
...@@ -44,11 +47,14 @@ while True: ...@@ -44,11 +47,14 @@ while True:
else: else:
y+=30 y+=30
pusition.append((x,y)) pusition.append((x,y))
pusition.pop(0) pusition.pop(0)
if x==apple_x and y==apple_y:
apple_x=randint(0,660)
apple_y=randint(0,480)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right,pusition[-1]) screen.blit(snake_head,pusition[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(pusition)-1): for i in range(len(pusition)-1):
screen.blit(body,pusition[i]) screen.blit(body,pusition[i])
...@@ -57,7 +63,7 @@ while True: ...@@ -57,7 +63,7 @@ while True:
#screen.blit(body, (180, 120)) #screen.blit(body, (180, 120))
#screen.blit(body, (180, 90)) #screen.blit(body, (180, 90))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(3)
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