Commit 9fbdca13 by BellCodeEditor

save project

parent 2ff35634
Showing with 10 additions and 4 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -7,6 +8,8 @@ pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
x,y=240, 120
food_x=360
food_y=300
aaa=[(180, 90),(180, 120),(210, 120),(x,y)]
# 背景
background = pygame.image.load('bg.png')
......@@ -20,6 +23,7 @@ aa=pygame.time.Clock()
setheading="right"
snake_head=right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -48,6 +52,9 @@ while True:
y+=30
aaa.append((x,y))
aaa.pop(0)
if food_x==x and food_y==y:
food_x=random.randint(0,660)
food_y=random.randint(0,480)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
......@@ -55,11 +62,9 @@ while True:
# 将贪吃蛇的身体画上去
for i in range(len(aaa)-1):
screen.blit(body,aaa[i])
# screen.blit(body, (210, 120))
# screen.blit(body, (180, 120))
# screen.blit(body, (180, 90))
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (food_x, food_y))
# 刷新画面
pygame.display.update()
aa.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