Commit 375a754f by BellCodeEditor

save project

parent 96fdc25e
Showing with 22 additions and 3 deletions
import pygame
import random
from pygame import locals
# 初始化pygame,为使用硬件做准备
......@@ -12,13 +13,31 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x,y =240,120
positon=[(180,90),(180,120),(210,120),(x,y)]
apple_x = random.randint(0,660)
apple_y = random.randint(0,480)
setheading = "right"
x += 30
positon.append((x,y))
positon.pop(0)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT setheading !="left":
setheading = 'right'
if event.key == locals.K_LEFT setheading !="right":
setheading = 'left'
if event.key == locals.K_DOWN setheading !="up":
setheading = 'down'
if event.key == locals.K_UP setheading !="down":
setheading = 'up'
x += 30
positon.append((x,y))
positon.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
......@@ -28,6 +47,6 @@ while True:
screen.blit(body, (180, 120))
screen.blit(body, (180, 90))
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apple_x,apple_y)
# 刷新画面
pygame.display.update()
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