Commit 672e21f2 by BellCodeEditor

save project

parent 32f1aeed
Showing with 14 additions and 2 deletions
# 导入pygame、locals模块
import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
# 初始化FPSCLOCK
FPSCLOCK=pygame.time.Clock()
# 设置xy变量
x=240
y=120
# 创建一个窗口
# 设置位置列表
position = [(180,90),(180,120),(210,120),(240,120)]
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
# 背景
# 导入背景、角色素材
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
left = pygame.image.load("left.png")
......@@ -19,8 +27,10 @@ down = pygame.image.load("down.png")
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
# 初始化蛇头判断变量
setheading = "right"
# 初始化蛇头方向变量
snake_tou = left
while True:
......@@ -29,6 +39,7 @@ while True:
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
# 判断键盘情况
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading != "left":
setheading = "right"
......@@ -42,6 +53,7 @@ while True:
if event.key == locals.K_DOWN and setheading != "up":
setheading = "down"
snake_tou = down
# 蛇头根据方向变换
if snake_tou == right:
x += 30
elif snake_tou == left:
......
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