Commit 278f8780 by BellCodeEditor

save project

parent b53a269c
Showing with 8 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()
...@@ -19,6 +19,8 @@ x,y=240,120 ...@@ -19,6 +19,8 @@ x,y=240,120
position=[(210,120),(180,120),(180,90),(x,y)] position=[(210,120),(180,120),(180,90),(x,y)]
setheading='right' setheading='right'
snakehead=right snakehead=right
apple_x=360
apple_y=300
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:
...@@ -49,7 +51,9 @@ while True: ...@@ -49,7 +51,9 @@ while True:
y=y+30 y=y+30
else: else:
y=y-30 y=y-30
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -64,8 +68,8 @@ while True: ...@@ -64,8 +68,8 @@ 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()
a.tick(3) a.tick(5)
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