Commit b681f5c3 by BellCodeEditor

save project

parent d5739bd2
Showing with 16 additions and 6 deletions
import pygame
from pygame import locals
apx=300
apy=300
n1=0
n2=0
# 初始化pygame,为使用硬件做准备
pygame.init()
from random import *
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -41,7 +44,7 @@ while True:
if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
# 设置贪吃蛇的头部坐标
if setheading == "right":
x += 30
......@@ -51,8 +54,14 @@ while True:
y -= 30
else:
y += 30
position.append((x, y))
position.pop(0)
position.append((x, y))
if apx==x and apy==y:
n1=randint(1,22)
n2=randint(1,16)
apx=30*n1-30
apy=30*n2-30
else:
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
......@@ -62,7 +71,7 @@ while True:
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apx, apy))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ 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