Commit d1e7ca9f by BellCodeEditor

save project

parent 2a5dfa35
Showing with 8 additions and 2 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -17,6 +17,8 @@ up= pygame.image.load('up.png') ...@@ -17,6 +17,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
p=[(180,90),(180,120),(210,120),(x,y)] p=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=300
setheading='right' setheading='right'
s=right s=right
...@@ -47,6 +49,9 @@ while True: ...@@ -47,6 +49,9 @@ while True:
else: else:
y+=30 y+=30
p.append((x,y)) p.append((x,y))
if x==apple_x and y==apple_y:
apple_x=random.randint(0,630)
apple_y=random.randint(0,450)
p.pop(0) p.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
...@@ -57,7 +62,7 @@ while True: ...@@ -57,7 +62,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()
fps.tick(4) fps.tick(4)
\ 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