Commit 269af895 by BellCodeEditor

save project

parent f2f9d841
Showing with 18 additions and 0 deletions
import pygame import pygame
from pygame import locals from pygame import locals
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
x=240 x=240
y=120 y=120
position = [(180,90),(180,120),(210,120),(x,y)] position = [(180,90),(180,120),(210,120),(x,y)]
setheading="right"
snake_head=right
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -20,6 +25,19 @@ while True: ...@@ -20,6 +25,19 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
elif event.type==locals.KEYDOWN:
if event.key == locals.K_right:
setheading="right"
snake_head=right
if event.key == locals.K_left:
setheading="left"
snake_head=left
if event.key == locals.K_up:
setheading="up"
snake_head=up
if event.key == locals.K_down:
setheading="down"
snake_head=down
x += 30 x += 30
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(0)
......
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