|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pygame
import sys
from pygame.locals import *
pygame.init()
size = width, height = 600, 400
bg = (255, 255, 255)
snake = (0, 255, 0)
fanxiang = 'right'
left = 300
top = 200
screen = pygame.display.set_mode(size)
pygame.display.set_caption('贪吃蛇')
move = USEREVENT
pygame.time.set_timer(move, 1 * 1000)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == move:
if fanxiang == 'left':
left -= 11
elif fanxiang == 'top':
top -= 11
elif fanxiang == 'right':
left += 11
elif fanxiang == 'bottom':
top += 11
key_pressed = pygame.key.get_pressed()
if key_pressed[K_w] or key_pressed[K_UP]:
fanxiang = 'top'
if key_pressed[K_s] or key_pressed[K_DOWN]:
fanxiang = 'bottom'
if key_pressed[K_d] or key_pressed[K_RIGHT]:
fanxiang = 'right'
if key_pressed[K_a] or key_pressed[K_LEFT]:
fanxiang = 'left'
if fanxiang == 'left':
left -= 11
elif fanxiang == 'top':
top -= 11
elif fanxiang == 'right':
left += 11
elif fanxiang == 'bottom':
top += 11
screen.fill(bg)
pygame.draw.rect(screen, snake, (left, top, 10, 10), 0)
pygame.display.flip()
pygame.time.delay(10)
请问为什么pygame.time.set_timer(move, 1 * 1000)不能倒计时1秒?谢谢 |
|